Twilio

TwiML Quickstart: Hello Monkey

Hello Monkey, v1.1

Ok, that was fun. Seriously, it was. But let's raise the stakes a bit. Let's lookup the caller, and try to greet known callers by name:

quickstart/twiml/1.1/hello-monkey.php
<?php

	// make an associative array of callers we know, indexed by phone number
	$people = array(
		"4158675309"=>"Curious George",
		"4158675310"=>"Boots",
		"4158675311"=>"Virgil",
		"4158675312"=>"Marcel"
	);
	
	// if the caller is known, then greet them by name
	// otherwise, consider them just another monkey
	if(!$name = $people[$_REQUEST['Caller']])
		$name = "Monkey";
		
	// now greet the caller
	header("content-type: text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
	<Say>Hello <?php echo $name ?>.</Say>
</Response>

If you add your phone number and name to the $people array you can listen to Twilio greet you by name.

Next: Hello Monkey 1.2