Skip to content

Commit a6559af

Browse files
committed
Limit text message for telegram
1 parent 01c7cc6 commit a6559af

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/TelegramHandler.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function write(array $record): void
8383
file_get_contents(
8484
'https://api.telegram.org/bot' . $this->botToken . '/sendMessage?'
8585
. http_build_query([
86-
'text' => $this->formatText($record),
86+
'text' => $this->applyTelegramMaxCharactersLimit($this->formatText($record)),
8787
'chat_id' => $this->chatId,
8888
'parse_mode' => 'html'
8989
])
@@ -114,4 +114,13 @@ private function formatText(array $record): string
114114
])
115115
);
116116
}
117+
118+
/**
119+
* @param string $text
120+
* @return string
121+
*/
122+
private function applyTelegramMaxCharactersLimit(string $text): string
123+
{
124+
return mb_substr($text, 0, 4096);
125+
}
117126
}

0 commit comments

Comments
 (0)