diff --git a/backend/src/Webhook/Connector/GroupMe.php b/backend/src/Webhook/Connector/GroupMe.php index 46eee29b53..2f33f2dbba 100644 --- a/backend/src/Webhook/Connector/GroupMe.php +++ b/backend/src/Webhook/Connector/GroupMe.php @@ -47,26 +47,32 @@ public function dispatch( $webhookUrl = $apiUrl . '/bots/post'; - $requestParams = [ - 'bot_id' => $botId, - 'text' => $messages['text'], - ]; + $text = $messages['text']; + $chunks = str_split($text, 1000); - $response = $this->httpClient->request( - 'POST', - $webhookUrl, - [ - 'headers' => [ - 'Content-Type' => 'application/json', - ], - 'json' => $requestParams, - ] - ); + foreach ($chunks as $chunk) { + $requestParams = [ + 'bot_id' => $botId, + 'text' => $chunk, + ]; - $this->logHttpResponse( - $webhook, - $response, - $requestParams - ); + $response = $this->httpClient->request( + 'POST', + $webhookUrl, + [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'json' => $requestParams, + ] + ); + + $this->logHttpResponse( + $webhook, + $response, + $requestParams + ); + usleep(100000); // Delay to prevent sending out of order + } } }