Support for When-Then Rules Webhook Action - Telegram Integration

Hi everyone.

I see that in the new version of OR there is the webhook option for the when-then rules. I consult them if they tried the integration with the Telegram bot. In the smartcity demo I don’t see any example of webhook.
Thank you very much.

Hi! The webhook works as follows:

When the rule is triggered, an HTTP Request is sent to the web url you specify.
You can add headers, authorization, and customize the body that is sent.
An example use case would be that you are developing your own application, that has a rest api endpoint where OpenRemote can send http requests to.

I don’t know anything about Telegram bots and what use case you have with them, but you could send a request directly to their API and change the body that needs to be sent.

About whether we tried integrating with 3rd parties;
We have tested sending webhook requests to several HTTP API’s, not specifically with Telegram.
It should support any url you specify; whether it is your own service or an external one.

I btw should mention that the webhook form in the screenshot looks like an older version.
We have made changes and fixed some webhook bugs recently, so I would recommend to try updating. :wink:

1 Like

Thank you very much Martin. I test the integration with Telegram and post the result on the forum.

Mariano

1 Like

Good afternoon, I was finally able to make sending messages to a Telegram channel or group work. This allows receiving alerts to a Telegram group or channel through OR rules.

The procedure would be the following:

Step 1: Create a Telegram BOT
Create a Telegram BOT via BotFather
Click here or search for the username “@botfather” in Telegram and click on it to start the chat.
Then, click on the START button at the bottom of the chat.
Send the following commands in your chat:
/start

It will show you a lot of options. Then type:
/newbot

Now it will ask you to choose the name of your bot. For example type:

Alarms 1 Open Remote

Now it will ask you to choose a username for your bot.

But, it should end with _bot suffix. For example type:

oralarm1_bot

Now, your bot is ready. It will return you an HTTP API value which looks something like the below value:

1234567890:AAAAxY6udNO5u-9fO793yFdZaL1qU2RIkGT

Note: Do not share this value with anyone because it can be used to control your bot.

Step 2: You must have a Telegram Channel
Create a Telegram public channel
Open Telegram on your mobile, and click on New Channel option from the menu.
Then give your channel a name. For example “Alarms 1”
Choose a username for your channel. For example “usealarms”
Add any single contact of one of your family or friends to your channel.

Step 3: Add your BOT to your Telegram Channel
Open your channel details and click on Administrators option.
Then click on Add Admin and search for your bot username and add it.
That’s it. You are ready to send your first message via Bot API. Copy the below the HTTP GET request and replace BOT API KEY, CHANNEL USERNAME & MESSAGE TEXT with your values:

https://api.telegram.org/bot[BOT API KEY]/sendMessage?chat_id=[ID CHANNEL]&text=[MESSAGE TEXT]

The command to get the channel ID

https://api.telegram.org/bot1234567890:AAAAxY6udNO5u-9fO793yFdZaL1qU2RIkGT/getUpdates

“my_chat_member”:{“chat”:{“id”:-100180168898,“title”:“Alarms 1”,“type”:“channel”},“from”:

You can use any browser to test it. Just paste this in the URL section.

https://api.telegram.org/bot1234567890:AAAAxY6udNO5u-9fO793yFdZaL1qU2RIkGT/sendMessage?chat_id=-100180168898&text=high%20power%20consumption%20alarm

Now we can use that link in the “WEB URL” of the OR When-Then Rules webhook. The text to send must be modified according to what you want to alert. For now I did not find the way to use the Body in the request.

4 Likes