wiz0u / WTelegramClient

Telegram Client API (MTProto) library written 100% in C# and .NET
https://wiz0u.github.io/WTelegramClient/
MIT License
956 stars 156 forks source link

Getting Message History with min_id #249

Closed isaacrlevin closed 4 months ago

isaacrlevin commented 4 months ago

Maybe I am having a moment, but I don't see how you can get all messages for a channel based on the latest message in a datastore. This is because the message.ID is stored as a long, but parameter min_id for Messages_GetHistory is an int. No type of conversion is going to make this work. Is there something I am missing here. Here is a snippet for instance.


client = new WTelegram.Client(appid, "apphash");
while (client.User == null)
            switch (await client.Login("phonenumber"))
            {
                case "verification_code": Console.Write("Code: "); loginInfo = Console.ReadLine(); break;
                case "name": loginInfo = "John Doe"; break;    // if sign-up is required (first/last_name)
                case "password": loginInfo = "secret!"; break; // if user has enabled 2FA
                default: loginInfo = null; break;
            }

var chats = await client.Messages_GetAllChats();

foreach (var (id, chat) in chats.chats)
    {
            switch (chat)
            {
                case Channel group:
                    Console.WriteLine($"{id}: Group {group.username}: {group.title}");
                    var messages = await client.Messages_GetHistory(group, limit: 1000);
                    var latestMessage = messages.Messages.OrderByDescending(a => a.date).FirstOrDefault();
                    Thread.Sleep(100000);
                    // Here you fail at compilation because long to int conversion. Casting will warrant incorresults
                    var newMessages = messages = await client.Messages_GetHistory(channel, limit: 1000,  min_id: latestMessage.id);
                    break;
            }
    }
wiz0u commented 4 months ago

why is your message.ID a long? it's an int.

anyway, you should ask this on StackOverflow

github-actions[bot] commented 4 months ago

Please note that Github Issues should be used only for problems with the library code itself. For questions about Telegram API usage, you can search the API official documentation or click here to ask your question on StackOverflow so the whole community can help and benefit.