c# - 如何在 TLSharp 重用 session.dat?

标签 c# .net-core telegram

我通过 TLSharp 连接到 Telegram 并成功授权,但我不知道如何重新使用我启动的 session 。

session.dat 我在项目路径中。

var client = new TelegramClient(, "");
await client.ConnectAsync();

var hash = await client.SendCodeRequestAsync("");
var code = Console.ReadLine(); // you can change code in debugger

var user = await client.MakeAuthAsync("", hash, code);

最佳答案

Hello! There are a "sessionUserId" parameter in the constructor of the client object. You can give a unique value for each of your accounts. In my case i use a phone number to identificate sessions.

public TelegramClient (int apiId, string apiHash,
             ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null)

For example

int apiId = 123456;
string apiHash = "123456";
string phone_number = "1234567890";
var client = new TelegrowTelegramClient (apiId, apiHash, null, phone_number);

It's create a 1234567890.dat file in app folder. Ofcourse you can write your own ISessionHandler implementation and store sessions anywhere you want.

https://github.com/sochix/TLSharp/issues/641

关于c# - 如何在 TLSharp 重用 session.dat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55936037/

相关文章:

c# - 强制 C# 异步任务懒惰?

c# - 最短单词列表算法

c# - 打开进程启动命令提示符后如何在 C# 中编写 ipconfig

c# - 为什么未指定操作名称时不调用索引方法

python - 如何实现一个可以处理多步输入的 Telegram 机器人程序?

python - 用于检查字符串中的变量是否存在的命令

android - 选择 SMS、WhatsApp 或 Telegram 发送消息

c# - 如何从 void 函数返回数据?

c# - C# 方法链可以是 "too long"吗?

c# - 在 .net core/webpack Web 应用程序中注入(inject) css 样式的最佳实践