How to create a Telegram bot, get the API key and chat ID

How to create a Telegram bot, get the API key and chat ID

This guide will show you how to create a new Telegram bot, get the API and chat ID to be used to send chat messages through programming software.

Create a new Telegram bot and get the HTTP API key

1. Download and install “Telegram” app in your smartphone and register a new account in Telegram (new user).

2. Once logged on to your Telegram account, search for “BotFather” and select it. Make sure it's the one labelled as 'bot'.

3. Type “/start” and type “/newbot” to create a new Telegram bot.

4. Type the name of your new bot (for example “Msg”).

5. Type the username for your new bot which must be ended with “bot” and you cannot choose a username already taken by others (for example “MsgAidBot”)

6. After successfully created a new bot, BotFather will send you a message containing the HTTP API key.

Get the chat ID:

1. In your telegram, create a new chat group and add the bot that you have created into the chat group.

2. To get the chat ID of the group chat, use your internet browser and search for “Telegram Web”. Login to your account on Telegram Web by scanning the QR code.

3. Select the group chat that you have added your Telegram bot into, you will find the chat ID of the group chat shown in the URL within the address bar.

Tips: If you want to send messages to a private chat, the user (the one who receives bot message) must first send a message to the Telegram bot to start up the bot. The "-" sign is not needed for the chat ID of a private chat.

Related topics