laravel-twilio

Laravel Twillio API Integration

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

  • twilio:sms
  • twilio:call

Installation

Begin by installing this package through Composer. Run this command from the Terminal:

    composer require aloha/twilio

Laravel integration

To wire this up in your Laravel project, wether it's built in Laravel 4 or 5, you need to add the service provider. Open app.php, and add a new item to the providers array.

'Aloha\Twilio\Support\Laravel\ServiceProvider',

Then, add a Facade for more convenient usage. In your app.php config file add the following line to the aliases array:

'Twilio' => 'Aloha\Twilio\Support\Laravel\Facade',

In Laravel 4 you need to publish the default config file to app/config/packages/aloha/twilio/config.php with the artisan command config:publish aloha/twilio.

In Laravel 5 you need to publish the default config file to config/twilio.php with the artisan command vendor:publish.

Facade

The facade now has the exact same methods as the Aloha\Twilio\TwilioInterface. One extra feature is that you can define which settings (and which sender phone number) to use:

Twilio::from('callcenter')->message($user->phone, $message);
Twilio::from('board_room')->message($boss->phone, 'Hi there boss!');

Define multiple entries in your twilio config to make use of this feature.

Usage

Creating a Twilio object. This object implements the Aloha\Twilio\TwilioInterface.

$twilio = new Aloha\Twilio\Twilio($accountId, $token, $fromNumber);

Sending a text message:

$twilio->message('+18085551212', 'Pink Elephants and Happy Rainbows');

Creating a call:

$twilio->call('+18085551212', 'http://foo.com/call.xml');

Generating a call and building the message in one go:

$twilio->call('+18085551212', function ($message) {
    $message->say('Hello');
    $message->play('https://api.twilio.com/cowbell.mp3', ['loop' => 5]);
});

Generating TwiML:

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

print $twiml;

License

laravel-twilio is open-sourced software licensed under the MIT license

Languages
JavaScript 52.5%
PHP 17%
Handlebars 14.2%
Mermaid 9.1%
Shell 2.3%
Other 4.9%