From 86062788d705baf1dbd73a11cf527b9c809c8c96 Mon Sep 17 00:00:00 2001 From: Edgar Bolender Date: Sun, 16 Apr 2023 16:48:46 +0200 Subject: [PATCH] Notification for very long texts (use subject of email template) --- core/telegram_api.php | 2 +- language/de/email/forum_notify.txt | 3 +-- language/de/email/newtopic_notify.txt | 3 +-- language/en/email/forum_notify.txt | 4 +--- language/en/email/newtopic_notify.txt | 4 +--- notification/method/telegram.php | 7 ++++++- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/core/telegram_api.php b/core/telegram_api.php index 83e4c8f..a7db9e6 100644 --- a/core/telegram_api.php +++ b/core/telegram_api.php @@ -207,7 +207,7 @@ private function prepareText($text) $text = substr($text,$pos + strlen($splitmarker)); } // Warning: Topic is too long and was cut. Telegram doesn \'t allow more than 4096 characters !', - $pretext = $this->language->lang('EBT_TOPIC_SHORTENED') . PHP_EOL . '...' . PHP_EOL; + $pretext = PHP_EOL . $this->language->lang('EBT_TOPIC_SHORTENED') . PHP_EOL . '...' . PHP_EOL; $remaining_len = $maxlen - $this->formatters->pure_text_len($pretext) - $this->formatters->pure_text_len($title); $text = $this->formatters->pure_text_substr($text, $remaining_len); $text = $title . $pretext . $text; diff --git a/language/de/email/forum_notify.txt b/language/de/email/forum_notify.txt index 4976ee2..075d098 100644 --- a/language/de/email/forum_notify.txt +++ b/language/de/email/forum_notify.txt @@ -1,4 +1,3 @@ -Subject: (wird in Telegram ignoriert) -{AUTHOR_NAME} hat im Forum {FORUM_NAME} zum Beitrag {TOPIC_TITLE} eine neue Antwort erfasst: +Subject:{AUTHOR_NAME} hat im Forum {FORUM_NAME} zum Beitrag {TOPIC_TITLE} eine neue Antwort erfasst: {TELEGRAM_MESSAGE} \ No newline at end of file diff --git a/language/de/email/newtopic_notify.txt b/language/de/email/newtopic_notify.txt index a4a2070..5d04e21 100644 --- a/language/de/email/newtopic_notify.txt +++ b/language/de/email/newtopic_notify.txt @@ -1,4 +1,3 @@ -Subject: (wird in Telegram ignoriert) -{AUTHOR_NAME} hat im Forum {FORUM_NAME} den neuen Beitrag {TOPIC_TITLE} erfasst: +Subject:{AUTHOR_NAME} hat im Forum {FORUM_NAME} den neuen Beitrag {TOPIC_TITLE} erfasst: {TELEGRAM_MESSAGE} \ No newline at end of file diff --git a/language/en/email/forum_notify.txt b/language/en/email/forum_notify.txt index 93a5e0f..4c45430 100644 --- a/language/en/email/forum_notify.txt +++ b/language/en/email/forum_notify.txt @@ -1,5 +1,3 @@ -Subject: (ignored in Telegram) - -There is a new post by {AUTHOR_NAME} for the topic {TOPIC_TITLE} in the forum {FORUM_NAME}: +Subject:There is a new post by {AUTHOR_NAME} for the topic {TOPIC_TITLE} in the forum {FORUM_NAME}: {TELEGRAM_MESSAGE} \ No newline at end of file diff --git a/language/en/email/newtopic_notify.txt b/language/en/email/newtopic_notify.txt index 51c72da..c444336 100644 --- a/language/en/email/newtopic_notify.txt +++ b/language/en/email/newtopic_notify.txt @@ -1,5 +1,3 @@ -Subject: (ignored in Telegram) - -{AUTHOR_NAME} has written the new topic {TOPIC_TITLE} in the forum {FORUM_NAME}: +Subject:{AUTHOR_NAME} has written the new topic {TOPIC_TITLE} in the forum {FORUM_NAME}: {TELEGRAM_MESSAGE} \ No newline at end of file diff --git a/notification/method/telegram.php b/notification/method/telegram.php index 6b2c7da..44bb903 100644 --- a/notification/method/telegram.php +++ b/notification/method/telegram.php @@ -214,8 +214,13 @@ function($val) /* Send with break=true only prepares the text, but does not send the message */ $messenger->send(NOTIFY_EMAIL, true); - $this->msg = $messenger->msg; + $splitmarker = "\u{200B}\u{200B}"; + //The splitmarker makes sure, that the subject is shown, even if the message + //is shortended due to the length limit of telegram. + //(See telegram_api->prepareText) + $this->msg = $messenger->subject . PHP_EOL . $splitmarker . PHP_EOL . $messenger->msg; + $this->language->set_user_language($user['user_lang'], true); // Lets send to Telegram $this->send($telegram_id, $this->msg, $topic_id, $permissions);