Skip to content

Commit

Permalink
Merge pull request #175 from sebastian-king/master
Browse files Browse the repository at this point in the history
hotfixes from production to untr master
  • Loading branch information
sebastian-king authored Nov 16, 2024
2 parents afa63a5 + 0360c3b commit e4f4050
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion api/sendgrid-inbound/parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'" . $db->real_escape_string($name) . "',
'" . $db->real_escape_string($email) . "',
'" . $db->real_escape_string("orgsync/inbound-parse") . "',
'" . $db->real_escape_string(bin2hex(random_bytes(16))) . "'
'" . $db->real_escape_string($token) . "'
)");

AdminBot::send_message("{$name} ({$email}) db write attempt (" . $token . "): " . $db->insert_id . "/" . $db->affected_rows);
Expand Down
1 change: 1 addition & 0 deletions template/top.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function email($to, $subject, $message, $replyto = false, $headers = NULL, $atta
$email = new \SendGrid\Mail\Mail();
$email->setFrom("no-reply@untrobotics.com", "UNT Robotics");
$email->setSubject($subject);
$email->addBcc("sebastian-king@my.unt.edu");

if ($replyto) {
$email->setReplyTo($replyto);
Expand Down
48 changes: 25 additions & 23 deletions twilio/find-first/find-first-available.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

require('../phone-numbers-config.php');

function dial_attempt($phone_number) {
function dial_attempt($incoming_sid, $phone_number) {
$ch = curl_init();

$post = array(
Expand All @@ -40,14 +40,14 @@ function dial_attempt($phone_number) {

$data = json_decode($result);

error_log("DIAL ATTEMPT: " . var_export($result, true));
error_log("[$incoming_sid] DIAL ATTEMPT. TO:" . $data->to);

return $data->sid;
}

function call_completed($sid) {

$status = call_status($sid);
$status = call_info($sid)->status;

$final_status = array('busy', 'no-answer', 'canceled', 'failed', 'completed');

Expand All @@ -58,27 +58,27 @@ function call_completed($sid) {
return false;
}

function call_status($sid) {
function call_info($sid) {

$ch = curl_init();
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/' . TWILIO_ACCOUNT_SID . '/Calls/' . $sid . '.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/' . TWILIO_ACCOUNT_SID . '/Calls/' . $sid . '.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

curl_setopt($ch, CURLOPT_USERPWD, TWILIO_ACCOUNT_SID . ':' . TWILIO_AUTH_TOKEN);
curl_setopt($ch, CURLOPT_USERPWD, TWILIO_ACCOUNT_SID . ':' . TWILIO_AUTH_TOKEN);

$result = curl_exec($ch);
if (curl_errno($ch)) {
error_log('ERROR (curl) when getting message SID info: ' . curl_error($ch));
}
curl_close($ch);
$result = curl_exec($ch);
if (curl_errno($ch)) {
error_log('ERROR (curl) when getting message SID info: ' . curl_error($ch));
}
curl_close($ch);

$data = json_decode($result);
error_log("OUTGOING CALL STATUS: " . $data);
return $data->status;
$data = json_decode($result);

//error_log("OUTGOING CALL STATUS: " . var_export($data, true));

return $data;
}

function queue_size($queue_sid = TWILIO_FIND_FIRST_QUEUE_SID) {
Expand Down Expand Up @@ -114,13 +114,15 @@ function queue_size($queue_sid = TWILIO_FIND_FIRST_QUEUE_SID) {
$max_attempts = 5;
$i = 1;

error_log("[$incoming_sid] INCOMING CALL. FROM:" . call_info($incoming_sid)->from);

while ($i <= $max_attempts) {
foreach (constant('PHONE_NUMBERS') as $phone_number) {
if (queue_size() > 0) {
$outgoing_sid = dial_attempt($phone_number);
$outgoing_sid = dial_attempt($incoming_sid, $phone_number);
do {
error_log("INCOMING CALL STATUS: " . call_status($incoming_sid));
sleep(1);
//error_log("INCOMING CALL STATUS: " . call_status($incoming_sid));
sleep(2);
} while (!call_completed($outgoing_sid) && queue_size() > 0);
} else {
break 2;
Expand All @@ -129,4 +131,4 @@ function queue_size($queue_sid = TWILIO_FIND_FIRST_QUEUE_SID) {
$i++;
}

error_log("INCOMING CALL STATUS LAST: " . call_status($incoming_sid));
error_log("[$incoming_sid] INCOMING CALL STATUS LAST: " . call_info($incoming_sid)->status);
20 changes: 8 additions & 12 deletions twilio/process-incoming-call.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,26 @@
<Gather input="dtmf" timeout="10" numDigits="1" action="/twilio/process-incoming-call.php?code=<?php echo API_SECRET; ?>">
<Pause length="2"/>
<Say voice="woman" language="en-GB">
Press 2 for Sebastian King, Co-President.
3 for Lauren Caves, Co-President.
4 for Tyler Martinez, Vice-President.
5 for Ashank Annam, Corporate Relation.
6 for Lauren Caves, Secretary.
Press 2 for Nicholas Tindle, Co-President.
3 for Laurence Boyd, Vice-President.
4 for Carter Moore, Secretary.
5 for Sophia Casas, Corporate Relation.
</Say>
</Gather>
<?php
break;
case 2:
?><Dial><?php echo PHONE_NUMBERS['SebK']; ?></Dial><?php
?><Dial><?php echo PHONE_NUMBERS['NickT']; ?></Dial><?php
break;
case 3:
?><Dial><?php echo PHONE_NUMBERS['LaurenC']; ?></Dial><?php
?><Dial><?php echo PHONE_NUMBERS['LaurenceB']; ?></Dial><?php
break;
case 4:
?><Dial><?php echo PHONE_NUMBERS['TylerM']; ?></Dial><?php
?><Dial><?php echo PHONE_NUMBERS['CarterM']; ?></Dial><?php
break;
case 5:
?><Dial><?php echo PHONE_NUMBERS['AshankA']; ?></Dial><?php
?><Dial><?php echo PHONE_NUMBERS['SophiaC']; ?></Dial><?php
break;
case 6:
?><Dial><?php echo PHONE_NUMBERS['LaurenC']; ?></Dial><?php
break;
case 9: // Voicemail
?>
<Say voice="woman" language="en-GB">
Expand Down

0 comments on commit e4f4050

Please sign in to comment.