2017 © Pedro Peláez
 

library twilio

A boilerplate for contributions.Forked from laravel-notification-channels/twilio

image

chuoke/twilio

A boilerplate for contributions.Forked from laravel-notification-channels/twilio

  • Saturday, May 12, 2018
  • by chuoke
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 24 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Twilio notifications channel for Laravel 5.3+

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads, (*1)

This package makes it easy to send Twilio notifications with Laravel 5.3., (*2)

Contents

Installation

You can install the package via composer:, (*3)

``` bash composer require laravel-notification-channels/twilio, (*4)


Add the service provider (only required on Laravel 5.4 or lower): ```php // config/app.php 'providers' => [ ... NotificationChannels\Twilio\TwilioProvider::class, ],

Setting up your Twilio account

Add your Twilio Account SID, Auth Token, and From Number (optional) to your config/services.php:, (*5)

// config/services.php
...
'twilio' => [
    'username' => env('TWILIO_USERNAME'), // optional when using auth token
    'password' => env('TWILIO_PASSWORD'), // optional when using auth token
    'auth_token' => env('TWILIO_AUTH_TOKEN'), // optional when using username and password
    'account_sid' => env('TWILIO_ACCOUNT_SID'),
    'sms_service_sid' => env('TWILIO_SMS_SERVICE_SID'), // optional
    'from' => env('TWILIO_FROM'), // optional
],
...

Usage

Now you can use the channel in your via() method inside the notification:, (*6)

``` php use NotificationChannels\Twilio\TwilioChannel; use NotificationChannels\Twilio\TwilioSmsMessage; use Illuminate\Notifications\Notification;, (*7)

class AccountApproved extends Notification { public function via($notifiable) { return [TwilioChannel::class]; }, (*8)

public function toTwilio($notifiable)
{
    return (new TwilioSmsMessage())
        ->content("Your {$notifiable->service} account was approved!");
}

}, (*9)


You can also send an MMS: ``` php use NotificationChannels\Twilio\TwilioChannel; use NotificationChannels\Twilio\TwilioMmsMessage; use Illuminate\Notifications\Notification; class AccountApproved extends Notification { public function via($notifiable) { return [TwilioChannel::class]; } public function toTwilio($notifiable) { return (new TwilioMmsMessage()) ->content("Your {$notifiable->service} account was approved!") ->mediaUrl("https://picsum.photos/300"); } }

Or create a Twilio call:, (*10)

``` php use NotificationChannels\Twilio\TwilioChannel; use NotificationChannels\Twilio\TwilioCallMessage; use Illuminate\Notifications\Notification;, (*11)

class AccountApproved extends Notification { public function via($notifiable) { return [TwilioChannel::class]; }, (*12)

public function toTwilio($notifiable)
{
    return (new TwilioCallMessage())
        ->url("http://example.com/your-twiml-url");
}

}, (*13)


And you can also create a Twilio notify: ``` php use NotificationChannels\Twilio\TwilioChannel; use NotificationChannels\Twilio\TwilioNotifyMessage; use Illuminate\Notifications\Notification; class AccountApproved extends Notification { public function via($notifiable) { return [TwilioChannel::class]; } public function toTwilio($notifiable) { return (new TwilioNotifyMessage()) // you can change the service sid,and default will use the config's // ->setServiceSid('Service Sid') ->content('Yes! Your account was approved!'); } }

In this case,don't need the from., (*14)

In order to let your Notification know which phone are you sending/calling to, the channel will look for the phone_number attribute of the Notifiable model. If you want to override this behaviour, add the routeNotificationForTwilio method to your Notifiable model., (*15)

public function routeNotificationForTwilio()
{
    return '+1234567890';
}

Available Message methods

TwilioSmsMessage

  • from(''): Accepts a phone to use as the notification sender.
  • content(''): Accepts a string value for the notification body.

TwilioCallMessage

  • from(''): Accepts a phone to use as the notification sender.
  • url(''): Accepts an url for the call TwiML.

Changelog

Please see CHANGELOG for more information what has changed recently., (*16)

Testing

bash $ composer test, (*17)

Security

If you discover any security related issues, please email gregoriohc@gmail.com instead of using the issue tracker., (*18)

Contributing

Please see CONTRIBUTING for details., (*19)

Credits

License

The MIT License (MIT). Please see License File for more information., (*20)

The Versions