Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

Telegram Bot - how to get a group chat id?

I've been using telegram_bot, and trying to get groupChat id to send notifications to group chat, but don't know which methods I have to use for it.

For getting chat id I use to message.chat.id when the bot participated in the chat but which I have to use for getting group chat id can't find/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In order to get the group chat id, do as follows:

  1. Add the Telegram BOT to the group.

  2. Get the list of updates for your BOT:

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

    Ex:

     https://api.telegram.org/bot123456789:jbd78sadvbdy63d37gda37bd8/getUpdates
    
  3. Look for the "chat" object:

{"update_id":8393,"message":{"message_id":3,"from":{"id":7474,"first_name":"AAA"},"chat":{"id":<group_ID>,"title":""},"date":25497,"new_chat_participant":{"id":71,"first_name":"NAME","username":"YOUR_BOT_NAME"}}}

This is a sample of the response when you add your BOT into a group.

  1. Use the "id" of the "chat" object to send your messages.

  2. (If you created the new group with the bot and you only get {"ok":true,"result":[]}, remove and add the bot again to the group)

  3. Private chart only works in image argoprojlabs/argocd-notifications:v1.1.0 or above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...