Mikrotik telegram notification on openvpn access

From Fvettore-WIKI
Revision as of 09:02, 31 July 2025 by Administrator (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

To receive Telegram notifications for OpenVPN connections/disconnections

In the following example:

  • we have two bot user chatIds (Fabrizio and Banion), respectively 173072004 and 5704842034.
  • the BOT API key is: 1757914630\:AAFw1EE42wCTJ4Vy5HTUtRUb34BQna6nU3I (not a real value, example only)

On the routerboard, open the PPP configuration
In the profile configuration, there is a SCRIPT tab. You can configure scripts for connection and disconnection (On Up & On Down).

Example On Up:

 ;local chatid "173072004"
 ;local chatid1 "5704842034"
 :local botapi "1757914630:AAFw1EE42wCTJ4Vy5HTUtRUb34BQna6nU3I"
 
 :local message "VPN CONNECTION on ";
 :local who "$[/system identity get name]";
 :local address $"remote-address";
 :local caller  $"caller-id";
 
 /tool fetch url="https://api.telegram.org/bot$botapi/sendMessage?text=$message$who USER $user $address $caller&chat_id=$chatid1" keep-result=no;
 /tool fetch url="https://api.telegram.org/bot$botapi/sendMessage?text=$message$who USER $user $address $caller&chat_id=$chatid" keep-result=no;

Example On Down

 ;local chatid "173072004";
 ;local chatid1 "5704842034";
 :local botapi "1757914630:AAFw1EE42wCTJ4Vy5HTUtRUb34BQna6nU3I";
 
 :local message "VPN DISCONNECTED on ";
 :local who "$[/system identity get name]";
 :local address $"remote-address";
 :local caller  $"caller-id";
 
 /tool fetch url="https://api.telegram.org/bot$botapi/sendMessage?text=$message$who USER $user $address $caller&chat_id=$chatid1" keep-result=no;
 /tool fetch url="https://api.telegram.org/bot$botapi/sendMessage?text=$message$who USER $user $address $caller&chat_id=$chatid" keep-result=no;