如何在 Telegram Api 中订阅聊天更新? [英] How to subscribe to chat updates in Telegram Api?

查看:155
本文介绍了如何在 Telegram Api 中订阅聊天更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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.

现在我需要能够获取和处理应该来自 Telegram 本身的更新 - 例如传入的聊天消息和其他更新.

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

如何在 Telegram API 中执行此操作?是否有任何长轮询机制或类似的机制?我阅读了所有 API 文档,但未能找到任何允许订阅更新消息的 API.我发现的最好的事情是这个 updates.getDifference,但这只是一个请求允许获取所有更新 - 而不是订阅新更新.

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.

注意我没有使用 Telegram Bot Api.

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

推荐答案

您的 Telegram 客户端保持与 Telegram 服务器的开放连接以进行活动会话.

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

只要此连接保持打开状态,Telegram 就会向您发送消息更新.

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

我发现最好简单地侦听来自 Telegram 服务器的入站消息,并按照我的用例要求处理收到的有效负载(TL 数据).

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.

在启动时,我只是将它从连接发送到我的主 DC:

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))

这篇关于如何在 Telegram Api 中订阅聊天更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆