9 февр. 2023 г.

Microtik ppp-up and ppp-down scripts Telegram notification

 Global script (go to /system script) name - SendTelegram

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

Up script in the ppp profile

global telegramMessage
:local remoteAddr
:local callerId
:set remoteAddr $"remote-address"
:set callerId $"caller-id"
:set telegramMessage "Connected $user from $callerId with ip $remoteAddr"
/system script run SendTelegram

Down script in the ppp profile

global telegramMessage
:local remoteAddr
:local callerId
:set remoteAddr $"remote-address"
:set callerId $"caller-id"
:set telegramMessage "Disconnected $user from $callerId with ip $remoteAddr"
/system script run SendTelegram

Got from Here and Here