Skip to content

Commit

Permalink
Merge pull request #5 from anasterism/TwiML
Browse files Browse the repository at this point in the history
TwiML Integration
  • Loading branch information
aloha committed May 20, 2014
2 parents adead4b + 34c0cdd commit fd14c70
Show file tree
Hide file tree
Showing 2 changed files with 43 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
15 changes: 15 additions & 0 deletions src/Travisjryan/Twilio/Twilio.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,23 @@ 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);
} else {
throw new \InvalidArgumentException("Callback is not valid.");
}

return $message->__toString();

}

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

}

0 comments on commit fd14c70

Please sign in to comment.