Skip to content

Commit

Permalink
Adding TwiML generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
anasterism committed May 10, 2014
1 parent 0c13ffe commit 9dea002
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,38 @@ Edit `config/packages/travisjryan/twilio` with your appropriate Twilio settings

Sending a SMS Message

`Twilio::message('+18085551212', 'Pink Elephants and Happy Rainbows');`
```php
<?php

Twilio::message('+18085551212', 'Pink Elephants and Happy Rainbows');

?>
```

Creating a Call

`Twilio::call('+18085551212', 'http://foo.com/call.xml');`
```php
<?php

Twilio::call('+18085551212', 'http://foo.com/call.xml');

?>
```

Generating TwiML

```php
<?php

$twiml = Twilio::twiml(function($message) {
$message->say('Hello');
$message->play('https://api.twilio.com/cowbell.mp3', array('loop' => 5));
});

print $twiml;

?>
```

### License

Expand Down
13 changes: 13 additions & 0 deletions src/Travisjryan/Twilio/Twilio.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,21 @@ public function call($to, $url, $options=array(), $from=null) {
$options);
}

public function twiml($callback)
{
$message = new \Services_Twilio_Twiml();

if( $callback instanceof \Closure ) {
call_user_func($callback, $message);
}

return $message->__toString();

}

private function getTwilio()
{
return new \Services_Twilio($this->config['sid'], $this->config['token']);
}

}

0 comments on commit 9dea002

Please sign in to comment.