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

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


当前回答

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

可以访问消息

显然,不管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,“标题”

其他回答

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

可以访问消息

显然,不管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,“标题”

我发现的最简单的方法是只使用电报网:

开放网络。电报在浏览器(在我的情况下chrome) 右键单击左侧菜单上的组名 点击“检查”按钮 您将在属性中看到组id Data-peer-id ="-xxxxxxxxxx" or peer="-xxxxxxxxxx"

群聊id: -xxxxxxxxxx

频道聊天id: -100xxxxxxxxxx

(对于某些频道/组,您需要添加-100前缀)

编辑: 在某些情况下,当您单击组名时,ID会显示在浏览器的地址栏中

https://web.telegram.org/z/#-xxxxxxxxxx

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

邀请@RawDataBot到你的组。

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

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

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

我想说的是一个非常具体的案例让我绕开了它。

我已经得到了上面步骤的chat_id格式如-1001379XXXXXX。因此,我假设真实的id是1001379XXXXXX,并将其以这样的格式留给grafana管理页面。但事实上,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!