Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Introduction

Telegram is a widespread messaging service for all kinds of platforms and devices (similar to WhatsApp).
While WhatsApp only supports sending end-to-end messages from one physical mobile phone number to another, Telegram allows the creation of custom "Bots".

Bots are special accounts that do not require a mobile phone number and can be used to send messages to your own mobile phone.
Telegram provides a public API which will be used by the NETx BMS Core Server to programmatically send messages.

Essentially, it works like this:

  • Inside the Telegram app on your mobile phone, you create a custom bot, which can then be used to publish messages to
  • The created bot has a unique "Token" and "Chat ID", which can be seen as a physical mobile phone number of a contact
  • The NETx BMS Core Server can now send messages to your bot, which you will instantly receive on your mobile phone

Things to keep in mind

Just like with a mobile phone number, everyone knowing your secret "Token" and "Chat ID" is able to push messages to your mobile phone.
You are always able to deactivate and remove a bot, but just keep in mind to treat this information confidently.

Prerequisites

  • A Telegram account is required
    • Download the telegram app for your operating system on your mobile phone
    • Follow the instructions to create an account or use your existing account, if you already have one

Create a custom Telegram bot

In this tutorial, the configuration of the custom bot is performed on iOS, but works similarly on other operating systems, such as Android.

Telegram uses a special account called "BotFather", which is used to create and manage custom bots on your mobile phone.

To create a custom bot, open the Telegram application and search for "BotFather", click the BotFather account to open the chat.

Telegram application 


BotFather initially shows a list of all available commands. All commands need to start with a slash ( / ). To create a new bot, we need to use the 

/newbot

command.

As you start typing, BotFather will automatically suggest available commands. Click the "newbot" command. The BotFather will then ask you to provide some information for your new bot.
Once you're done giving your bot a username and a name (the username of the bot needs to end in "bot"), the BotFather will text you the unique token of your bot.
As mentioned in the introduction, this is the unique identifier of your bot, which you will need to send messages to it.
Copy or write down the token now, because we will need it later on when configuring Telegram for the NETx BMS Core Server.


Great! You have created a custom bot.

Add the bot to your contacts and initiate a conversation

Now that you've added a custom bot, we need to add it to your contact list and initiate a conversation so that it's ready to receive messages from us.
Enter the name or username of your new bot in the search bar (both "NETxTutorialBot" in our case) and click it. The conversation opens.
Click the "Start" button to initiate the conversation and send an initial messages so that everything's set up correctly (for example "hello").


Perfect. You have initiated a conversation with your new bot. This means that it's almost ready to be used. The last step is to retrieve the chat ID, which is the unique identifier of the initiated conversation.

Retrieve the chat ID

This one is a bit tricky. As already mentioned, the chat ID represents the unique identifier of the initiated conversation between you and your bot. The reason that you also need a chat ID is,
that you could, for example, add your bot to a group conversation as well. Therefore, the bot token itself is not enough to identify where to push the message to. So in order to know where to publish messages to,
Telegram requires a combination of both the token (unique identifier of YOUR bot) plus the chat ID of a conversation (in this case, the 1:1 conversation with you and your bot).

Just to clarify: If your bot were member of a group conversation, which you'd like to publish your messages to, you would need the same token of your bot, but the corresponding chat ID of the group conversation.

To retrieve the chat ID, you need the previously noted token of your bot.

Open a web browser (for example Google Chrome), and enter the following url:

https://api.telegram.org/bot<bot token>/getUpdates

where you need to replace <bot_token> with your bot's unique token. In our example:

https://api.telegram.org/bot794823343:AAHYbhf59s0TZacUFpwrghqpUBQJOakacZ8/getUpdates

It may occur that this request won't return the desired results, which should look similar to this:

If this happens, just send another message from your mobile phone to your bot and try it again.
If everything has been set up correctly, you should receive a JSON response containing the required chat ID, which should look similar to this:

Write down the chat ID, in this case "569011464", because we'll need it in the next step.

(tick) Well done, you have now finished setting everything up. Now let's configure your telegram bot within the NETx BMS Core Server.

Configure your Telegram bot within the NETx BMS Core Server



  • No labels