How to Create a Telegram Bot and Find a Chatroom ID

How to Create a Telegram Bot and Find a Chatroom ID #

Creating a Telegram Bot #

For strategies that use Telegram tools or outcomes to work, a Telegram bot needs to be created and properly configured. To achieve that, you first need to start a chat with @BotFather on Telegram and register a new bot by sending the /newbot command, followed by the name and username of the bot (they can be the same):

Step 1
FlapjackTestBot is used only as an example name, the name of your bot should be different and unique.

By default, a Telegram bot only receives messages that either start with the / symbol or mention the bot by username. However, to allow the Flapjack engine to count the message matches in a group accurately, we need to change the default behavior. To do that, enter the /mybots command and select your bot from the list. This should prompt its control panel to appear:

Step 2

Now, click Bot Settings, and, in the next screen, Group Privacy:

Step 3

And finally Turn off:

Step 4

The last step is to add the bot as a member to the group where you want to look for certain message patterns or use to post your own, automatic messages.

Step 5

Your bot cannot be removed from the group, otherwise the Flapjack engine will not be able to look for message patterns or make any new posts.

Also note that the same Telegram bot can be added to multiple groups, as long as it is used by only one Flapjack engine instance.

Retrieving a Telegram Chatroom ID #

To find the group chatroom ID, use your internet browser and go to the web version of Telegram (web.telegram.org). Once you log in, select the group chatroom of which your Telegram bot is a member. The chatroom ID will be available in the URL within the browser’s address bar:

Step 6
The ID is the number that goes after the # symbol, which, in the example above, is -4059983752.

Another, albeit more technical, approach is to send a request to the Telegram API: https://api.telegram.org/bot{ACCESS_TOKEN}/getUpdates. Replace the {ACCESS_TOKEN} placeholder with your bot’s access token (it is sent by the @BotFather as part of the bot creation confirmation message), paste the whole URL into the browser’s address bar and press enter.

Since the response data is the JSON format, you will find your ID in a chat object:

Step 7
Be sure to check that the title property of your target chat object matches the name of your group. If it does not, look for another chat object as there can be more than one.