用户加入频道时的电报Bot事件 [英] Telegram Bot Event When Users Join To Channel

查看:97
本文介绍了用户加入频道时的电报Bot事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建电报漫游器后,访问并管理该漫游器以进行引导.用户加入此频道时如何获取频道成员列表或事件?

After create telegram bot, access and admin this bot to channel. how to get channel members list or event when users join to this channel?

推荐答案

当前的答案非常令人失望,因此,我将留下一个更新的答案(截至2018年2月),其中说明了如何使用电报API 本身,以及我使用的框架

Pretty disappointed with the current answers, so I'll leave an updated (as of February 2018) answer that explains how to do this with the Telegram API itself, as well as with the framework I am using, Telegraf for Node.

Telegram API不仅功能强大,而且就API而言非常简单.如果您使用的是获取更新的轮询方法,而不是使用Websocket,而这又是另外一个问题,那么检查是否有人已添加到组或频道非常容易.

The Telegram API is both very powerful, and pretty simple as far as API's go. If you are using the polling method of getting updates, and not websockets which are a whole other issue, checking if someone new has been added to a group or channel is very easy.

API方法getUpdates返回一个Update对象的数组,其中包含您可能需要的所有可能的信息,包括所有已发送的消息,内联查询和新的聊天成员.要获取任何新的聊天成员,您只需访问update.message.new_chat_members,它将包含一系列新用户.作为参考,您可以在此处中查看API.

The API method getUpdates returns an array of Update objects, which contain all of the possible information you could want including any messages sent, inline queries, and new chat members. To get any new chat members you simply need to access update.message.new_chat_members which will contain an array of new users. For reference you can look in the API documentation here.

要在浏览器中或使用curl获取更新对象,只需将GET或POST请求发送到

To fetch the update objects in browser, or with curl, all you have to do is send a GET or POST request to https://api.telegram.org/botYOUR-BOT-TOKEN/getUpdates. Then just look for messages->new_chat_members.

如果将Telegraf bot框架与NodeJ一起使用,则可以将bot.on方法与事件new_chat_members一起使用.

If you are using the Telegraf bot framework with NodeJs you can use the bot.on method with the event new_chat_members.

示例:

bot.on('new_chat_members', (ctx) => console.log(ctx.message.new_chat_members))

我知道这个问题是在不久前问到的,但是我希望这可以帮助其他人进行搜索.

I know this was asked a while ago, but I hope this helps other people searching.

这篇关于用户加入频道时的电报Bot事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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