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

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


当前回答

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) 我现在就测试了,效果很好

其他回答

创建一个机器人,如果已经创建了,则如下所示:

可以访问消息

显然,不管Telegram群组有多老/多新:

向组中添加一个机器人 从组中移除机器人 再次将bot添加到组中 创建一个脚本文件并运行getUpdates方法 例子:

    var vApiTokenTelegram = "1234567890:???>yg5GeL5PuItAOEhvdcPPELAOCCy3jBo"; // @?????Bot API token
    var vUrlTelegram = "https://api.telegram.org/bot" + vApiTokenTelegram;

    function getUpdates() {
        var response = UrlFetchApp.fetch(vUrlTelegram + "/getUpdates");
        console.log(response.getContentText());
    }

登录控制台的功能如下:

[20-04-21 00:46:11:130 PDT] {"ok":true,"result":[{"update_id":81329501,
"message":{"message_id":975,"from":{"id":962548471,"is_bot":false,"first_name":"Trajano","last_name":"Roberto","username":"TrajanoRoberto","language_code":"en"},"chat":{"id":-1001202656383,"title":"R\u00e1dioRN - A voz da na\u00e7\u00e3o!","type":"supergroup"},"date":1587454914,"left_chat_participant":{"id":1215098445,"is_bot":true,"first_name":"MediaFlamengoRawBot","username":"MediaFlamengoRawBot"},"left_chat_member":{"id":1215098445,"is_bot":true,"first_name":"MediaFlamengoRawBot","username":"MediaFlamengoRawBot"}}},{"update_id":81329502,
"message":{"message_id":976,"from":{"id":962548471,"is_bot":false,"first_name":"Trajano","last_name":"Roberto","username":"TrajanoRoberto","language_code":"en"},"chat":{"id":-1001202656383,"title":"R\u00e1dioRN - A voz da na\u00e7\u00e3o!","type":"supergroup"},"date":1587454932,"new_chat_participant":{"id":1215098445,"is_bot":true,"first_name":"MediaFlamengoRawBot","username":"MediaFlamengoRawBot"},"new_chat_member":{"id":1215098445,"is_bot":true,"first_name":"MediaFlamengoRawBot","username":"MediaFlamengoRawBot"},"new_chat_members":[{"id":1215098445,"is_bot":true,"first_name":"MediaFlamengoRawBot","username":"MediaFlamengoRawBot"}]}}]}

电报组chat_id可以从上面的消息提取 “聊天”:{" id ": -1001202656383,“标题”

您可以以同样的方式检索组ID。它以message.chat.id的形式出现在消息体中,通常是一个负数,而正常的聊天则是正数。

组id和聊天id只能从收到的消息中检索,没有可用的调用来检索活动的组等。收到消息时必须记住组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) 我现在就测试了,效果很好

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