Telegram Bot - 如何获得群聊 ID? [英] Telegram Bot - how to get a group chat id?

查看:193
本文介绍了Telegram Bot - 如何获得群聊 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 telegram_bot,并尝试获取 groupChat id 以向群聊发送通知,但不知道我必须使用哪些方法.

为了获取聊天 ID,当机器人参与聊天时,我使用 message.chat.id 但我必须使用它来获取群聊 ID 找不到/

解决方案

获取群聊id,操作如下:

  1. 将 Telegram BOT 添加到群组中.

  2. 获取 BOT 的更新列表:

     https://api.telegram.org/bot/getUpdates

    例如:

     https://api.telegram.org/bot123456789:jbd78sadvbdy63d37gda37bd8/getUpdates

  3. 寻找聊天"对象:

<块引用>

{"update_id":8393,"message":{"message_id":3,"from":{"id":7474,"first_name":"AAA"},"chat":{"id":,"title":""},"date":25497,"new_chat_participant":{"id":71,"first_name":NAME"、用户名":YOUR_BOT_NAME"}}}

这是您将 BOT 添加到组中时的响应示例.

  1. 使用id"的聊天"反对发送您的消息.

  2. (如果您使用机器人创建了新组并且您只得到 {ok":true,result":[]},请删除并再次添加机器人到群)

  3. 私有图表仅适用于图像 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:

  1. Add the Telegram BOT to the group.

  2. Get the list of updates for your BOT:

     https://api.telegram.org/bot<YourBOTToken>/getUpdates
    

    Ex:

     https://api.telegram.org/bot123456789:jbd78sadvbdy63d37gda37bd8/getUpdates
    

  3. 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.

  1. Use the "id" of the "chat" object to send your messages.

  2. (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)

  3. Private chart only works in image argoprojlabs/argocd-notifications:v1.1.0 or above.

这篇关于Telegram Bot - 如何获得群聊 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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