aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-09-27 20:38:09 +0200
committerGravatar Christian Hesse <mail@eworm.de>2020-09-27 20:38:09 +0200
commit9ea6b159b697359ace83f45d1cbd12cb6b0d6dd5 (patch)
tree38dfa3a3f0116a57057e10ee372a531aefa43242 /global-functions
parent697e32a30640c7bb8c132aaed44968081e6e3872 (diff)
global-functions: $SendTelegram: truncate messages if too long
Telegram messages have a maximum length of 4096 characters. Truncate if too long, keep some spare characters for status messages.
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions9
1 files changed, 8 insertions, 1 deletions
diff --git a/global-functions b/global-functions
index 2d25b34..5aab671 100644
--- a/global-functions
+++ b/global-functions
@@ -744,6 +744,7 @@
:global CertificateAvailable;
:global LogPrintExit;
+ :global SymbolForNotification;
:global UrlEncode;
:local ChatId $TelegramChatId;
@@ -755,7 +756,13 @@
:return false;
}
- :local Text [ $UrlEncode ("[" . $Identity . "] " . $Subject . "\n\n" . $Message) ];
+ :local Text ("[" . $Identity . "] " . $Subject . "\n\n" . $Message);
+ :if ([ :len $Text ] > 3968) do={
+ :set Text ([ :pick $Text 0 3840 ] . "...\n\n" . [ $SymbolForNotification "warning-sign" ] . \
+ "The Telegram message was too long and has been truncated.");
+ }
+ :set Text [ $UrlEncode $Text ];
+
:do {
:if ([ $CertificateAvailable "Go Daddy Secure Certificate Authority - G2" ] = false) do={
$LogPrintExit warning ("Downloading required certificate failed.") true;