From 9ea6b159b697359ace83f45d1cbd12cb6b0d6dd5 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 27 Sep 2020 20:38:09 +0200 Subject: 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. --- global-functions | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3-70-g09d2