Search code examples
c#messaginglong-pollingtelegram

How to subscribe to chat updates in Telegram Api?


I'm using Telegram API to develop small custom chat application. I managed to make some basic operations like authorization/chats creation and inviting other users to them.

Now I need to be able to get and handle updates that should come from Telegram itself - like incoming chat messages and other updates.

How do I do this in Telegram API? Is there any long-polling mechanism or something similar? I read all API documentation but failed to find any API that would allow to subscribe to update messages. Best thing that I've found is this updates.getDifference, but it is just a request that allows to get all updates - not to subscribe for new ones.

N.B. I'm not using Telegram Bot Api.


Solution

  • Your Telegram client keeps an open connection(s) to the telegram servers for active session(s).

    Telegram sends you message update as long as this connection stays open.

    I find it best to simply listen for in-bound message from Telegram Servers and process the payload(TL data) received as my use-case dictates.

    At startup I just send this from a connection to my primary DC:

     msg = TL.invokewithlayer(layer, TL.initconnection(app_id, device_model, system_version, app_version, lang_code, TL.help_getconfig))