aboutsummaryrefslogtreecommitdiffstats
path: root/telegram-chat.rsc
diff options
context:
space:
mode:
Diffstat (limited to 'telegram-chat.rsc')
-rw-r--r--telegram-chat.rsc19
1 files changed, 14 insertions, 5 deletions
diff --git a/telegram-chat.rsc b/telegram-chat.rsc
index f2750f5..10952a6 100644
--- a/telegram-chat.rsc
+++ b/telegram-chat.rsc
@@ -1,16 +1,18 @@
#!rsc by RouterOS
# RouterOS script: telegram-chat
-# Copyright (c) 2023-2024 Christian Hesse <mail@eworm.de>
-# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
+# Copyright (c) 2023-2025 Christian Hesse <mail@eworm.de>
+# https://rsc.eworm.de/COPYING.md
#
# requires RouterOS, version=7.15
+# requires device-mode, fetch
#
# use Telegram to chat with your Router and send commands
-# https://git.eworm.de/cgit/routeros-scripts/about/doc/telegram-chat.md
+# https://rsc.eworm.de/doc/telegram-chat.md
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
+:local ExitOK false;
:do {
:local ScriptName [ :jobname ];
@@ -35,6 +37,7 @@
:global MIN;
:global MkDir;
:global RandomDelay;
+ :global RmDir;
:global ScriptLock;
:global SendTelegram2;
:global SymbolForNotification;
@@ -43,6 +46,7 @@
:global WaitFullyConnected;
:if ([ $ScriptLock $ScriptName ] = false) do={
+ :set ExitOK true;
:error false;
}
@@ -57,6 +61,7 @@
:if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" ] = false) do={
$LogPrint warning $ScriptName ("Downloading required certificate failed.");
+ :set ExitOK true;
:error false;
}
@@ -82,6 +87,7 @@
:if ($Data = false) do={
$LogPrint warning $ScriptName ("Failed getting updates.");
+ :set ExitOK true;
:error false;
}
@@ -130,6 +136,7 @@
:local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]);
:if ([ $MkDir "tmpfs/telegram-chat" ] = false) do={
$LogPrint error $ScriptName ("Failed creating directory!");
+ :set ExitOK true;
:error false;
}
$LogPrint info $ScriptName ("Running command from update " . $UpdateID . ": " . $Command);
@@ -148,7 +155,7 @@
$State . [ $IfThenElse ([ :len $Content ] > 0) \
([ $SymbolForNotification "memo" ] . "Output:\n" . $Content) \
([ $SymbolForNotification "memo" ] . "No output.") ]) });
- /file/remove "tmpfs/telegram-chat";
+ $RmDir "tmpfs/telegram-chat";
} else={
$LogPrint info $ScriptName ("The command from update " . $UpdateID . " failed syntax validation!");
$SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=false; replyto=($Message->"message_id"); \
@@ -176,4 +183,6 @@
}
:set TelegramChatOffset ([ :pick $TelegramChatOffset 1 3 ], \
[ $IfThenElse ($UpdateID >= $TelegramChatOffset->2) ($UpdateID + 1) ($TelegramChatOffset->2) ]);
-} on-error={ }
+} on-error={
+ :global ExitError; $ExitError $ExitOK [ :jobname ];
+}