我一直在使用telegram_bot,并试图获得groupChat id发送通知到组聊天,但不知道我必须使用哪些方法。

为了获得聊天id,当机器人参与聊天时,我使用message.chat.id,但我必须使用它来获得组聊天id,无法找到/


当前回答

要获取群聊id,请执行以下步骤:

将Telegram BOT添加到群组中。 获取BOT的更新列表:

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

Ex:

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

查找"chat"对象:

{“update_id”:8393年,“消息”:{“message_id”:3,"从":{" id ": 7474年,“first_name”:“AAA”},“聊天”:{" id ": < group_ID >,“标题”:"},“日期”:25497年,“new_chat_participant”:{" id ": 71年,“first_name”:“名字”,“用户名”:“YOUR_BOT_NAME”}}}

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

使用"chat"对象的"id"发送消息。 (如果你用bot创建了一个新的组,你只得到{"ok":true,"result":[]},删除并重新添加bot到组中) 私有图表只适用于image argoprojlabs/argocd-notifications:v1.1.0或更高版本。

其他回答

去你选择的小组吧 添加@rose机器人 输入命令/id 输入命令/id

要获取群聊id,请执行以下步骤:

将Telegram BOT添加到群组中。 获取BOT的更新列表:

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

Ex:

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

查找"chat"对象:

{“update_id”:8393年,“消息”:{“message_id”:3,"从":{" id ": 7474年,“first_name”:“AAA”},“聊天”:{" id ": < group_ID >,“标题”:"},“日期”:25497年,“new_chat_participant”:{" id ": 71年,“first_name”:“名字”,“用户名”:“YOUR_BOT_NAME”}}}

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

使用"chat"对象的"id"发送消息。 (如果你用bot创建了一个新的组,你只得到{"ok":true,"result":[]},删除并重新添加bot到组中) 私有图表只适用于image argoprojlabs/argocd-notifications:v1.1.0或更高版本。

使用python和telethon,很容易获得聊天id。这个解决方案最适合那些使用电报API的人。

如果你没有电视马拉松,运行这个:

pip install telethon

如果你没有telegram的注册应用,注册一个: 链接如下:https://my.telegram.org/

然后运行以下代码:

from telethon import InteractiveTelegramClient
from telethon.utils.tl_utils import get_display_name

client = InteractiveTelegramClient('session_id', 'YOUR_PHONE_NUMBER', api_id=1234YOURAPI_ID, api_hash='YOUR_API_HASH')

dialog_count = 10
dialogs, entities = client.get_dialogs(dialog_count)
for i, entity in enumerate(entities):
                    i += 1  # 1-based index
                    print('{}. {}. id: {}'.format(i, get_display_name(entity), entity.id))

您可能希望向您的群组发送消息,以便该群组显示在列表顶部。

我对错误的第二个解决方案{"ok":true,"result":[]}

加入你的电报群 添加新用户(邀请) 搜索“getidsbot”=> @getidsbot 消息:/ start@getidsbot 现在您看到了ID。看起来像1068773197,对于bot来说是-1001068773197(前缀是-100)!! 把机器人踢出群组。 现在转到web浏览器,发送这一行(测试消息):

https://api.telegram.org/botAPITOKENNUMBER:APITOKENKEYHERE/sendmessage?chat_id=-100GROUPNUMBER&text=test

编辑API令牌和Group-ID!

截至2021年5月,简单地说:

邀请@RawDataBot到你的组。

加入后,它将输出一个JSON文件,其中您的聊天id将位于message.chat.id。

"message": {
    "chat": {
        "id": -210987654,
        "title": ...,
        "type": "group",
        ...
    }
    ...
}

之后一定要把@RawDataBot从组中踢出去。