From 2d0ce176299c12de6898e17964ccfc4505b65b7c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 27 Apr 2021 21:31:11 +0200 Subject: global-functions: $SendTelegram2: support overriding token id and chat id --- global-functions | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/global-functions b/global-functions index fa0a34f..3535f38 100644 --- a/global-functions +++ b/global-functions @@ -961,9 +961,11 @@ :global TelegramFixedWidthFont; :global TelegramQueue; :global TelegramTokenId; + :global TelegramTokenIdOverride; :global CertificateAvailable; :global CharacterReplace; + :global EitherOr; :global IfThenElse; :global LogPrintExit2; :global SymbolForNotification; @@ -996,12 +998,10 @@ :return $Return; } - :local ChatId $TelegramChatId; - :if ([ :len $TelegramChatIdOverride ] > 0) do={ - :set ChatId $TelegramChatIdOverride; - } + :local ChatId [ $EitherOr ($TelegramChatIdOverride->($Notification->"origin")) $TelegramChatId ]; + :local TokenId [ $EitherOr ($TelegramTokenIdOverride->($Notification->"origin")) $TelegramTokenId ]; - :if ([ :len $TelegramTokenId ] = 0 || [ :len $ChatId ] = 0) do={ + :if ([ :len $TokenId ] = 0 || [ :len $ChatId ] = 0) do={ :return false; } @@ -1031,7 +1031,7 @@ $LogPrintExit2 warning $0 ("Downloading required certificate failed.") true; } / tool fetch check-certificate=yes-without-crl output=none http-method=post \ - ("https://api.telegram.org/bot" . $TelegramTokenId . "/sendMessage") \ + ("https://api.telegram.org/bot" . $TokenId . "/sendMessage") \ http-data=("chat_id=" . $ChatId . "&disable_notification=" . ($Notification->"silent") . \ "&disable_web_page_preview=true&parse_mode=" . $ParseMode . "&text=" . $Text) as-value; } on-error={ @@ -1043,7 +1043,7 @@ :set Text ($Text . [ $UrlEncode ("\n" . [ $SymbolForNotification "alarm-clock" ] . \ [ $EscapeMD ("This message was queued since " . [ / system clock get date ] . \ " " . [ / system clock get time ] . " and may be obsolete.") "hint" ]) ]); - :set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TelegramTokenId; + :set ($TelegramQueue->[ :len $TelegramQueue ]) { chatid=$ChatId; tokenid=$TokenId; parsemode=$ParseMode; text=$Text; silent=($Notification->"silent") }; :if ([ :len [ / system scheduler find where name="FlushTelegramQueue" ] ] = 0) do={ / system scheduler add name=FlushTelegramQueue interval=1m start-time=startup \ -- cgit v1.2.3-54-g00ecf