Send telegram messages from Mikrotik RouterOS

If you are here you probably already know what telegram is. If not you can read about it here.

I created a simple script (SendToTelegram) that allows you to send messages to telegram:

:global telegramMessage
:local botid
:local chatid

set botid "sdfzgasf7126jwsd7a8s12>" # <- change this
set chatid "21156423187"            # <- change this

if ($telegramMessage != "") do={
   /tool fetch url="https://api.telegram.org/bot$botid/sendMessage\?chat_id=$chatid&text=$telegramMessage" keep-result=no
   set telegramMessage ""
}

Usage:

set your message to telegramMessage global variable

global telegramMessage "Wolfy was here"

run script

/system script run SendToTelegram

You can use this in combination with netwach:

you should recieve a message to your telegram :)

3 thoughts on “Send telegram messages from Mikrotik RouterOS”

  1. Hi Mario,

    in one of the RouterOS system updates they disabled the option to change global variables.

    One possible solution is to create one script per message and call that “hardcoded” script.

  2. Thank you. This is useful script. Maybe we can use file or other unused configuration parameter to exchange messages instead of global variable. E.g. firewall address list, dummy dns static record or just dummy any config with comment parameter anywhere.

Comments are closed.