aboutsummaryrefslogtreecommitdiffstats
path: root/mod
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2023-10-10 13:07:21 +0200
committerGravatar Christian Hesse <mail@eworm.de>2023-10-16 11:51:04 +0200
commit8ecde47a7836de8ec0e42ab2d95e80aff43151a8 (patch)
tree237688f7ff3917fa1d629fa7ab4ab7d5eac07f4c /mod
parent7df4f9e78c9213dfb1bb9e423e1d55d2bc01dd6d (diff)
mod/notification-telegram: remember ids of sent messages
Diffstat (limited to 'mod')
-rw-r--r--mod/notification-telegram.rsc26
1 files changed, 17 insertions, 9 deletions
diff --git a/mod/notification-telegram.rsc b/mod/notification-telegram.rsc
index ea47b1a..641c6f0 100644
--- a/mod/notification-telegram.rsc
+++ b/mod/notification-telegram.rsc
@@ -15,9 +15,11 @@
# flush telegram queue
:set FlushTelegramQueue do={
:global TelegramQueue;
+ :global TelegramMessageIDs;
:global IsFullyConnected;
:global LogPrintExit2;
+ :global ParseJson;
:if ([ $IsFullyConnected ] = false) do={
$LogPrintExit2 debug $0 ("System is not fully connected, not flushing.") false;
@@ -34,14 +36,13 @@
:foreach Id,Message in=$TelegramQueue do={
:if ([ :typeof $Message ] = "array" ) do={
:do {
- /tool/fetch check-certificate=yes-without-crl output=none http-method=post \
+ :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user http-method=post \
("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;
+ 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");
:set ($TelegramQueue->$Id);
+ :set ($TelegramMessageIDs->([ $ParseJson ([ $ParseJson $Data ]->"result") ]->"message_id")) 1;
} on-error={
$LogPrintExit2 debug $0 ("Sending queued Telegram message failed.") false;
:set AllDone false;
@@ -64,6 +65,7 @@
:global TelegramChatId;
:global TelegramChatIdOverride;
:global TelegramFixedWidthFont;
+ :global TelegramMessageIDs;
:global TelegramQueue;
:global TelegramTokenId;
:global TelegramTokenIdOverride;
@@ -73,6 +75,7 @@
:global EitherOr;
:global IfThenElse;
:global LogPrintExit2;
+ :global ParseJson;
:global SymbolForNotification;
:global UrlEncode;
@@ -111,6 +114,10 @@
:return false;
}
+ :if ([ :typeof $TelegramMessageIDs ] = "nothing") do={
+ :set TelegramMessageIDs ({});
+ }
+
:local Truncated false;
:local Text ("*__" . [ $EscapeMD ("[" . $IdentityExtra . $Identity . "] " . \
($Notification->"subject")) "plain" ] . "__*\n\n");
@@ -139,11 +146,12 @@
:if ([ $CertificateAvailable "Go Daddy Secure Certificate Authority - G2" ] = false) do={
$LogPrintExit2 warning $0 ("Downloading required certificate failed.") true;
}
- /tool/fetch check-certificate=yes-without-crl output=none http-method=post \
+ :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user http-method=post \
("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;
+ "&reply_to_message_id=" . ($Notification->"replyto") . "&disable_web_page_preview=true" . \
+ "&parse_mode=" . $ParseMode . "&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;