Primary Verbs¶
Response¶
All TwiML starts with the <Response> verb. The following code creates an empty response.
$response = new Services_Twilio_Twiml;
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response></Response>
Say¶
$response = new Services_Twilio_Twiml;
$response->say("Hello World");
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello World</Say>
</Response>
Play¶
$response = new Services_Twilio_Twiml;
$response->play("https://api.twilio.com/cowbell.mp3", array('loop' => 5));
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play loop="5">https://api.twilio.com/cowbell.mp3</Play>
<Response>
Gather¶
$response = new Services_Twilio_Twiml;
$gather = $response->gather(array('numDigits' => 5));
$gather->say("Hello Caller");
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather numDigits="5">
<Say>Hello Caller</Say>
</Gather>
<Response>
Record¶
$response = new Services_Twilio_Twiml;
$response->record(array(
'action' => 'http://foo.com/path/to/redirect',
'maxLength' => 20
));
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Record action="http://foo.com/path/to/redirect" maxLength="20"/>
</Response>
Sms¶
$response = new Services_Twilio_Twiml;
$response->sms('Hello World', array(
'to' => '+14150001111',
'from' => '+14152223333'
));
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Sms to="+14150001111" from="+14152223333">Hello World</Sms>
</Response>
Dial¶
$response = new Services_Twilio_Twiml;
$response->dial('+14150001111', array(
'callerId' => '+14152223333'
));
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial callerId="+14152223333">+14150001111</Dial>
</Response>
Number¶
$response = new Services_Twilio_Twiml;
$dial = $response->dial(NULL, array(
'callerId' => '+14152223333'
));
$dial->number('+14151112222', array(
'sendDigits' => '2'
));
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial callerId="+14152223333">
<Number sendDigits="2">+14151112222</Number>
</Dial>
</Response>
Client¶
$response = new Services_Twilio_Twiml;
$dial = $response->dial(NULL, array(
'callerId' => '+14152223333'
));
$dial->client('client-id');
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial callerId="+14152223333">
<Client>client-id</Client>
</Dial>
</Response>
Conference¶
require("Services/Twilio.php");
$response = new Services_Twilio_Twiml;
$dial = $response->dial();
$dial->conference('Customer Waiting Room', array(
"startConferenceOnEnter" => "true",
"muted" => "true",
"beep" => "false",
));
print $response;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Conference startConferenceOnEnter="true" muted="true" beep="false">
Customer Waiting Room
</Conference>
</Dial>
</Response>