@@ -80,14 +80,11 @@ public function write(array $record): void
80
80
81
81
// trying to make request and send notification
82
82
try {
83
- file_get_contents (
84
- 'https://api.telegram.org/bot ' . $ this ->botToken . '/sendMessage? '
85
- . http_build_query ([
86
- 'text ' => $ this ->applyTelegramMaxCharactersLimit ($ this ->formatText ($ record )),
87
- 'chat_id ' => $ this ->chatId ,
88
- 'parse_mode ' => 'html '
89
- ])
90
- );
83
+ $ textChunks = str_split ($ this ->formatText ($ record ), 4096 );
84
+
85
+ foreach ($ textChunks as $ textChunk ) {
86
+ $ this ->sendMessage ($ textChunk );
87
+ }
91
88
} catch (Exception $ exception ) {
92
89
\Log::channel ('single ' )->error ($ exception ->getMessage ());
93
90
}
@@ -107,7 +104,6 @@ protected function getDefaultFormatter(): FormatterInterface
107
104
*/
108
105
private function formatText (array $ record ): string
109
106
{
110
-
111
107
return view ($ this ->template , array_merge ($ record ,[
112
108
'appName ' => $ this ->appName ,
113
109
'appEnv ' => $ this ->appEnv ,
@@ -116,11 +112,16 @@ private function formatText(array $record): string
116
112
}
117
113
118
114
/**
119
- * @param string $text
120
- * @return string
115
+ * @param string $text
121
116
*/
122
- private function applyTelegramMaxCharactersLimit (string $ text ): string
117
+ private function sendMessage (string $ text ): void
123
118
{
124
- return mb_substr ($ text , 0 , 4096 );
119
+ $ httpQuery = http_build_query ([
120
+ 'text ' => $ text ,
121
+ 'chat_id ' => $ this ->chatId ,
122
+ 'parse_mode ' => 'html ' ,
123
+ ]);
124
+
125
+ file_get_contents ('https://api.telegram.org/bot ' .$ this ->botToken .'/sendMessage? ' . $ httpQuery );
125
126
}
126
127
}
0 commit comments