Bandwidth Example app for PHP Voice Appointment Reminders
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
vendor
CODE_OF_CONDUCT.md
CONTRIBUTING.md
ISSUE_TEMPLATE.md
LICENSE
PULLREQUEST.md
PULL_REQUEST_TEMPLATE.md
Procfile
README.md
composer.json
composer.lock
fpm_custom.conf

README.md

Bandwidth Appointment Reminders PHP Example

Bandwidth Voice & Messaging API Sample App for Appointment Reminders, see http://dev.bandwidth.com/

Prerequisites

  • You have a Bandwidth account
  • You have at least one Bandwidth Phone Number allocated to your account
  • You have a Heroku account

Getting Started & Installing on Heroku

$ git clone https://github.com/bandwidthcom/php-bandwidth-voice-appt-reminder
$ cd php-bandwidth-voice-appt-reminder
$ heroku create
$ git push heroku master
$ heroku config:set BANDWIDTH_USER_ID='u_your_user_id_found_in_account_tab'
$ heroku config:set BANDWIDTH_API_TOKEN='t_your_token_found_in_account_tab'
$ heroku config:set BANDWIDTH_API_SECRET='your_secret_found_in_account_tab'
$ heroku open

Understanding how it works

Start an outgoing phone call - set the callback to callback.php

app/index.php

$call = new Catapult\Call(array(
	"from" => new Catapult\PhoneNumber($_POST['fromPhoneNumber']),
	"to" => new Catapult\PhoneNumber($_POST['toPhoneNumber']),
	"callbackUrl" => "https://".$_SERVER['HTTP_HOST']."/callback.php",
	"callbackHttpMethod" => "GET"
));	

Phone Call is answered - detect the [eventType = "answer"] (http://ap.bandwidth.com/docs/callback-events/voice-calls/answer-event/)

Create a BXML response for Gather - set the callback for gather to callback.php

app/callback.php

<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

echo '<Response>';

if ($_REQUEST['eventType'] == 'answer') {

  echo '<Gather requestUrl= "https://'.$_SERVER['HTTP_HOST'].'/callback.php" maxDigits="1">
    		<SpeakSentence gender="female" locale="en" voice="kate">
    			Hello, please confirm your appointment on tuesday, press 1 to confirm and press 2 to reschedule.
    		</SpeakSentence>
  		</Gather>';

}

...

echo '</Response>';

?>

Determine which key is pressed and speak to the user based on which key is pressed, then hangup the call.

app/callback.php

<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

echo '<Response>';

...

elseif ($_REQUEST['eventType'] == 'bamlRequest') {

	# @start snippet
	$user_pushed = (int) $_REQUEST['digits'];
	# @end snippet

	if ($user_pushed == 1)
	{
	    echo '<SpeakSentence locale="en_US" gender="female" voice="kate">Thanks. You are confirmed. Goodbye.</SpeakSentence>';
	}
	elseif ($user_pushed == 2) {
	    echo '<SpeakSentence locale="en_US" gender="female" voice="kate">Thanks. We will reschedule. Goodbye.</SpeakSentence>';
	}
	else {
	    echo '<SpeakSentence locale="en_US" gender="female" voice="kate">I am sorry. I did not get your answer. Goodbye.</SpeakSentence>';
	}

	echo '<Hangup></Hangup>';

} //end of digit press


echo '</Response>';

?>