Skip to content

ResIOT Telegram Bot Tutorial

Usage

ResIOT allow you to set up your own Telegram BOT customizable through Scene and Advance Scene. Users can interact with bots by sending them messages, commands and inline requests.
You may get notified while a certain event raises or for a real example, when a Node is triggered. In this tutorial we are going to create our custom Telegram Bot through a few steps.

*This guide requires a Telegram account which the Bot will send messages to

1. Get Telegram Token

In order to get your own Bot you need to, first of all, connect to your Telegram account and search for BotFather.

Find

Write the command /newbot in order to create a new Bot.
First of all you need to choose one name for your bot e.g. BotName then it will ask you a more technical name ending in bot e.g botname_bot. Finally it will give you the token to accesso to your bot's API.

Find

2. Get Chat ID

Now you need to open a chat with your new Bot: search for your Bot's name into the research bar, in this case botname_bot and click on Start. Then you have to navigate to the following link in order to retrieve Bot's chat_ID:

https://api.telegram.org/bot<your_token>/getUpdates

The server response will be an encoded JSON message; you have to look for the field id into chat structure:

"chat": {
            "id": 123456789,
            "first_name": ...,
            "last_name": ...,
            "type": ...
        }

Note: if the chat structure doesn't appear in the JSON you can solve this by writing a message into your bot and then reload the page linked before.

3. Create Telegram object on ResIOT

Now that you have your personal Bot with token and chat_id navigate to the Media/Smtp/Telegram field in ResIOT and click on Add New.
First of all select Telegram from the Type menu. Than compile the remaining input fields with a Name, your Token and the Chat ID.

Find

To test connection click on Send button. If everything went good the Bot will send you a message:

Find

Click on Create to save your Telegram Configuration.

4. Scenes and Telegram

Your Telegram configuration now is ready for use all you need to know is its HexID retrievable from the Media/Smtp/Telegram field.
Here are two examples: 1 for Smart Scenes and 1 for Script Lua 5.1 Scene.

Example:

Smart Scenes:

Find Find

Script Lua 5.1 Scenes:
    Message = "ResIOT Message"
    HexadecimalId = "ad246D3F"
    AllWorked = resiot_telegram(Message, HexadecimalId)
    if AllWorked ~= "" then
        resiot_debug(AllWorked)
    end