Skip to content

Commit

Permalink
implement retry logic with twilio conferences api (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbraswell authored Aug 27, 2023
1 parent 3ffbcb3 commit c0f1ba3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions app/Http/Controllers/HelplineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,28 @@ public function dial(Request $request)
exit();
}

$conferences = $this->twilio->client()->conferences
->read(array ("friendlyName" => $request->get('FriendlyName')));
// Sometime in August 2023, Twilio introduced a change in API Behavior. The conferences API
// now seems to be eventually consistent. Sometimes we get the conference back on the first
// try, and other times it takes a few tries. Retrying every half second seems to get the
// job done after no more than about 4 retries in the worst case. We try up to 10 times just
// to be safe.
$conferences = array();
for ($i = 0; $i < 10; $i++) {
$conferences = $this->twilio->client()
->conferences
->read(array("friendlyName" => $request->get('FriendlyName')));

if ($i > 0) {
$this->settings->logDebug("conferences eventual consistency issue, retry $i");
}

if (count($conferences)) {
break;
}

sleep(0.5);
}

if (count($conferences) > 0 && $conferences[0]->status != "completed") {
$sms_body = $this->settings->word('you_have_an_incoming_phoneline_call_from') . " ";

Expand Down

0 comments on commit c0f1ba3

Please sign in to comment.