Agents Standing By: Notifications through Telegram
I got a request to go over the setup of a Telegram agent for Huginn. I personally don’t use Telegram at the moment, but I managed to get a basic bot set up.
Create your Telegram bot⌗
First you will need to create a bot by messaging the BotFather and requesting a new bot.
This can be done by typing /newbot
and then filling out the prompts for a username and bot name.
Once this is completed, BotFather will give you an HTTP API token. We will need this value.
Click the link to start messaging your bot. Send a message, this will come in handy later.
Setting up the Telegram Agent⌗
In Huginn, we will create a new Telegram Agent.
The fields are pretty self explanatory.
- Paste your auth token from BotFather into the Auth token field
- To get your
chat_id
, visithttps://api.telegram.org/bot<API TOKEN>/getUpdates
, replacing<API TOKEN>
with your actual token. Then theid
field underchat
will have thechat_id
. - Change other options to preference
I think parsing into markdown is great, since I am familiar with it already.
Sending Data⌗
The Telegram agent expects events with one of the following tags: text
, photo
, audio
, document
or video
.
Most likely you will need to use an EventFormattingAgent
to put your desired messages into this format.
To test it out, I created a simple ManualEventAgent
and pointed it at the Telegram agent.
I fired off an event that was simply
{
"text": "Hello World"
}
and promptly received the text “Hello World” from my bot.
With the use of the EventFormattingAgent
and a bit of imagination, you can format pretty much any incoming event to a telegram message