2017 © Pedro Peláez
 

library twilio

Twilio API for Laravel

image

aloha/twilio

Twilio API for Laravel

  • Thursday, May 3, 2018
  • by aloha
  • Repository
  • 24 Watchers
  • 284 Stars
  • 546,207 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 118 Forks
  • 10 Open issues
  • 21 Versions
  • 9 % Grown

The README.md

laravel-twilio

Laravel Twilio API Integration, (*1)

Build Status Total Downloads Latest Stable Version License, (*2)

Installation

Begin by installing this package through Composer. Run this command from the Terminal:, (*3)

composer require aloha/twilio

This will register two new artisan commands for you:, (*4)

  • twilio:sms
  • twilio:call

And make these objects resolvable from the IoC container:, (*5)

  • Aloha\Twilio\Manager (aliased as twilio)
  • Aloha\Twilio\TwilioInterface (resolves a Twilio object, the default connection object created by the Manager).

There's a Facade class available for you, if you like. In your app.php config file add the following line to the aliases array if you want to use a short class name:, (*6)

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

You can publish the default config file to config/twilio.php with the terminal command, (*7)

php artisan vendor:publish --provider="Aloha\Twilio\Support\Laravel\ServiceProvider"

Facade

The facade has the exact same methods as the Aloha\Twilio\TwilioInterface. First, include the Facade class at the top of your file:, (*8)

use Twilio;

To send a message using the default entry from your twilio config file:, (*9)

Twilio::message($user->phone, $message);

One extra feature is that you can define which settings (and which sender phone number) to use:, (*10)

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

Define multiple entries in your twilio config file to make use of this feature., (*11)

Usage

Creating a Twilio object. This object implements the Aloha\Twilio\TwilioInterface., (*12)

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

Sending a text message:, (*13)

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

Creating a call:, (*14)

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

Generating a call and building the message in one go:, (*15)

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

or to make a call with any Twiml description you can pass along any Twiml object:, (*16)

$message = new \Twilio\TwiML\VoiceResponse();
$message->say('Hello');
$message->play('https://api.twilio.com/cowbell.mp3', ['loop' => 5]);

$twilio->call('+18085551212', $message);

Access the configured Twilio\Rest\Client object:, (*17)

$sdk = $twilio->getTwilio();

You can also access this via the Facade as well:, (*18)

$sdk = Twilio::getTwilio();
Pass as many optional parameters as you want

If you want to pass on extra optional parameters to the messages->sendMessage(...) method from the Twilio SDK, you can do so by adding to the message method. All arguments are passed on, and the from field is prepended from configuration., (*19)

$twilio->message($to, $message, $mediaUrls, $params);
// passes all these params on.

The same is true for the call method., (*20)

$twilio->call($to, $message, $params);
// passes all these params on.

Dummy class

There is a dummy implementation of the TwilioInterface available: Aloha\Twilio\Dummy. This class allows you to inject this instead of a working implementation in case you need to run quick integration tests., (*21)

Logging decorator

There is one more class available for you: the Aloha\Twilio\LoggingDecorator. This class wraps any TwilioInterface object and logs whatever Twilio will do for you. It also takes a Psr\Log\LoggerInterface object (like Monolog) for logging, you know., (*22)

By default the service providers don't wrap objects with the LoggingDecorator, but it is at your disposal in case you want it. A possible use case is to construct a TwilioInterface object that logs what will happen, but doesn't actually call Twilio (using the Dummy class):, (*23)

if (getenv('APP_ENV') === 'production') {
    $twilio = $container->make(\Aloha\Twilio\Manager::class);
} else {
    $psrLogger = $container->make(\Psr\Log\LoggerInterface::class);
    $twilio = new LoggingDecorator($psrLogger, new \Aloha\Twilio\Dummy());
}

// Inject it wherever you want.
$notifier = new Notifier($twilio);

Credits

License

laravel-twilio is open-sourced software licensed under the MIT license, (*24)

The Versions

03/05 2018

dev-master

9999999-dev https://github.com/aloha/laravel-twilio

Twilio API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

laravel sms ivr twilio

03/05 2018

4.0.1

4.0.1.0 https://github.com/aloha/laravel-twilio

Twilio API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

laravel sms ivr twilio

23/04 2018

4.0.0

4.0.0.0 https://github.com/aloha/laravel-twilio

Twilio API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

laravel sms ivr twilio

05/10 2017
19/09 2017
18/07 2017
27/06 2017

3.0.1

3.0.1.0 https://github.com/aloha/laravel-twilio

Twilio API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

laravel sms ivr twilio

23/07 2016
16/06 2016

2.x-dev

2.9999999.9999999.9999999-dev https://github.com/aloha/laravel-twilio

Twilio API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

laravel sms ivr twilio

21/05 2016

2.1.1

2.1.1.0 https://github.com/aloha/laravel-twilio

Twilio API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

laravel sms ivr twilio

18/03 2016

2.1.0

2.1.0.0 https://github.com/aloha/laravel-twilio

Twilio API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

laravel sms ivr twilio

26/10 2015

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/aloha/laravel4-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

sms laravel4 ivr twilio

26/10 2015

1.1.0

1.1.0.0 https://github.com/aloha/laravel4-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

sms laravel4 ivr twilio

17/07 2015

2.0.0

2.0.0.0 https://github.com/aloha/laravel-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

sms laravel4 ivr twilio

17/07 2015

2.0.0-RC5

2.0.0.0-RC5 https://github.com/aloha/laravel-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

sms laravel4 ivr twilio

09/06 2015

2.0.0-RC4

2.0.0.0-RC4 https://github.com/aloha/laravel-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

sms laravel4 ivr twilio

03/06 2015

2.0.0-RC3

2.0.0.0-RC3 https://github.com/aloha/laravel-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

sms laravel4 ivr twilio

16/04 2015

2.0.0-RC2

2.0.0.0-RC2 https://github.com/aloha/laravel-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

sms laravel4 ivr twilio

08/04 2015

2.0.0-RC1

2.0.0.0-RC1 https://github.com/aloha/laravel-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Travis J Ryan

sms laravel4 ivr twilio

04/09 2014

1.0.2

1.0.2.0 https://github.com/aloha/laravel4-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

by Travis J Ryan

sms laravel4 ivr twilio

20/05 2014

1.0.1

1.0.1.0 https://github.com/travisjryan/laravel4-twilio

Twilio API for Laravel 4

  Sources   Download

MIT

The Requires

 

by Travis J Ryan

sms laravel4 ivr twilio