Manual:The Dude v6/Dude Telegram Example
Overview
Here is quick example how to instantly send messages from your RouterOS (Dude) to Telegram bot.
1. Create Telegram BOT.
To receive messages from the Dude server / RouterOS, you will need to create your Telegram BOT, more information can be found on this page:
When the bot will be created, you will receive token which can be used for HTTP API
Token Example: 309683994:AAFh8645FeAOgUbcOgUVIhtclbmzpwwIXpAB
For a description of the Bot API, see this page: https://core.telegram.org/bots/api
2. Send messages from RouterOS/Dude .
Telegram supports both - GET and POST HTTP method. Since /tool fetch is able to use HTTP GET method you can use this tool to send instant messages to Telegram
To successfully send message to your bot, you will need to know the bot token. Simple send message looks like this:
/tool fetch url="https://api.telegram.org/bot309683994:AAFh8645FeAOgUbcOgUVIhtclbmzpwwIXpAB/sendMessage\?chat_id=312605050&text=ExampleMessage"
Where the HTTPs URL GET query string is created from:
- https://api.telegram.org/bot - The base of URL
- 309683994:AAFh8645FeAOgUbcOgUVIhtclbmzpwwIXpAB - Your Telegram bot token
- /sendMessage - Command type
- \?chat_id=312605050 - 312605050 is the chat where messages will appear
- &text=ExampleMessage - ExampleMessage is message string, which will be sent to your bot
Note: Note that "?" need to be escaped with backlash
The variables in the URL you will need to change:
/tool fetch url="https://api.telegram.org/bot309683994:AAFh8645FeAOgUbcOgUVIhtclbmzpwwIXpAB/sendMessage\?chat_id=312605050&text=ExampleMessage"
Most likely you will use the same bot and chat, this means each time you will need to change only message text:
/tool fetch url="https://api.telegram.org/bot309683994:AAFh8645FeAOgUbcOgUVIhtclbmzpwwIXpA/sendMessage\?chat_id=312605050&text=ExampleMessage"
If the Telegram bot is configured correctly, you should instantly see the message, when the tool fetch command is executed in RouterOS/Dude.
Dude notification example using Telegram bot
You can use Dude to execute commands in your RouterOS, this means you can use same tool fetch to send messages from the Dude server.
Dude notidication type which allows to execute commands in RouterOS is called execute on server. More about Dude notifications can be found here: http://wiki.mikrotik.com/wiki/Manual:The_Dude_v6/Notifications
To create new notification, that will send messages to Telegram bot follow these steps:
1. Create new notification, with notification type "execute on server" 2. Add tool fetch command in the Command field
It's also possible to use Dude variables in the command:
/tool fetch url="https://api.telegram.org/bot309683994:AAFh8645FeAOgUbcOgUVIhtclbmzpwwIXpA/sendMessage\?chat_id=312605050&text=Time: [Time]; Device: [Device.FirstAddress]; Status: [Service.Status]"
This code will result in telegram notification messages:
Test fetch command
Note: The fastest way to check if everything works correctly is to use "Test" button, just note that with "Test" button Dude variables will not work, that's why for testing purposes use simple text.