Receiving devices notifications using Slack and Telegram messengers
2Smart Standalone users receive several types of notifications in the web application: system notifications, notifications from devices, notifications launched by a script, etc.
All notifications can also be received in Slack and Telegram messengers. In this case, the user can constantly monitor events occurring in his ecosystem of IoT devices.
Telegram
To configure a Telegram channel:
- Open Telegram bot.
- To create a new bot, enter: /newbot.
- Specify the bot's name and the bot's username (a name for users to refer to the bot).
- Save the received token (should start with "bot", for example, a valid token might look like this: bot1000000000:AAAAAA_aaaaaaaaa_abcdefghijklmnopq).
Determine chat id:
if the chat is private:
- send any message to the created bot;
- (a) open https://api.telegram.org/%BOT_TOKEN%/getUpdates?allowed_updates=[%22message%22];
- find the last message in the result. If there are many messages in (a), you can find the last one by adding the offset and limit (1 from 100) parameters to the query;
- find the message.chat.id field and save.
if the chat is a group:
- add a bot to the chat;
- (а) open https://api.telegram.org/%BOT_TOKEN%/getUpdates?allowed_updates=[%22message%22];
- find the last message in the result. If there are many messages in (a), you can find the last one by adding the offset and limit (1 from 100) parameters to the query;
- find the field message.chat.id and save; By default, the bot does not see messages in the chat. For a message to appear in getUpdates - in the group add @%BOT_USERNAME% to the message.
Enter the Name, Chat ID and Token in the Telegram channel configuration form.
Token Recovery
To restore the token:
- Open Telegram bot.
- Enter /mybots or /token.
- Select the bot for which the new token is generated.
Slack
To configure a Slack channel:
- Open https://api.slack.com/apps.
- Click on the "Create New App" button.
- Enter the App name and select Workspace.
- In Add features and functionality, click on Incoming Webhooks.
- Change the state of the switch to On.
- Click on "Add New Webhook to Workspace".
- Select a channel, and click on "Allow".
- Copy the generated link
- Enter the Name, and Webhook link in the Slack channel configuration form.
Webhook Recovery
To restore Webhook:
- Open https://api.slack.com/apps.
- Select the desired App.
- In Add features and functionality, click on Incoming Webhooks.