From 761ac81cbb6e5926222edee8fff4039b90e7fe75 Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Thu, 28 Nov 2024 07:49:31 -0600 Subject: [PATCH] Fixes #7565 -- Splitting long GroupMe messages into chunks and adding a small delay to prevent sending out of order (#7588) --- backend/src/Webhook/Connector/GroupMe.php | 44 +++++++++++++---------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/backend/src/Webhook/Connector/GroupMe.php b/backend/src/Webhook/Connector/GroupMe.php index 46eee29b537..2f33f2dbba7 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 + } } }