From 399d952ac21057c5ab88120bef4a400b06caea3b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 10 Oct 2023 13:16:58 +0200 Subject: telegram-chat: act on reply from self --- news-and-changes.rsc | 1 + 1 file changed, 1 insertion(+) (limited to 'news-and-changes.rsc') diff --git a/news-and-changes.rsc b/news-and-changes.rsc index b027fb6..bbbaad6 100644 --- a/news-and-changes.rsc +++ b/news-and-changes.rsc @@ -19,6 +19,7 @@ 103="Dropped hard-coded name and timeout from 'hotspot-to-wpa-cleanup', instead a comment is required for dhcp server now."; 104="All relevant scripts were ported to new wifiwave2 and are available for AX devices now!"; 105="Extended 'check-routeros-update' to support automatic update from specific neighbor(s)."; + 106="Modified 'telegram-chat' to make it act on message replies, without activation."; }; # Migration steps to be applied on script updates -- cgit v1.2.3-54-g00ecf From 1b62545d8c5b186e9059c9640761a12ad336ec7b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 13 Oct 2023 21:54:50 +0200 Subject: telegram-chat: answer question mark with short notice --- doc/telegram-chat.md | 5 +++++ news-and-changes.rsc | 2 +- telegram-chat.rsc | 8 +++++++- 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'news-and-changes.rsc') diff --git a/doc/telegram-chat.md b/doc/telegram-chat.md index 3cbc710..79a9eb1 100644 --- a/doc/telegram-chat.md +++ b/doc/telegram-chat.md @@ -78,6 +78,11 @@ Associated messages are cleared on device reboot. > ⚠️ **Warning**: If another device is activated both will act, the one from > reply and the active one! +### Ask for devices + +Send a message with a single question mark (`?`) to query for devices +currenty online. The answer can be used for command via reply then. + Known limitations ----------------- diff --git a/news-and-changes.rsc b/news-and-changes.rsc index bbbaad6..49b1671 100644 --- a/news-and-changes.rsc +++ b/news-and-changes.rsc @@ -19,7 +19,7 @@ 103="Dropped hard-coded name and timeout from 'hotspot-to-wpa-cleanup', instead a comment is required for dhcp server now."; 104="All relevant scripts were ported to new wifiwave2 and are available for AX devices now!"; 105="Extended 'check-routeros-update' to support automatic update from specific neighbor(s)."; - 106="Modified 'telegram-chat' to make it act on message replies, without activation."; + 106="Modified 'telegram-chat' to make it act on message replies, without activation. Also made it answer a single question mark with a short notice."; }; # Migration steps to be applied on script updates diff --git a/telegram-chat.rsc b/telegram-chat.rsc index e063e80..16edbca 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -77,7 +77,13 @@ $WaitFullyConnected; :if ($Trusted = true) do={ :local Done false; - :if ([ :pick ($Message->"text") 0 1 ] = "!") do={ + :if ($Message->"text" = "?") do={ + $SendTelegram2 ({ origin=$0; chatid=($Chat->"id"); silent=false; replyto=($Message->"message_id"); \ + subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \ + message=("Online, awaiting your commands!") }); + :set Done true; + } + :if ($Done = false && [ :pick ($Message->"text") 0 1 ] = "!") do={ :if ($Message->"text" ~ ("^! *(" . [ $EscapeForRegEx $Identity ] . "|@" . $TelegramChatGroups . ")\$")) do={ :set TelegramChatActive true; } else={ -- cgit v1.2.3-54-g00ecf From fed7f2da46fc02b12d23c0f05111452b8e9935e6 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 13 Oct 2023 16:42:24 +0200 Subject: mod/notification-telegram: drop support for non-fixed width font --- global-config.rsc | 2 -- global-functions.rsc | 2 +- mod/notification-telegram.rsc | 15 +++------------ news-and-changes.rsc | 1 + 4 files changed, 5 insertions(+), 15 deletions(-) (limited to 'news-and-changes.rsc') diff --git a/global-config.rsc b/global-config.rsc index 172c4cd..0ea18e5 100644 --- a/global-config.rsc +++ b/global-config.rsc @@ -41,8 +41,6 @@ #}; :global TelegramChatGroups "(all)"; #:global TelegramChatGroups "(all|home|office)"; -# This is whether or not to send Telegram messages with fixed-width font. -:global TelegramFixedWidthFont true; # You can send Matrix notifications. Configure these settings and # install the module: diff --git a/global-functions.rsc b/global-functions.rsc index dbedfbc..4617a3a 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -12,7 +12,7 @@ :local 0 "global-functions"; # expected configuration version -:global ExpectedConfigVersion 106; +:global ExpectedConfigVersion 107; # global variables not to be changed by user :global GlobalFunctionsReady false; diff --git a/mod/notification-telegram.rsc b/mod/notification-telegram.rsc index 641c6f0..b5729a4 100644 --- a/mod/notification-telegram.rsc +++ b/mod/notification-telegram.rsc @@ -40,7 +40,7 @@ ("https://api.telegram.org/bot" . ($Message->"tokenid") . "/sendMessage") \ http-data=("chat_id=" . ($Message->"chatid") . "&disable_notification=" . ($Message->"silent") . \ "&reply_to_message_id=" . ($Message->"replyto") . "&disable_web_page_preview=true" . \ - "&parse_mode=" . ($Message->"parsemode") . "&text=" . ($Message->"text")) as-value ]->"data"); + "&parse_mode=MarkdownV2&text=" . ($Message->"text")) as-value ]->"data"); :set ($TelegramQueue->$Id); :set ($TelegramMessageIDs->([ $ParseJson ([ $ParseJson $Data ]->"result") ]->"message_id")) 1; } on-error={ @@ -64,7 +64,6 @@ :global IdentityExtra; :global TelegramChatId; :global TelegramChatIdOverride; - :global TelegramFixedWidthFont; :global TelegramMessageIDs; :global TelegramQueue; :global TelegramTokenId; @@ -80,15 +79,9 @@ :global UrlEncode; :local EscapeMD do={ - :global TelegramFixedWidthFont; - :global CharacterReplace; :global IfThenElse; - :if ($TelegramFixedWidthFont != true) do={ - :return ($1 . [ $IfThenElse ($2 = "body") ("\n") "" ]); - } - :local Return $1; :local Chars { "body"={ "\\"; "`" }; @@ -140,7 +133,6 @@ (($LenSum - [ :len $Text ]) * 100 / $LenSum) . "%!") "plain" ]); } :set Text [ $UrlEncode $Text ]; - :local ParseMode [ $IfThenElse ($TelegramFixedWidthFont = true) "MarkdownV2" "" ]; :do { :if ([ $CertificateAvailable "Go Daddy Secure Certificate Authority - G2" ] = false) do={ @@ -150,7 +142,7 @@ ("https://api.telegram.org/bot" . $TokenId . "/sendMessage") \ http-data=("chat_id=" . $ChatId . "&disable_notification=" . ($Notification->"silent") . \ "&reply_to_message_id=" . ($Notification->"replyto") . "&disable_web_page_preview=true" . \ - "&parse_mode=" . $ParseMode . "&text=" . $Text) as-value ]->"data"); + "&parse_mode=MarkdownV2&text=" . $Text) as-value ]->"data"); :set ($TelegramMessageIDs->([ $ParseJson ([ $ParseJson $Data ]->"result") ]->"message_id")) 1; } on-error={ $LogPrintExit2 info $0 ("Failed sending telegram notification! Queuing...") false; @@ -162,8 +154,7 @@ [ $EscapeMD ("This message was queued since " . [ /system/clock/get date ] . \ " " . [ /system/clock/get time ] . " and may be obsolete.") "plain" ]) ]); :set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TokenId; - parsemode=$ParseMode; text=$Text; silent=($Notification->"silent"); - replyto=($Notification->"replyto") }; + text=$Text; silent=($Notification->"silent"); replyto=($Notification->"replyto") }; :if ([ :len [ /system/scheduler/find where name="\$FlushTelegramQueue" ] ] = 0) do={ /system/scheduler/add name="\$FlushTelegramQueue" interval=1m start-time=startup \ on-event=(":global FlushTelegramQueue; \$FlushTelegramQueue;"); diff --git a/news-and-changes.rsc b/news-and-changes.rsc index 49b1671..d20ace0 100644 --- a/news-and-changes.rsc +++ b/news-and-changes.rsc @@ -20,6 +20,7 @@ 104="All relevant scripts were ported to new wifiwave2 and are available for AX devices now!"; 105="Extended 'check-routeros-update' to support automatic update from specific neighbor(s)."; 106="Modified 'telegram-chat' to make it act on message replies, without activation. Also made it answer a single question mark with a short notice."; + 107="Dropped support for non-fixed width font in Telegram notifications."; }; # Migration steps to be applied on script updates -- cgit v1.2.3-54-g00ecf