I am currently working on a project with Twilio, and part of the project includes a set of 4 numbers and their consecutive call until one of them picks up at what point it stops calling. Everything seems to work, except for the part causing the stop.
Using the StatusCallback method, even after answering the call and confirming (by pressing 1 on the keyboard using the verb), he continues to continue calling other numbers. Is there a way to make this so that the StatusCallback only runs if the call does not answer?
<?php
$twilio = new Services_Twilio($AccountSID, $AccountToken);
$twilioPhone = "";
$numbers = Array(
trim($_GET["num1"]),
trim($_GET["num2"]),
trim($_GET["num3"]),
trim($_GET["num4"])
);
$message = trim($_GET["msg"]);
$called = $_GET["phone"];
$run = 0;
if ($called) {
$run = array_search($called, $numbers)+1;
}
if ($_GET['Digits']) {
?>
<Response>
<Say voice="alice">Okay, this number has been confirmed.</Say>
</Response>
<?
exit;
} else {
if (empty($_GET["automated"]) || $_GET["automated"] == null) {
$paramString = "automated=1&num1=".$numbers[0]."&num2=".$numbers[1]."&num3=".$numbers[2]."&num4=".$numbers[3]."&msg=".$message;
header("location: URL_HERE/index.php?".$paramString);
} else {
try {
$call = $twilio -> account -> calls -> create(
$twilioPhone,
$numbers[$run],
'http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3E'.rawurlencode(stripslashes($message)).'%3C%2FSay%3E%3CPause%20length=%221%22%2F%3E%3CGather%20numDigits=%221%22%20action=%22URL_HERE%2Findex.php%22%20method=%22GET%22%3E%3CSay%3EPlease%20press%201%20to%20confirm%20you%20have%20recieved%20this%20message.%3C%2FSay%3E%3C%2FGather%3E%3C%2FResponse%3E',
Array(
"timeout"=>"15",
"ifmachine"=>"hangup",
"StatusCallback"=>"URL_HERE/index.php?automated=1&phone=".$numbers[$run]."&num1=".$numbers[0]."&num2=".$numbers[1]."&num3=".$numbers[2]."&num4=".$numbers[3]."&msg=".$message
)
);
} catch (Exception $err) {
echo "Error: " . $err -> getMessage();
}
}
}
?>
source
share