Speed up development with full-stack environments for every branch.

Learn More

How to use Call Screening [PHP and twilio]

49 Runs 917 Views 245 Copies
Saved

Saved

sundip 66

sundip
published 4 years ago

<?php 

//The outcome of the <Dial> attempt.
$DialCallStatus = isset($_REQUEST['DialCallStatus']) ? $_REQUEST['DialCallStatus'] : "";

header("content-type: text/xml"); 

// Check the status of the call and 
require('twilio-php-master/Services/Twilio.php');

$sid = getenv("SID"); // Your Account SID from www.twilio.com/user/account
$token = getenv("TOKEN"); // Your Auth Token from www.twilio.com/user/account

$client = new Services_Twilio($sid, $token);
try {
  // make call
  $call = $client->account->calls->create(
    getenv("TWILIO_NUMBER"), // Verified Outgoing Caller ID or Twilio number
    getenv("TO_NUMBER"), // The phone number you wish to dial
    getenv("BASE_URL") // The URL of twiml.php on your server
  );
}
catch (Exception $e)
{
  echo 'Error starting phone call: ' . $e->getMessage();
}

// that there is a valid number to call

if($DialCallStatus!="completed")
{
?>
	<Response>
	<Dial action="attempt_call.php?number_index=<?php echo getenv("TO_NUMBER"); ?>">
		<Number url="screen_for_machine.php">
		<?php echo getenv("TO_NUMBER"); ?>
		</Number>
	</Dial>
	</Response>
<?php
} else {
?>
	<Response>
		<Hangup/>
	</Response>
<?php
}
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).