From fd1263324dbbb0e80bc99e30d317eca9fd7b264b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 11 Oct 2023 11:48:49 +0200 Subject: doc/telegram-chat: update screenshots --- doc/telegram-chat.d/01-chat-specific.avif | Bin 31869 -> 38468 bytes doc/telegram-chat.d/02-chat-all.avif | Bin 48099 -> 54713 bytes 2 files changed, 0 insertions(+), 0 deletions(-) (limited to 'doc') diff --git a/doc/telegram-chat.d/01-chat-specific.avif b/doc/telegram-chat.d/01-chat-specific.avif index 387dc3a..ab75f78 100644 Binary files a/doc/telegram-chat.d/01-chat-specific.avif and b/doc/telegram-chat.d/01-chat-specific.avif differ diff --git a/doc/telegram-chat.d/02-chat-all.avif b/doc/telegram-chat.d/02-chat-all.avif index 32fc181..ed1a389 100644 Binary files a/doc/telegram-chat.d/02-chat-all.avif and b/doc/telegram-chat.d/02-chat-all.avif differ -- cgit v1.2.3-70-g09d2 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 --- doc/telegram-chat.d/03-reply.avif | Bin 0 -> 50126 bytes doc/telegram-chat.md | 15 +++++++++++++++ global-functions.rsc | 2 +- news-and-changes.rsc | 1 + telegram-chat.rsc | 4 +++- 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 doc/telegram-chat.d/03-reply.avif (limited to 'doc') diff --git a/doc/telegram-chat.d/03-reply.avif b/doc/telegram-chat.d/03-reply.avif new file mode 100644 index 0000000..515853e Binary files /dev/null and b/doc/telegram-chat.d/03-reply.avif differ diff --git a/doc/telegram-chat.md b/doc/telegram-chat.md index 391042d..3cbc710 100644 --- a/doc/telegram-chat.md +++ b/doc/telegram-chat.md @@ -46,6 +46,8 @@ parameters: Usage and invocation -------------------- +### Activating device(s) + This script is capable of chatting with multiple devices. By default a device is passive and not acting on messages. To activate it send a message containing `! identity` (exclamation mark, optional space and system's @@ -63,6 +65,19 @@ act on your commands. Send a single exclamation mark or non-existent identity to make all devices passive again. +### Reply to message + +Let's assume you received a message from a device before, and want to send +a command to that device. No need to activate it, you can just reply to +that message. + +![reply to message](telegram-chat.d/03-reply.avif) + +Associated messages are cleared on device reboot. + +> ⚠️ **Warning**: If another device is activated both will act, the one from +> reply and the active one! + Known limitations ----------------- diff --git a/global-functions.rsc b/global-functions.rsc index df374b8..dbedfbc 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -12,7 +12,7 @@ :local 0 "global-functions"; # expected configuration version -:global ExpectedConfigVersion 105; +:global ExpectedConfigVersion 106; # global variables not to be changed by user :global GlobalFunctionsReady false; 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 diff --git a/telegram-chat.rsc b/telegram-chat.rsc index 6083fee..29130db 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -17,6 +17,7 @@ :global TelegramChatIdsTrusted; :global TelegramChatOffset; :global TelegramChatRunTime; +:global TelegramMessageIDs; :global TelegramTokenId; :global CertificateAvailable; @@ -83,7 +84,8 @@ $WaitFullyConnected; $LogPrintExit2 info $0 ("Now " . [ $IfThenElse $TelegramChatActive "active" "passive" ] . \ " from update " . $UpdateID . "!") false; } else={ - :if ($TelegramChatActive = true && [ :len ($Message->"text") ] > 0) do={ + :if (($TelegramMessageIDs->([ $ParseJson ($Message->"reply_to_message") ]->"message_id") = 1 || \ + $TelegramChatActive = true) && [ :len ($Message->"text") ] > 0) do={ :if ([ $ValidateSyntax ($Message->"text") ] = true) do={ :local State ""; :local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]); -- cgit v1.2.3-70-g09d2 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 'doc') 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-70-g09d2 From c9233773b3a1dd967d1dd5924c5f00c516d55d41 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 16 Oct 2023 13:07:29 +0200 Subject: telegram-chat: do not act on foreign reply... ... even if active! --- doc/telegram-chat.md | 3 --- telegram-chat.rsc | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/doc/telegram-chat.md b/doc/telegram-chat.md index 79a9eb1..397920a 100644 --- a/doc/telegram-chat.md +++ b/doc/telegram-chat.md @@ -75,9 +75,6 @@ that message. 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 diff --git a/telegram-chat.rsc b/telegram-chat.rsc index 1a89544..2bd8ccd 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -63,6 +63,7 @@ $WaitFullyConnected; :local Update [ $ParseJson $UpdateArray ]; :set UpdateID ($Update->"update_id"); :local Message [ $ParseJson ($Update->"message") ]; + :local IsReply [ :len ($Message->"reply_to_message") ]; :local IsMyReply ($TelegramMessageIDs->([ $ParseJson ($Message->"reply_to_message") ]->"message_id")); :if (($IsMyReply = 1 || $TelegramChatOffset->0 > 0 || $Uptime > 5m) && $UpdateID >= $TelegramChatOffset->2) do={ :local Trusted false; @@ -93,7 +94,7 @@ $WaitFullyConnected; " from update " . $UpdateID . "!") false; :set Done true; } - :if ($Done = false && ($IsMyReply = 1 || $TelegramChatActive = true) && [ :len ($Message->"text") ] > 0) do={ + :if ($Done = false && ($IsMyReply = 1 || ($IsReply = 0 && $TelegramChatActive = true)) && [ :len ($Message->"text") ] > 0) do={ :if ([ $ValidateSyntax ($Message->"text") ] = true) do={ :local State ""; :local File ("tmpfs/telegram-chat/" . [ $GetRandom20CharAlNum 6 ]); -- cgit v1.2.3-70-g09d2