-
Launch the Telegram app and use the search function to locate
@BotFather. -
Initiate interaction by selecting Start.
-
Access the Menu and choose
/newbotor simply type/newbotinto the chat and press Send. -
Proceed with the provided instructions until you receive a message similar to the following:
-
Success! Your new bot is ready. You can find it at t.me/your_bot. Feel free to add a description... Here is your token for the HTTP API: 63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c Guard this token carefully and store it securely, as it can be utilized by others to manage your bot. For detailed information on the Bot API, refer to this documentation: https://core.telegram.org/bots/api -
Take note of your bot token
63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4cand ensure its confidentiality.
-
Locate and initiate a conversation with your newly created Telegram bot.
-
Either click Start or send any message to activate the bot.
-
Navigate to the following URL in your web browser:
https://api.telegram.org/bot{your_bot_token}/getUpdates- Remember to prepend the word
botto your token. - For example:
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/getUpdates
- Remember to prepend the word
-
A JSON response will be displayed as follows:
-
{ "ok": true, "result": [ { "update_id": 83xxxxx35, "message": { "message_id": 2643, "from": {...}, "chat": { "id": 21xxxxx38, "first_name": "...", "last_name": "...", "username": "@username", "type": "private" }, "date": 1703062972, "text": "/start" } } ] } -
Locate the
result[0].message.chat.idvalue to find your Chat ID, which in this case is21xxxxx38. -
Test sending a message with the following URL:
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=21xxxxx38&text=test123 -
If the bot token and chat id are correctly configured, the message
test123will appear in your Telegram bot chat.
-
Include your Telegram bot as a member of the desired channel.
-
Post a message within the channel.
-
Visit
https://api.telegram.org/bot{your_bot_token}/getUpdates -
The JSON response will appear as follows:
{ "ok": true, "result": [ { "update_id": 838xxxx36, "channel_post": {...}, "chat": { "id": -1001xxxxxx062, "title": "....", "type": "channel" }, "date": 1703065989, "text": "test" } } ] } -
Identify the
result[0].channel_post.chat.idvalue to obtain your Chat ID, which is-1001xxxxxx062in this example. -
Attempt message delivery using the URL:
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=-1001xxxxxx062&text=test123 -
Upon successful configuration of the bot token and chat id, the message
test123will be delivered to your Telegram channel.
The most straightforward method to obtain a group chat ID is via the Telegram desktop application.
- Open the Telegram desktop app.
- Integrate your Telegram bot into the group chat.
- Post a message within the group chat.
- Right-click on the message and select
Copy Message Link.- The link will resemble:
https://t.me/c/194xxxx987/11/13 - The format is:
https://t.me/c/{group_chat_id}/{group_topic_id}/{message_id} - The Chat ID in this instance is
194xxxx987
- The link will resemble:
- For API usage, prefix the group chat ID with
-100, resulting in-100194xxxx987. - Send a test message with the URL:
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=-100194xxxx987&text=test123 - With the correct bot token and chat id, the message
test123will be received in the group chat.
To send a message to a particular topic within a Telegram group, you must acquire the topic ID.
- Following the steps above, after selecting
Copy Message Link, you will obtain a link like:https://t.me/c/194xxxx987/11/13, where the group Topic ID is11. - Utilize the
message_thread_idparameter as shown:https://api.telegram.org/bot783114779:AAEuRWDTFD2UQ7agBtFSuhJf2-NmvHN3OPc/sendMessage?chat_id=-100194xxxx987&message_thread_id=11&text=test123 - With the appropriate bot token and chat id, the message
test123will be sent to the specified topic within the group chat.