3
votes

I have a simple call application I am building using Twilio. Instead of using static twiml, Im building dynamic Twiml using the Services_Twilio_Twiml class provided by Twilio's PHP library.

I have it working very well for simple things, however, I cannot for the life of me figure out how to nest say/play verbs within the gather statement of the php library.

Here is what I have:

$this->gather(array ("action" => "http://pbx.somedomain.com/twilio/inbound/step/mainmenu_ivr")); (when keypad entry occurs it hits the action url)

What i need to duplicate is this twiml behavior somehow using the passed in array:

<gather action="http://pbx.somedomain.com/twilio/inbound/step/mainmenu_ivr">
    <say>Please enter your extension.</say>
</gather>

How would I structure the array I pass to the gather function to nest the say within the gather statement?

Thanks in advance.

1

1 Answers

2
votes

Try this:

require('/path/to/twilio-php/Services/Twilio.php');
$response = new Services_Twilio_Twiml();
$gather = $response->gather(array('action' => 'http://pbx.example.com'));
$gather->say('Please enter your extension');
print $response;

There are more examples listed on this page, Creating TwiML with PHP.