Integration and reception of Alerts with Telegram

OBJECTIVE

The main objective of this document is to demonstrate how Pegasus can send alerts and notifications via Telegram based on multiple conditions.  A summary of the steps we’ll take are:

CREATE A ROBOT IN TELEGRAM ASSOCIATED TO PEGASUS

ON YOUR PHONE

  1. Install Telegram from Google Play store or Apple App Store
  2. Create a new account

IN THE PC

  1. Enter in  https://web.telegram.org
  2. On the PC, enter to the Telegram account with your celular number. You are going to receive a code on the cellphone which must be copied into the web Telegram.
  3. Once inside Telegram PC, add the robot called “botfather”
  4. On the chat with botfather one can write /start to check all the possible commands. Write /newbot ⇒  Name to create a new bot for your Pegasus site. It is going to give you a token, please save it. This bot is going to be responsible to send  all the desired Pegasus alerts to the users with Telegram installed on their phones.

The token generated for this example was:

467664501:AAEqBqqpp5DwUFPw_JCq0O9TsiLd72BayZQ

This number must be saved since it will be part of the URL of all the alerts created to Telegram.

6. On the chat with “botfather”,  /edit  section -> “Edit Bots”, one can put details of this new bot. For this example we will put only a brief description. But you can put even an image.

7. On the left side, click on the new bot created and click on start, as shown on the animation below:

In this way the new bot is added to the contacts on the Telegram app of the Administrator.

TO BE MADE ON THE USER CELLPHONE, WHICH IS GOING TO RECEIVE THE ALERT

8. The user which is going to receive the alerts must add the bot we created above in his own Telegram, since it must be able to send him messages, as if he were another human user. For this example the bot for pegasus 1 was called  “MisAlertas_bot”, Select it, and click on “start” as well

9. Each user has his own “chat ID”. Every user must know its own chat ID in order to program alerts to him.

To find the “chat ID” of the user to whom the alert will be sent, Search any of the following bots on the left side: either “What’s my ID” bot or “Pegasus1” bot and add it as contact. Once done click on ID or write /ID and wait one minute, and the bot is going to answer the “chat ID” as shown below

Note: You can create groups of users as well (for example a group of customers), to obtain the group ID in this same way, and take it to send alerts to several people at once .

ADMIN: BACK INTO PC CREATING AN ALERT FOR THE USERS

10. In Pegasus, go to:
 Automatization ⇒ New trigger -> Actions ⇒ Third Party Integration

Example of the creation of a trigger to alert Ignition is either on or off:

Go to Actions -> External Integrations

2 resources (URLs) must be added: One to the message of alert and one for map

1st resource:

POST https://api.telegram.org/bot467664501:AAEqBqqpp5DwUFPw_JCq0O9TsiLd72BayZQ/sendmessage

*Red number is the code we created at the very beginning

Content-Type : application/json
{

"text":" Device *{{object.name}}* reports:\n

{% if body.label == "ignon" %} *Ignition has been turned ON.* {% endif %}

{% if body.label == "ignoff" %} *Ignition has been turned Off* {% endif %}

","chat_id":"388888888","parse_mode":"markdown"

}

*Red number above is the chat ID of the user, obtained at point number 9

2do Resource

POST https://api.telegram.org/bot467664501:AAEqBqqpp5DwUFPw_JCq0O9TsiLd72BayZQ/sendlocation

Content-Type : application/json

{

"Latitude":"{{body.formatedlat}}",

"Longitude":"{{body.formatedlon}}",

"chat_id":"38888888"}

Click on Save and that’s all, the user is going to receive alerts from now on.