diff options
author | Christian Hesse <mail@eworm.de> | 2021-04-27 21:31:11 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-04-28 13:58:37 +0200 |
commit | 2d0ce176299c12de6898e17964ccfc4505b65b7c (patch) | |
tree | 6bd916be08cc1b4c079d03172d838077b99aefe6 | |
parent | bd05ca1133635a595a976d150fd10e36d46705aa (diff) |
global-functions: $SendTelegram2: support overriding token id and chat id
-rw-r--r-- | global-functions | 14 |
1 files 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 \ |