Get Started

TwiML Quickstart: Hello Monkey

Play an mp3 for the Caller

That's nice, now let's play the sound of a nice monkey howl for the caller after we greet them by name.

  • quickstart/twiml/1.2/hello-monkey.php
    <?php
    
    	// make an associative array of callers we know, indexed by phone number
    	$people = array(
    		"+14158675309"=>"Curious George",
    		"+14158675310"=>"Boots",
    		"+14158675311"=>"Virgil",
    		"+14158675312"=>"Marcel"
    	);
    	
    	// if the caller is known, then greet them by name
    	// otherwise, consider them just another monkey
    	if(!$name = $people[$_REQUEST['From']])
    		$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>
    	<Play>http://demo.twilio.com/hellomonkey/monkey.mp3</Play>
    </Response>
        

This example uses the <Play> verb to fetch and play an MP3 file to the caller.

A recorded monkey howl is great, but our callers want more. Let's give them the option to talk to a real primate.


Next: Connect Call to Second Person »