Как узнать ид своего телеграм бота?
Не надо ставить как можно больше тэгов. Лучше оставить один, но конкретный, с которым проблема.
См.п.3.1 Регламента.

Модератор @TosterModerator
Фрагменты кода надо размещать в виде текста и оборачивать тэгом code для корректного отображения. Удобно делать кнопкой >
Это обязательно, см.п.3.8 Регламента.
Сюда же относится traceback, ввод и вывод в консоли и другая структурированная текстовая инфа.
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/
8,154 8 8 gold badges 49 49 silver badges 62 62 bronze badges
asked Sep 6, 2015 at 12:58
Roman Podpryatov Roman Podpryatov
4,251 3 3 gold badges 11 11 silver badges 5 5 bronze badges
I manage a bot for this. I hope this will help, check this
May 23, 2016 at 17:41
20 Answers 20
In order to get the group chat id, do as follows:
- Add the Telegram BOT to the group.
- Get the list of updates for your BOT:
https://api.telegram.org/bot/getUpdates
https://api.telegram.org/bot123456789:jbd78sadvbdy63d37gda37bd8/getUpdates
- Look for the «chat» object:
This is a sample of the response when you add your BOT into a group.
- Use the «id» of the «chat» object to send your messages.
- (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)
- Private chart only works in image argoprojlabs/argocd-notifications:v1.1.0 or above.
9,268 10 10 gold badges 67 67 silver badges 114 114 bronze badges
answered Sep 14, 2015 at 19:10
Maverick_Java Maverick_Java
5,813 2 2 gold badges 13 13 silver badges 16 16 bronze badges
@WannaBeCoder, you can add a BOT to a group just like any other member: Go to your group properties, click on add member, then use the search icon to look for the BOT’s name. BUT, keep in mind that since recent changes on Telegrams groups, you must be a group «admin» to add a new member, whether they are BOTs or not.
Jan 28, 2016 at 12:53
For newly created group getUpdates request returns <"ok":true,"result":[]>even if I try to send bunch of messages to the group and mention bot via @ and some random «commands» /my_id , /start , /help . Any ideas what to do? — UPDATE: OK, removing bot from group, and adding bot back fixed this issue (also it printed chat id in the group) — looks like bot can’t be added during group creation.
Apr 21, 2017 at 23:23
this returns: <"ok":true,"result":[]>
Jan 15, 2018 at 2:29
Hi @Tom. Have you already tried rutsky solution: «removing bot from group, and adding bot back fixed this issue (also it printed chat id in the group) — looks like bot can’t be added during group creation. » ? I have faced the same problem a couple of times, and removing the bot from group and adding it over again always solved the problem. Let me know if this won’t help you.
Jan 17, 2018 at 11:35
@tom, if you get <"ok":true,"result":[]>, type something into the bot channel. After this, you should get chat_id
Sep 24, 2019 at 1:28
Here is the sequence that worked for me after struggling for several hours:
Assume the bot name is my_bot.
1- Add the bot to the group.
Go to the group, click on group name, click on Add members, in the searchbox search for your bot like this: @my_bot, select your bot and click add.
2- Send a dummy message to the bot.
You can use this example: /my_id @my_bot
(I tried a few messages, not all the messages work. The example above works fine. Maybe the message should start with /)
3- Go to following url: https://api.telegram.org/botXXX:YYYY/getUpdates
replace XXX:YYYY with your bot token
4- Look for «chat»:
-zzzzzzzzzz is your chat id (with the negative sign).
5- Testing: You can test sending a message to the group with a curl:
curl -X POST "https://api.telegram.org/botXXX:YYYY/sendMessage" -d "chat_id=-zzzzzzzzzz&text=my sample text"
If you miss step 2, there would be no update for the group you are looking for. Also if there are multiple groups, you can look for the group name in the response («title»:»group_name«).
Определитель chat id telegram группы (канала)

Чтобы узнать chat id Telegram группы или канала, нужны две вещи:
- Токен Telegram бота, который выдаёт @BotFather (телеграм бот для создания телеграм ботов);
- Ссылка-приглашение группы (или канала) для которой нужно узнать chat id.
BotFather-ру нужно послать команду /newbot, написать ему как бы вы хотели назвать бота и он выдаст вам токен. А ссылка-приглашение есть у любого публичного канала или группы. Если вы хотите узнать chat id для закрытой группы, то вам на время узнавания необходимо сделать её публичной. А потом можно опять вернуть её приватность.
Теперь, зная необходимые данные, можно узнать chat id. Для этого можно подставить их в форму выше и узнать сhat id нужной группы или канала:

Узнать chat id группы Telegram через адресную строку браузера
Так же можно узнать chat id (и другую информацию) для группы (канала) Telegram, введя следующий адрес в адресную строку браузера:
https://api.telegram.org/botBOTTOKEN/getChat?chat_id=@Username
BOTTOKEN — Токен Telegram бота
Username — то чтот звёздочками: Ссылка-приглашение: t.me/********
Как определить, в какой теме в группе телеграмма пришло сообщение
В телеграме есть группы, в группах есть темы, выглядят эти темы как отдельные группы(подгруппы, группы внутри групп), но message.chat.id у всех тем одинаковый, такой же как у главной группы.
Как можно идентифицировать темы в телеботе, нужно что бы бот в разных темах вёл себя по разному, ему надо как то понять что сообщение прилетело не просто в группу ххх, но еще и в тему ууу из этой группы.
Пробовал использовать message.message_thread_id но похоже что это не идентификатор тем а что то другое, это свойство есть у групп у которых нет тем, и может быть разным внутри одной темы, несколько разных в одной теме или группе без тем.
def get_topic_id(message: telebot.types.Message) -> str: thread_id = message.message_thread_id chat_id = message.chat.id return f'[] []'

theurs ★★
24.07.23 01:21:57 MSK
- Ответить на это сообщение
- Ссылка

А в документации что написано?
Anoxemian ★★★★★
( 24.07.23 01:49:10 MSK )
- Ответить на это сообщение
- Показать ответ
- Ссылка
Ответ на: комментарий от Anoxemian 24.07.23 01:49:10 MSK

в обработчик сообщений поступает этот объект
в нем есть поле message_thread_id (int) – Optional. Unique identifier of a message thread to which the message belongs; for supergroups only
is_topic_message (bool) – Optional. True, if the message is sent to a forum topic
forum_topic_created (telebot.types.ForumTopicCreated) – Optional. Service message: forum topic created
forum_topic_edited (telebot.types.ForumTopicEdited) – Optional. Service message: forum topic edited
forum_topic_closed (telebot.types.ForumTopicClosed) – Optional. Service message: forum topic closed
forum_topic_reopened (telebot.types.ForumTopicReopened) – Optional. Service message: forum topic reopened
general_forum_topic_hidden (telebot.types.GeneralForumTopicHidden) – Optional. Service message: the ‘General’ forum topic hidden
general_forum_topic_unhidden (telebot.types.GeneralForumTopicUnhidden) – Optional. Service message: the ‘General’ forum topic unhidden
Есть еще такое, из чего можно подумать что message_thread_id это всё таки то что надо, но у меня почему то нет
class telebot.types.ForumTopic(message_thread_id: int, name: str, icon_color: int, icon_custom_emoji_id: Optional[str] = None) Bases: JsonDeserializable This object represents a forum topic. Telegram documentation: https://core.telegram.org/bots/api#forumtopic Parameters: message_thread_id (int) – Unique identifier of the forum topic name (str) – Name of the topic icon_color (int) – Color of the topic icon in RGB format icon_custom_emoji_id (str) – Optional. Unique identifier of the custom emoji shown as the topic icon Returns: Instance of the class Return type: telebot.types.ForumTopic
theurs ★★
( 24.07.23 03:09:59 MSK ) автор топика
- Ответить на это сообщение
- Показать ответ
- Ссылка
