steavy29 / Telegram.Net

Telegram (http://telegram.org) client library implemented in C#.
17 stars 6 forks source link

How to get channel updates? #30

Closed delykj closed 7 years ago

delykj commented 7 years ago

Hello,

I would like to get channel updates. I have used the sample code you provided in issue #25, but I didn't get any update when a channel get a new post.

FileSessionStore session = new FileSessionStore();
client = new TelegramClient(session, apiId, apiHash, new DeviceInfo("Telegram Test", "Telegram Test", "1.0", "en"));
client.UpdateMessage += TelegramUpdateHandler;
bool started = (await client.Start());

and the update handler code:

private void TelegramUpdateHandler(object sender, Updates update)
        {                       
            switch (update.constructor)
            {                 
                case Constructor.UpdatesTooLong: {
                        var upd = update as UpdatesTooLongConstructor;                        
                        break; }
                case Constructor.UpdateShortMessage:
                    {
                        var upd = update as UpdateShortMessageConstructor;
                        textBox1.Text = textBox1.Text + upd.message + "\r\n";                      
                        break;
                    }
                case Constructor.UpdateShortChatMessage: {
                        var upd = update as UpdateShortChatMessageConstructor;
                        textBox1.Text = textBox1.Text + upd.message + "\r\n";
                        break; }
                case Constructor.UpdateShort: {
                        var upd = update as UpdateShortConstructor;
                        break; }
                case Constructor.UpdatesCombined: {
                        var upd = update as UpdatesCombinedConstructor;                        
                        break; }
                case Constructor.Updates:
                    {
                        var upd = update as UpdatesConstructor;
                        foreach (var updatePiece in upd.updates)
                        {
                            // handle update                            
                        }
                        break;
                    }
            }
        }
steavy29 commented 7 years ago

Hi. Not sure if channels are supported in API 23. Will check today.

steavy29 commented 7 years ago

Yes, unfortunately channels aren't supported in current API version.

romi4rd1 commented 7 years ago

Hi... Mr. @steavy29, I have used like @delykj 's code and got same problem, but in my case i got updates update.constructor after added code like this:

FileSessionStore session = new FileSessionStore();
client = new TelegramClient(session, apiId, apiHash, new DeviceInfo("Telegram Test", "Telegram Test", "1.0", "en"));
client.UpdateMessage += TelegramUpdateHandler;
bool started = (await client.Start());
await client.ResolveUsername(textUserName.Text);

Sory for bad english.

delykj commented 7 years ago

Thanks,

@steavy29, is the official Telegram Client (https://github.com/telegramdesktop/tdesktop) using tricks to get channel updates and don't using the API to get channel updates?

@romi4rd1, I have tried to add your code, but I'm still don't get channel updates. Did you use Constructor.UpdateShortMessage, Constructor.UpdateShortChatMessage for channel updates? What constructor did you use? Do you see the message text that other person sent to the channel? Thanks your help.

steavy29 commented 7 years ago

@delykj "tdesktop" uses higher API(66 atm) version which supports channel updates and constructors. When Telegram.Net establishes connection with Telegram server it specifies it's API version so I think that server doesn't even try to send channel updates to it since it knows that those aren't supported by client(Telegram.Net).

delykj commented 7 years ago

@steavy29 Is it hard to support API v66 in your code? I suppose it isn't such easy to change 23 to 66 :-)

steavy29 commented 7 years ago

Working on latest Api support.

munrocket commented 7 years ago

Can i recieve channel messages throught message history for example and than mark as read?

munrocket commented 7 years ago

Here some code of layer 66. https://github.com/sochix/TLSharp/blob/master/TeleSharp.TL/TL/Updates/TLRequestGetChannelDifference.cs