Skip to content

Commit 9dea002

Browse files
committed
Adding TwiML generation.
1 parent 0c13ffe commit 9dea002

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,38 @@ Edit `config/packages/travisjryan/twilio` with your appropriate Twilio settings
4040

4141
Sending a SMS Message
4242

43-
`Twilio::message('+18085551212', 'Pink Elephants and Happy Rainbows');`
43+
```php
44+
<?php
45+
46+
Twilio::message('+18085551212', 'Pink Elephants and Happy Rainbows');
47+
48+
?>
49+
```
4450

4551
Creating a Call
4652

47-
`Twilio::call('+18085551212', 'http://foo.com/call.xml');`
53+
```php
54+
<?php
55+
56+
Twilio::call('+18085551212', 'http://foo.com/call.xml');
57+
58+
?>
59+
```
60+
61+
Generating TwiML
62+
63+
```php
64+
<?php
65+
66+
$twiml = Twilio::twiml(function($message) {
67+
$message->say('Hello');
68+
$message->play('https://api.twilio.com/cowbell.mp3', array('loop' => 5));
69+
});
70+
71+
print $twiml;
4872

73+
?>
74+
```
4975

5076
### License
5177

src/Travisjryan/Twilio/Twilio.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,21 @@ public function call($to, $url, $options=array(), $from=null) {
3030
$options);
3131
}
3232

33+
public function twiml($callback)
34+
{
35+
$message = new \Services_Twilio_Twiml();
36+
37+
if( $callback instanceof \Closure ) {
38+
call_user_func($callback, $message);
39+
}
40+
41+
return $message->__toString();
42+
43+
}
44+
3345
private function getTwilio()
3446
{
3547
return new \Services_Twilio($this->config['sid'], $this->config['token']);
3648
}
49+
3750
}

0 commit comments

Comments
 (0)