How to get chat id in telegram bot
How to get chat id in telegram bot
How to Find a Chat ID in Telegram
Telegram is a wildly popular messaging app with a Bot API interface. That means most, if not all tasks are performed by third-party software. It can pretty much do whatever you can think of – from customizing notifications to making multiplayer games.
Every chat room has an ID number attached to it. It doesn’t matter if it’s private or public nor how many people are involved.
How to Find a Telegram Chat ID On a Mac
You can access Telegram by using the built-in browser for Mac. From there on, you can contact a bot via the web app to find out what your personal chat ID is. Here’s how to do it:
We mentioned there’s a hack for checking the chat ID for your group. This only works for the web app, but it’s still pretty nifty:
If you’re not cut out for online use, you might want to download the desktop version. Telegram is available for free on the Mac App Store. Here’s how you can get it:
How to Find a Telegram Chat ID On a Windows PC
Of course, there’s a desktop version for both Windows and Linux PCs. You can get it from the official Telegram website. Here’s how:
The desktop app uses the same interface as the online or mobile version. It has all the same features as well, meaning you can use Telegram Bot Raw to find out your chat ID. Here’s how:
On Android
You can find the official Android app on Google Play. Once you install it on your phone, you gain access to all Bot API services. That includes Telegram Bot Raw. Here’s how to find your chat ID on the Android app:
Like we said, group chats also have an identification number. However, you can only look it up if you’re the admin. Here’s what you need to do:
How to Find a Telegram Chat ID On an Android
How to Find a Telegram Chat ID On an iPhone
The App Store also has a free mobile version available for iPhone. It looks and performs the same as the Android app, down to the process of getting your chat ID. Just in case, let’s go through it again:
You can also use a chat command to ask the Telegram bot for your account information. All it takes is sending a private message:
Protip: don’t delete the chat with Telegram Bot Raw. That way, you can always find your chat ID.
How to Create a New Telegram Chat ID
Unsurprisingly, the answer is by using bots. Telegram allows you to update your chat ID through a series of HTTPS requests. You first have to create a bot and then add it to your group as an admin. From there on, it’s pretty straightforward. Also, the process is identical for private and public chats alike.
The most convenient way to do it is by using your browser. Telegram is compatible with virtually any search engine currently in use. Technically, you can do it with your Android or iOS device, but it’s somewhat awkward. Getting a chat ID update requires you to copy and paste your bot token in a website URL, so it’s much easier to use your computer instead.
Keep reading for step-by-step instructions for each device.
On Mac
The first part of the process is creating your own bot by using (surprise) a different bot. It sounds far more complicated than it actually is. Here’s how to do it:
After that, you can update to a different chat ID through an HTTPS request. Here’s what you should do:
On Desktop
As we’ve mentioned, you can’t change your chat ID on the desktop app. It has to be done online. However, you can use it to make some necessary preparations instead. For example, adding the bot as an admin. Here’s how:
On Android (and iPhone)
It’s really not advisable to do this with your phone. It’s not that you can’t do it with your chosen browser app; it’s just so awkward. Since smartphones have a touch screen, copying your bot token into the URL is quite a hassle. The more sensible solution is to use your computer to access the API web page.
Additional FAQs
Why can’t I access the chat ID?
You have to have a username to be able to access chat IDs. Telegram doesn’t automatically generate one, so you have to set it yourself. Here’s how:
1. Tap on the Telegram icon on your home screen.
2. In the top-left corner, tap on the three horizontal lines. If the app launched a private conversation when opened, go back to the chat list.
3. Choose “Settings” from the drop-down panel on the left-hand side.
4. Tap on the “Username” section under your phone number. Type at least five characters to create a valid username. If it’s available, a notification will appear below. If not, the text will turn red. Telegram will ask you to come up with a different name.
5. Tap on the check-mark in the top-left corner to finish.
A Bot for Every Occasion
Once you get used to the particular interface, it’s actually quite handy. Telegram made sure there’s a bot for every occasion, and that includes managing chat IDs.
You can easily find out what your personal chat ID is after creating a username. When it comes to group chats, you have to be the admin to access that information. The same goes for creating or updating an ID number. And remember – in case of any bugs or glitches, you can always rely on Telegram’s excellent troubleshooting.
Do you like Telegram? What are your thoughts on apps that have Bot API? Comment below and tell us if there’s another way to change your chat ID.
Как получить ID группы или чата в Telegram
Важная информация
Получение chat_id в Telegram возможно исключительно сторонними средствами, так как в целях безопасности эта функциональность была удалена из мессенджера.
Способ 1: Get My ID
Для получения идентификатора группы можно воспользоваться ботами, например Get My ID. Как и большинство подобных решений, это одинаково работает как в настольном варианте приложения, так и в версиях для Android и iOS. В примере далее мы воспользуемся именно клиентом для ПК.
В окне выбора адресатов укажите Get My ID.
выберите пункт «Информация о группе».
Данный бот обычно срабатывает корректно, однако он неспособен определять идентификаторы приватных чатов и некоторых публичных.
Способ 2: UserInfo
Следующий бот, решающий поставленную задачу, называется UserInfo.
Это решение функционально ничем не отличается от приведённого выше, остальные похожие инструменты обладают подобными возможностями.
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/
18 Answers 18
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
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:
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.
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»:<"id":-zzzzzzzzzz,
-zzzzzzzzzz is your chat id (with the negative sign).
5- Testing: You can test sending a message to the group with a curl:
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«).
How to obtain the chat_id of a private Telegram channel
I use curl to update my public channels. This kind of syntax:
But what’s the chat_id of a private channel? It’s not the one you have in the private invite.
Because now we can pass a channel username (in the format @channelusername) in the place of chat_id in all methods (and instead of from_chat_id in forwardMessage). But what’s the @channelusername of a private channel that I administer?
14 Answers 14
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
I found the way to write in private channels.
You should convert it to public with some @channelName
Send a message to this channel through the Bot API:
As the response, you will get information with chat_id of your channel.
Now you can convert the channel back to private (by deleting the channel’s link) and send a message directly to the chat_id «-1001005582487»:
The easiest way:
Just send your invite link to your private channel to @username_to_id_bot (https://t.me/username_to_id_bot) bot. It will return its ID. The simplest level: maximum! 🙂
PS. I am not an owner of this bot.
PS 2. the Bot will not join your group, but to be sure in security. Just revoke your old invitation link if it is matter for you after bot using.
A more cumbersome way:
Making the channel public cannot be done by the user with exist at least five public groups/channels, so. the problem is not solved. Yes, you can revoke one of them, but for now, we cannot retrieve chat id another way.
A crazy solution:
So. your channel id will be «-1001055587116». Magic happens 🙂
How to obtain Telegram chat_id for a specific user?
How to obtain user chat_id in Telegram bot API? The documentation says:
Integer | Unique identifier for the message recipient — User or GroupChat id
10 Answers 10
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
The message updates you receive via getUpdates or your webhook will contain the chat ID for the specific message. It will be contained under the message.chat.id key.
This seems like the only way you are able to retrieve the chat ID. So if you want to write something where the bot initiates the conversation you will probably have to store the chat ID in relation to the user in some sort of key->value store like MemCache or Redis.
I believe their documentation suggests something similar here, https://core.telegram.org/bots#deep-linking-example. You can use deep-linking to initiate a conversation without requiring the user to type a message first.
It does not only work for user chat ID, but also for group chat ID.
To get group chat ID, first you have to add the bot to the group, then send /my_id in the group.
There is a bot that echoes your chat id upon starting a conversation.
Another option is @getidsbot which gives you much more information. This bot also gives information about a forwarded message (from user, to user, chad ids, etc) if you forward the message to the bot.
First, post a message in a chat where your bot is included (channel, group mentioning the bot, or one-to-one chat). Then, just run:
Feel free to remove the | jq part if your dont have jq installed, it’s only useful for pretty printing. You should get something like this:
You can see the chat ID in the returned json object, together with the chat name and associated message.
You can just share the contact with your bot and, via /getUpdates, you get the «contact» object
Using the Perl API you can get it this way: first you send a message to the bot from Telegram, then issue a getUpdates and the chat id must be there:
The id should be in chat_id but it may depend of the result, so I also added a dump of the whole result.
Источники информации:
- http://lumpics.ru/how-find-out-chat-id-in-telegram/
- http://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id
- http://stackoverflow.com/questions/33858927/how-to-obtain-the-chat-id-of-a-private-telegram-channel
- http://stackoverflow.com/questions/31078710/how-to-obtain-telegram-chat-id-for-a-specific-user