Telegram
Telegram is a module for sending messages from i3 Pro to Telegram. A Telegram bot sends messages configured in iRidi Studio when an event is triggered (for example, notifications from leak sensors, smoke detectors, and other equipment).
Documentation updated 01.01.2024
Creating a Telegram bot
-
Open Telegram, enter BotFather in the search field ;
-
Select the bot found in the search, open a conversation with it, and click Start ;
-
Send the command /newbot to create your bot;
-
BotFather will ask you to choose a name for your bot. Enter a name;
-
Choose a unique username for the bot. The name must end with _bot ;
-
After successful registration, BotFather will send you a message with a token that you must save for later use.
Integrating the module into a project
We have prepared a project that demonstrates the Telegram module. To integrate the module into a project:
-
Download the project template containing the Telegram module;
-
Open the module in iRidi Studio;
-
Merge your project with the Telegram module:

-
In the SCRIPT section, open the Main file containing the example;
-
Change the parameters in the example:
- device Name - Telegram driver name;
- chat ID - user or group ID;
- token of the bot - i ;
- timeout between messages - delay between messages, in milliseconds;
- print Log - a variable that determines whether logs are output (true, false).
Getting the chat ID:
- Open Telegram, enter userinfobot in the search field ;
- Select the bot found in the search, open a conversation with it, and click Start ;
- The message provides information about your Telegram account: login, id, first name, last name .
Getting a group's chat ID:
- Add the bot to the group (use the usual member-adding procedure and search for the bot by name);
- Start the bot with the command /start ;
- You can get a list of updates for your bot at the following link, where **** is replaced with your bot's token: https://api.telegram.org/bot/getUpdates ;
- You will receive a response similar to this:
In the chat object, the id field is your group ID.
- Following the example, write a data handler in the Main script. Specify the event that sends the message and the message text.
6.1. Example of sending a message when a button is pressed"
-
Replace the chat ID and token of the bot values with those used by the Telegram bot;
-
Create the function send_mail() and enter the message text to be sent by the Telegram bot;
-
Bind the function send_mail() to a graphical item (button) using the Script call macro.
var l_pTelegram;
IR.AddListener(IR.EVENT_START, 0, function(){
l_pTelegram = new Telegram(
/* device Name */ "Telegram",
/* chat ID */ "0000",
/* token of the bot */ "botToken",
/* timeout between messages */ 200,
/* print Log */ true);
});
function send_mail()
{
l_pTelegram.SendMessage("text message");
}
6.2. Example of sending a message when driver tag values change"
-
Replace the chat ID and token of the bot values with those used by the Telegram bot;
-
Replace ** "Name Device" ** with the name of the driver whose values you want to monitor and send to Telegram.
-
In the IR.EVENT_TAG_CHANGE listener, add the required channels whose values you want to monitor and the message text to be sent to Telegram.
var l_pTelegram;
IR.AddListener(IR.EVENT_START, 0, function(){
l_pTelegram = new Telegram(
/* device Name */ "Telegram",
/* chat ID */ "0000",
/* token of the bot */ "botToken",
/* timeout between messages */ 200,
/* print Log */ true);
var driver = IR.GetDevice("Name Device"); // driver name
});
IR.AddListener(IR.EVENT_TAG_CHANGE, driver, function(name,value)
{
if (name == "Address 1" && value == 1) // if the driver feedback "Address 1" changed to 1
{
l_pTelegram.SendMessage("Back door opened!"); // text of notification
}
});
6.3. Example of sending a message on a specified date"
-
Replace the chat ID and token of the bot values with those used by the Telegram bot;
-
In the IR.EVENT_GLOBAL_TAG_CHANGE listener, specify the date and time to send the message and the message text.
var l_pTelegram;
IR.AddListener(IR.EVENT_START, 0, function(){
l_pTelegram = new Telegram(
/* device Name */ "Telegram",
/* chat ID */ "0000",
/* token of the bot */ "botToken",
/* timeout between messages */ 200,
/* print Log */ true);
});
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function (name, value)
{
// conditions:
if (IR.GetVariable("System.Date.MM_DD") == "03/14" && IR.GetVariable("System.Time.Hour") == 10 && IR.GetVariable("System.Time.Minutes") == 0)
{
l_pTelegram.SendMessage("Happy Birthday Mike!"); // text of notification
}
});
IR.SubscribeTagChange("System.Time.Minutes"); // subscribe on minutes to check condition each minute
Starting the bot as an end user
To start using the Telegram bot, the end user must:
-
Provide the chat ID of their account or group chat to the integrator;
-
Find the bot by its username ;
-
Open a conversation and start the bot by sending the command /start .