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

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


当前回答

我现在测试了4h,但它不工作2021与群聊id。错误{"ok":true,"result":[]}

但现在我找到了一个解决方案:

1)安装“Plus Messenger”(https://play.google.com/store/apps/details?id=org.telegram.plus)

2:)进入群组=>现在在群组头部点击“Group- name”=>现在在群组标题上双击。信息即将到来:ID123456789是剪贴板中的副本

3:)进入组,粘贴剪贴板文本。是你,地面id

4:)看起来像1068773197,这是机器人的-1001068773197(有-100前缀)!!

顺便说一下,你也可以在你的个人资料上看到用户id。

5:)现在转到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从组中踢出去。

2018年代中期之后: 1)邀请@getidsbot或@RawDataBot到你的组,并从聊天id字段获取你的组id。

Message
 ├ message_id: 338
 ├ from
 ┊  ├ id: *****
 ┊  ├ is_bot: false
 ┊  ├ first_name: 사이드
 ┊  ├ username: ******
 ┊  └ language_code: en
 ├ chat
 ┊  ├ id: -1001118554477    // This is Your Group id
 ┊  ├ title: Test Group
 ┊  └ type: supergroup
 ├ date: 1544948900
 └ text: A

2:)使用非官方的聊天工具,比如Plus Messenger,在群组/频道信息中查看你的群组id。

2018年年中之前:(不要使用) 1: Goto (https://web.telegram.org) 2:去你的Gorup,找到你的Gorup链接(https://web.telegram.org/#/im?p=g154513121) 3:复制g后面的数字,在前面加一个(-)-154513121 4:发送你的信息给Gorup 机器人。“嗨”sendMessage (-154513121) 我现在就测试了,效果很好

我对错误的第二个解决方案{"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!

群组聊天id应该以-(减号)开头

This is wrong
10540154212

This is correct
-10540154212

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

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