sochix / TLSharp

Telegram client library implemented in C#
1k stars 380 forks source link

Get Message of bot #868

Closed GreenMine closed 5 years ago

GreenMine commented 5 years ago

I tried to get the chat ID with the bot, but it is not in the list. Or is there another way to get it?

GreenMine commented 5 years ago
TLDialogs dialogs = (TLDialogs)await client.GetUserDialogsAsync();
var chats = dialogs.Chats
    .Where(c => c.GetType() == typeof(TLChannel))
    .Cast<TLChannel>();

foreach(TLChannel channel in chats)
{
        Console.WriteLine(channel.Title);

}
GreenMine commented 5 years ago

Solution:

var dialogs = (TLDialogs)client.GetUserDialogsAsync().Result;
var users = dialogs.Users.AsEnumerable().ToList();
var bot = users.Where(c => c.GetType() == typeof(TLUser)).Cast<TLUser>().FirstOrDefault(c => c.Username == "etlgr_bot");