global-functions: $SendTelegram: allow to override chatid

This allows to send Telegram messages to different contact or group.
Use something like this:

/system scheduler add name=netwatch-notify interval=1m start-time=startup \
  on-event=":global TelegramChatIdOverride \"-1234\"; / system script run netwatch-notify; :set TelegramChatIdOverride;"
This commit is contained in:
Christian Hesse 2020-03-05 10:39:34 +01:00
parent 71ae8cb75f
commit 34db2e34db

View file

@ -428,16 +428,22 @@
:global Identity;
:global TelegramTokenId;
:global TelegramChatId;
:global TelegramChatIdOverride;
:global UrlEncode;
:global CertificateAvailable;
:if ([ :len $TelegramTokenId ] > 0 && [ :len $TelegramChatId ] > 0) do={
:local ChatId $TelegramChatId;
:if ([ :len $TelegramChatIdOverride ] > 0) do={
:set ChatId $TelegramChatIdOverride;
}
:if ([ :len $TelegramTokenId ] > 0 && [ :len $ChatId ] > 0) do={
$CertificateAvailable "Go Daddy Secure Certificate Authority - G2";
:do {
/ tool fetch check-certificate=yes-without-crl output=none http-method=post \
("https://api.telegram.org/bot" . $TelegramTokenId . "/sendMessage") \
http-data=("chat_id=" . $TelegramChatId . "&disable_notification=" . $Silent . \
http-data=("chat_id=" . $ChatId . "&disable_notification=" . $Silent . \
"&text=" . [ $UrlEncode ("[" . $Identity . "] " . $Subject . "\n\n" . $Message) ]);
} on-error={
:log warning "Failed sending telegram notification!";