]> Git [git.vados.ru] :: Repos - Mikrotiks/ros.vados.ru.git/commitdiff
Autocommit in repo: ros.vados.ru, generated by owner: root, in 00:35:03 01.05.2026.
authorvados-dev <192440777+vados-dev@users.noreply.github.com>
Thu, 30 Apr 2026 21:35:03 +0000 (00:35 +0300)
committervados-dev <192440777+vados-dev@users.noreply.github.com>
Thu, 30 Apr 2026 21:35:03 +0000 (00:35 +0300)
html/AM-GlobalFunc.rsc
html/mod/AM-TG-Notifications.rsc
html/mod/AM-TG-Notifications.rsc.diff
html/mod/notification-telegram.rsc

index 8afe83fd0bcf65697fecc347ac68a4025c343aa6..a30e4f6ee93e1807c3292bfca320ec2152419569 100644 (file)
@@ -17,9 +17,9 @@
 :global GlobalFuncReady false;
 
 # Git commit id & info, expected configuration version
-:global CommitId "main/318/cc6455ca";
+:global CommitId "main/319/8b20c54e";
 :global CommitTAG "unknown";
-:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 00:30:03 01.05.2026.";
+:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 00:35:03 01.05.2026.";
 
 # The variables are received right here.
 :global GlobalConfVersion 138;
index 63bc2b292f8e0b0a365212c8ad81b16e8c223899..de283f17db72eba41868352efa980347ec959c74 100644 (file)
@@ -12,7 +12,6 @@
 :global PurgeTelegramQueue;
 :global SendTelegram;
 :global SendTelegram2;
-
 # flush telegram queue
 :set FlushTelegramQueue do={ :onerror Err {
   :global TelegramQueue;
@@ -20,7 +19,6 @@
   :global CertificateAvailable;
   :global IsFullyConnected;
   :global LogPrint;
-
   :if ([ $IsFullyConnected ] = false) do={
     $LogPrint debug $0 ("System is not fully connected, not flushing.");
     :return false;
@@ -29,7 +27,6 @@
     $LogPrint warning $0 ("Downloading required certificate failed.");
     :return false;
   }
-
   :local AllDone true;
   :local QueueLen [ :len $TelegramQueue ];
   :if ([ :len [ /system/scheduler/find where name="_FlushTelegramQueue" ] ] > 0 && $QueueLen = 0) do={
@@ -56,7 +53,6 @@
 } do={
 :global ExitOnError; $ExitOnError $0 $Err;
 } }
-
 # get the chat id
 :set GetTelegramChatId do={ :onerror Err {
   :global TelegramTokenId;
@@ -93,7 +89,6 @@
 # send notification via telegram - expects one array argument
 :set ($NotificationFunctions->"telegram") do={
   :local Notification $1;
-
   :global Identity;
   :global IdentityExtra;
   :global TelegramChatId;
   :global TelegramTokenId;
   :global TelegramTokenIdOverride;
   :global CertificateAvailable;
-
   :global CharacterReplace;
   :global EitherOr;
   :global IfThenElse;
   :global ProtocolStrip;
   :global SymbolForNotification;
   :global UrlEncode;
-
   :local EscapeMD do={
     :local Text [ :tostr $1 ];
     :local Mode [ :tostr $2 ];
     :local Excl [ :tostr $3 ];
-
     :global CharacterReplace;
     :global IfThenElse;
-
     :local Chars {
        "body"={ "\\"; "`" };
       "plain"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">";
     }
   }
 }
-
 # purge the Telegram queue
 :set PurgeTelegramQueue do={
   :global TelegramQueue;
   /system/scheduler/remove [ find where name="_FlushTelegramQueue" ];
   :set TelegramQueue;
 }
-
 # send notification via telegram - expects at least two string arguments
 :set SendTelegram do={ :onerror Err {
   :global SendTelegram2;
   $SendTelegram2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 });
-} do={:global ExitOnError; $ExitOnError $0 $Err}
-}
-
+} do={:global ExitOnError; $ExitOnError $0 $Err.
+} }
 # send notification via telegram - expects one array argument
 :set SendTelegram2 do={
   :local Notification $1;
index 63a688a445e807c6c5a176b5a4d9474c5a26dd5c..d5f762323afe9917b340063ceab6e4f5b1b13432 100644 (file)
@@ -1,87 +1,43 @@
-19a20
-> 
-27a29
-> 
-34a37
-> 
-37a41
-> 
-51a56
-> 
-57c62
+54c54
 < :global ExitOnError; $ExitOnError $0 $Err;
 ---
 >   :global ExitOnError; $ExitOnError $0 $Err;
-62a68
-> 
-64a71
-> 
-68a76
-> 
-77a86
-> 
-79a89
-> 
-83a94
-> 
-90c101
+86c86
 < :global ExitOnError; $ExitOnError $0 $Err;
 ---
 >   :global ExitOnError; $ExitOnError $0 $Err;
-107d117
-<   :global CertificateAvailable;
-108a119
->   :global CertificateAvailable;
-135c146,150
+88d87
+< 
+126c125,127
 <     :if ($Mode = "body") do={:return ("```\n" . $Text . "\n```")}
 ---
-> 
 >     :if ($Mode = "body") do={
 >       :return ("```\n" . $Text . "\n```");
 >     }
-> 
-137a153
-> 
-144,145c160,168
+135,136c136,141
 <   :if ([ :len $TokenId ] = 0 || [ :len $ChatId ] = 0) do={:return false}
 <   :if ([ :typeof $TelegramMessageIDs ] = "nothing") do={:set TelegramMessageIDs ({})}
 ---
-> 
 >   :if ([ :len $TokenId ] = 0 || [ :len $ChatId ] = 0) do={
 >     :return false;
 >   }
-> 
 >   :if ([ :typeof $TelegramMessageIDs ] = "nothing") do={
 >     :set TelegramMessageIDs ({});
 >   }
-> 
-156c179,181
+147c152,154
 <   } else={:set Text ($Text . [ $EscapeMD ($Notification->"message") "body" ])}
 ---
 >   } else={
 >     :set Text ($Text . [ $EscapeMD ($Notification->"message") "body" ]);
 >   }
-166a192
-> 
-181c207,210
+172c179,181
 <     :if ([ :typeof $TelegramQueue ] = "nothing") do={:set TelegramQueue ({})}
 ---
-> 
 >     :if ([ :typeof $TelegramQueue ] = "nothing") do={
 >       :set TelegramQueue ({});
 >     }
-196a226
-> 
-203a234
-> 
-205,206c236,238
-< } do={:global ExitOnError; $ExitOnError $0 $Err}
-< }
+194c203,204
+< } do={:global ExitOnError; $ExitOnError $0 $Err.
 ---
 > } do={
 >   :global ExitOnError; $ExitOnError $0 $Err;
-> } }
-210a243
-> 
-211a245
-> 
index 84f4bc98df4ad834f53551614b1991915b988871..884ccb993111e381e29eaedf06fa38b87871431e 100644 (file)
 :global PurgeTelegramQueue;
 :global SendTelegram;
 :global SendTelegram2;
-
 # flush telegram queue
 :set FlushTelegramQueue do={ :onerror Err {
   :global TelegramQueue;
   :global TelegramMessageIDs;
-
   :global CertificateAvailable;
   :global IsFullyConnected;
   :global LogPrint;
-
   :if ([ $IsFullyConnected ] = false) do={
     $LogPrint debug $0 ("System is not fully connected, not flushing.");
     :return false;
   }
-
   :if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" "fetch" ] = false) do={
     $LogPrint warning $0 ("Downloading required certificate failed.");
     :return false;
   }
-
   :local AllDone true;
   :local QueueLen [ :len $TelegramQueue ];
-
   :if ([ :len [ /system/scheduler/find where name="_FlushTelegramQueue" ] ] > 0 && $QueueLen = 0) do={
     $LogPrint warning $0 ("Flushing Telegram messages from scheduler, but queue is empty.");
   }
-
   :foreach Id,Message in=$TelegramQueue do={
     :if ([ :typeof $Message ] = "array" ) do={
       :onerror Err {
@@ -53,7 +46,6 @@
       }
     }
   }
-
   :if ($AllDone = true && $QueueLen = [ :len $TelegramQueue ]) do={
     /system/scheduler/remove [ find where name="_FlushTelegramQueue" ];
     :set TelegramQueue;
 } do={
   :global ExitOnError; $ExitOnError $0 $Err;
 } }
-
 # get the chat id
 :set GetTelegramChatId do={ :onerror Err {
   :global TelegramTokenId;
-
   :global CertificateAvailable;
   :global LogPrint;
-
   :if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" "fetch" ] = false) do={
     $LogPrint warning $0 ("Downloading required certificate failed.");
     :return false;
   }
-
   :local Data;
   :onerror Err {
     :set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
     $LogPrint warning $0 ("Fetching data failed: " . $Err);
     :return false;
   }
-
   :local JSON [ :deserialize from=json value=$Data ];
   :local Count [ :len ($JSON->"result") ];
-
   :if ($Count = 0) do={
     $LogPrint info $0 ("No message received.");
     :return false;
   }
-
   :local Message ($JSON->"result"->($Count - 1)->"message");
   $LogPrint info $0 ("The chat id is: " . ($Message->"chat"->"id"));
   :if (($Message->"is_topic_message") = true) do={
 } do={
   :global ExitOnError; $ExitOnError $0 $Err;
 } }
-
 # send notification via telegram - expects one array argument
 :set ($NotificationFunctions->"telegram") do={
   :local Notification $1;
-
   :global Identity;
   :global IdentityExtra;
   :global TelegramChatId;
   :global TelegramThreadIdOverride;
   :global TelegramTokenId;
   :global TelegramTokenIdOverride;
-
   :global CertificateAvailable;
   :global CharacterReplace;
   :global EitherOr;
   :global ProtocolStrip;
   :global SymbolForNotification;
   :global UrlEncode;
-
   :local EscapeMD do={
     :local Text [ :tostr $1 ];
     :local Mode [ :tostr $2 ];
     :local Excl [ :tostr $3 ];
-
     :global CharacterReplace;
     :global IfThenElse;
-
     :local Chars {
        "body"={ "\\"; "`" };
       "plain"={ "_"; "*"; "["; "]"; "("; ")"; "~"; "`"; ">";
         :set Text [ $CharacterReplace $Text $Char ("\\" . $Char) ];
       }
     }
-
     :if ($Mode = "body") do={
       :return ("```\n" . $Text . "\n```");
     }
-
     :return $Text;
   }
-
   :local ChatId [ $EitherOr ($Notification->"chatid") \
     [ $EitherOr ($TelegramChatIdOverride->($Notification->"origin")) $TelegramChatId ] ];
   :local ThreadId [ $EitherOr ($Notification->"threadid") \
     [ $EitherOr ($TelegramThreadIdOverride->($Notification->"origin")) \
     [ $IfThenElse ([ :len ($TelegramChatIdOverride->($Notification->"origin")) ] = 0) $TelegramThreadId ] ] ];
   :local TokenId [ $EitherOr ($TelegramTokenIdOverride->($Notification->"origin")) $TelegramTokenId ];
-
   :if ([ :len $TokenId ] = 0 || [ :len $ChatId ] = 0) do={
     :return false;
   }
-
   :if ([ :typeof $TelegramMessageIDs ] = "nothing") do={
     :set TelegramMessageIDs ({});
   }
-
   :local Truncated false;
   :local Text ("*__" . [ $EscapeMD ("[" . $IdentityExtra . $Identity . "] " . \
     ($Notification->"subject")) "plain" ] . "__*\n\n");
       [ $EscapeMD ("The message was too long and has been truncated, cut off _" . \
       (($LenSum - [ :len $Text ]) * 100 / $LenSum) . "%_!") "plain" "_" ]);
   }
-
   :local HTTPData ("chat_id=" . $ChatId . "&disable_notification=" . ($Notification->"silent") . \
       "&reply_to_message_id=" . ($Notification->"replyto") . "&message_thread_id=" . $ThreadId . \
       "&disable_web_page_preview=true&parse_mode=MarkdownV2");
     :set ($TelegramMessageIDs->[ :tostr ([ :deserialize from=json value=$Data ]->"result"->"message_id") ]) 1;
   } do={
     $LogPrint info $0 ("Failed sending Telegram notification: " . $Err . " - Queuing...");
-
     :if ([ :typeof $TelegramQueue ] = "nothing") do={
       :set TelegramQueue ({});
     }
     }
   }
 }
-
 # purge the Telegram queue
 :set PurgeTelegramQueue do={
   :global TelegramQueue;
-
   /system/scheduler/remove [ find where name="_FlushTelegramQueue" ];
   :set TelegramQueue;
 }
-
 # send notification via telegram - expects at least two string arguments
 :set SendTelegram do={ :onerror Err {
   :global SendTelegram2;
-
   $SendTelegram2 ({ origin=$0; subject=$1; message=$2; link=$3; silent=$4 });
 } do={
   :global ExitOnError; $ExitOnError $0 $Err;
 } }
-
 # send notification via telegram - expects one array argument
 :set SendTelegram2 do={
   :local Notification $1;
-
   :global NotificationFunctions;
-
   ($NotificationFunctions->"telegram") ("\$NotificationFunctions->\"telegram\"") $Notification;
 }