Search another article?
Configure SGBox to use Telgram API in LCE Module and send alert messages
This articles explain how to configure SGBox to interact with Telegram API in order to send alert messages when a specific event occur.
Requirements:
- SGBox version 4.2.4 with the LM and LCE modules.
- A Telegram BOT.
There are many tutorial about how to configure a Telegram BOT. We choose @BotFather for our example.
First you need to create your bot and obtain your TOKEN:
A token is something like: 1148120703:AbIUGpERusdQDEEag_EL1KDtynRB9sIhbj1.
You need also a the chat_id, so: start and say “Hello” to your bot, than retrieve the chat id:
From your browser go to:https://api.telegram.org/bot1148120703:AbIUGpERusdQDEEag_EL1KDtynRB9sIhbj1/getupdates
Find the ID in the response:id: 124229696
Telegram App Installation
Install Telegram application: SCM > Applications
![Telegram App 5 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/install_1.png)
> Packages
![Telegram App 6 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/install_2.png)
find the “Telegram Alert”, in this case the package is already installed but the installation’s button is in the same place
![Telegram App 7 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/install_3-1.png)
After the dowmload we verify in PB
![Telegram App 8 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/usage_1-1.png)
When PB is open search Tlegram alert in filter name
![Telegram App 9 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/usage_2-1024x424.png)
When we find Telegram_Alert we need to modify with the button on the right side
![Telegram App 10 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/usage_3-1024x232.png)
Telegram_Alert’s Playbook has this format
![Telegram App 11 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/PB-1024x409.png)
Afetr we need to create an Event/logs queries to connect with the Telegram_Alert’s Playbook, we have to go to LM > Analysis > Event/logs queries
![Telegram App 12 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/event_log_queries_1.png)
Create new Queries with the blue button on the right
![Telegram App 13 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/event_log_queries_2-1024x218.png)
in the select we put the parameters that we are interested in seeing in the future message that will arrive on our Telegram.
On this example we write:
$HOST as Host, $EVENT as Action, $PARAM:[TargetUserName] as details, $TIMESTAMP as Timestamp
![Telegram App 14 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/event_queries_6.png)
Now set your “FROM” ( The class or classes )
![Telegram App 15 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/from_1.png)
Now i choose the event or events:
![Telegram App 16 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/from_2.png)
Important: we need to verify the proper functioning of our query, NB: before clicking the test button, chech the range time
![Telegram App 17 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/check_query-1024x501.png)
Now press the button = ” Show Scheduling Options “
![Telegram App 18 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/show_scheduling_option-1024x222.png)
put the tick on the flag ” Run Playbook ” and choose our Telegram alert
![Telegram App 19 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/show_scheduling_option_2-1024x612.png)
back to the playbook section
![Telegram App 20 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/PB-1-1024x409.png)
we have to set our Telegram bot credential, to do it we can go on the second rectangle from the left and click on modify:
![Telegram App 21 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/foto_2_2.png)
Name fileld: bot_id ( do not change ), ( we can find in the first part of our guide the credentials that need to be entered )
Value: 1148120703:AbIUGpERusdQDEEag_EL1KDtynRB9sIhbj1
Name fileld: chat_id ( do not change ), ( we can find in the first part of our guide the credentials that need to be entered )
Value: 124229696
Also when we finisched to insert our credential, we can test all and save, close the window
![Telegram App 22 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/edit_node_credential-2-1024x398.png)
go to format message
![Telegram App 23 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/foto_3_3.png)
same passage as before click on the edit button, in the section text we write the telegrammessage that will come to us once we set :
Telegram Alert
Host: $1
Action: $2
Details: $3
Timestamp: $4
the values refer to the query we made earlier, to add parameters in the text message click on plus or trash to delete
Save all with the button on the right “save”
![Telegram App 24 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/foto_3-2-1024x716.png)
Back to Playbook section, search Telegram_Alert and check the status of the playbook on the right side, if it’s green playbook will alert you whenever the event we have indicated will happen
![Telegram App 25 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/usage_3-2-e1718702274450-1024x255.png)
If it’s all correctly, after the login telegram alert me that someone has done a LogonOK
![Telegram App 26 Telegram App](https://www.sgbox.eu/wp-content/uploads/2024/06/tg.png)