Skip to content

Commit

Permalink
Fixes AzuraCast#7565 -- Splitting long GroupMe messages into chunks a…
Browse files Browse the repository at this point in the history
…nd adding a small delay to prevent sending out of order (AzuraCast#7588)
  • Loading branch information
mdrxy authored Nov 28, 2024
1 parent beec9f4 commit 761ac81
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions backend/src/Webhook/Connector/GroupMe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 761ac81

Please sign in to comment.