@@ -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 ->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,11 +104,24 @@ 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 ,
114
110
])
115
111
);
116
112
}
113
+
114
+ /**
115
+ * @param string $text
116
+ */
117
+ private function sendMessage (string $ text ): void
118
+ {
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 );
126
+ }
117
127
}
0 commit comments