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

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


当前回答

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

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

其他回答

要获取群聊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应该以-(减号)开头

This is wrong
10540154212

This is correct
-10540154212
function adminCheck( chat_id, name ) {
var bAdminCheck = false;
var contents = JSON.parse( getAdmin( chat_id ) );      
var i = 0;
while( !bAdminCheck && (i < contents.result.length ) ) {
    if( name == (contents.result[i].user.first_name + " " + contents.result[i].user.last_name) ) {
        bAdminCheck = true;  
    }
    i++;
}  
return bAdminCheck;

}

您可以通过向bot userinfobot发送/start消息来获得您的id

注意:一旦你在telegram中搜索userinfobot,你会得到很多回复。 确保你选择了带有@bot标签的那个