Telegram Bot - 如何获得群聊 ID? [英] Telegram Bot - how to get a group chat id?
问题描述
我一直在使用 telegram_bot,并尝试获取 groupChat id 以向群聊发送通知,但不知道我必须使用哪些方法.
为了获取聊天 ID,当机器人参与聊天时,我使用 message.chat.id 但我必须使用它来获取群聊 ID 找不到/
获取群聊id,操作如下:
将 Telegram BOT 添加到群组中.
获取 BOT 的更新列表:
https://api.telegram.org/bot
/getUpdates 例如:
https://api.telegram.org/bot123456789:jbd78sadvbdy63d37gda37bd8/getUpdates
寻找聊天"对象:
<块引用>
{"update_id":8393,"message":{"message_id":3,"from":{"id":7474,"first_name":"AAA"},"chat":{"id":
这是您将 BOT 添加到组中时的响应示例.
使用id"的聊天"反对发送您的消息.
(如果您使用机器人创建了新组并且您只得到
{ok":true,result":[]}
,请删除并再次添加机器人到群)私有图表仅适用于图像
argoprojlabs/argocd-notifications:v1.1.0
或更高版本.
I've been using telegram_bot, and trying to get groupChat id to send notifications to group chat, but don't know which methods I have to use for it.
For getting chat id I use to message.chat.id when the bot participated in the chat but which I have to use for getting group chat id can't find/
In order to get the group chat id, do as follows:
Add the Telegram BOT to the group.
Get the list of updates for your BOT:
https://api.telegram.org/bot<YourBOTToken>/getUpdates
Ex:
https://api.telegram.org/bot123456789:jbd78sadvbdy63d37gda37bd8/getUpdates
Look for the "chat" object:
{"update_id":8393,"message":{"message_id":3,"from":{"id":7474,"first_name":"AAA"},"chat":{"id":<group_ID>,"title":""},"date":25497,"new_chat_participant":{"id":71,"first_name":"NAME","username":"YOUR_BOT_NAME"}}}
This is a sample of the response when you add your BOT into a group.
Use the "id" of the "chat" object to send your messages.
(If you created the new group with the bot and you only get
{"ok":true,"result":[]}
, remove and add the bot again to the group)Private chart only works in image
argoprojlabs/argocd-notifications:v1.1.0
or above.
这篇关于Telegram Bot - 如何获得群聊 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!