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

Learn More

How to create a Phone Menu [PHP and twilio]

108 Runs 633 Views 68 Copies
Saved

Saved

dipesh.parmar 55

dipesh.parmar
published 4 years ago

<?php
// @start snippet
/* Define Menu */
require "twilio-php-master/Services/Twilio.php";

// @start snippet
/* Define Menu */
$web = array();
$web['default']  = array('receptionist','hours', 'location', 'duck');
$web['location'] = array('receptionist','east-bay', 'san-jose', 'marin');
// @end snippet

/* Get the menu node, index, and url */
$node = isset($_REQUEST['node']) ? $_REQUEST['node'] : 'default';
$index = isset($_REQUEST['Digits']) ? (int) $_REQUEST['Digits'] : 1;
$url = 'http://'.dirname($_SERVER["SERVER_NAME"].$_SERVER['PHP_SELF']).'/phonemenu.php';

/* Check to make sure index is valid */
if(isset($web[$node]) || count($web[$node]) >= $index && !is_null($_REQUEST['Digits']))
  $destination = $web[$node][$index];
else
	$destination = NULL;
// @end snippet

// @start snippet
/* Render TwiML */
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response>\n";
switch($destination)
{
	case 'hours':
?>
		<Say>Initech is open Monday through Friday, 9am to 5pm</Say>
		<Say>Saturday, 10am to 3pm and closed on Sundays</Say>
		<?php
			break;
	case 'location':
		?>
		<Say>Initech is located at 101 4th St in San Francisco California</Say>
		<Gather action="<?php echo 'http://' . dirname($_SERVER["SERVER_NAME"] .  $_SERVER['PHP_SELF']) . '/phonemenu.php?node=location'; ?>" numDigits="1">
			<Say>For directions from the East Bay, press 1</Say>
			<Say>For directions from San Jose, press 2</Say>
		</Gather>
		<?php
			break;
	case 'east-bay':
		?>
		<Say>Take BART towards San Francisco / Milbrae. Get off on Powell Street. Walk a block down 4th street</Say>
		<?php
			break;
	case 'san-jose':
		?>
		<Say>Take Cal Train to the Milbrae BART station. Take any Bart train to Powell Street</Say>
		<?php
			break;
	case 'duck';
		?>
		<Play>duck.mp3</Play>
		<?php
			break;
	case 'receptionist';
		?>
		<Say>Please wait while we connect you</Say>
		<Dial>NNNNNNNNNN</Dial>
		<?php
			break;
	default:
		?>
		<Gather action="<?php echo 'http://' . dirname($_SERVER["SERVER_NAME"] .  $_SERVER['PHP_SELF']) . '/phonemenu.php?node=default'; ?>" numDigits="1">
			<Say>Hello and welcome to the Initech Phone Menu</Say>
			<Say>For business hours, press 1</Say>
			<Say>For directions, press 2</Say>
			<Say>To hear a duck quack, press 3</Say>
			<Say>To speak to a receptionist, press 0</Say>
		</Gather>
		<?php
		break;
}
// @end snippet

// @start snippet
if($destination && $destination != 'receptionist')
{
?>
	<Pause/>
	<Say>Main Menu</Say>
	<Redirect><?php echo 'http://' . dirname($_SERVER["SERVER_NAME"] .  $_SERVER['PHP_SELF']) . '/phonemenu.php' ?></Redirect>
<?php
}
// @end snippet
?>
</Response>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).