简体   繁体   English

如何在Telegram Api中订阅聊天更新?

[英]How to subscribe to chat updates in Telegram Api?

I'm using Telegram API to develop small custom chat application. 我正在使用Telegram API开发小型自定义聊天应用程序。 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? 如何在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. 我阅读了所有API文档,但找不到任何允许订阅更新消息的API。 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. 我发现的最好的东西是updates.getDifference ,但这只是一个允许获取所有更新的请求-而不是订阅新的。

NB I'm not using Telegram Bot Api. 注意:我没有使用Telegram Bot Api。

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. 只要此连接保持打开状态,Telegram就会向您发送消息更新。

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. 我发现最好只是侦听来自Telegram Server的入站消息,并按照我的用例指示处理收到的有效负载(TL数据)。

At startup I just send this from a connection to my primary DC: 在启动时,我只是将其从连接发送到我的主DC:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM