GithubHelp home page GithubHelp logo

larron / twilio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brayancruces/twilio

0.0 2.0 0.0 40 KB

Twilio notifications channel for Laravel 5.3

Home Page: http://laravel-notification-channels.com

License: MIT License

PHP 100.00%

twilio's Introduction

Twilio notifications channel for Laravel 5.3

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads

This package makes it easy to send Twilio notifications with Laravel 5.3.

Contents

Installation

You can install the package via composer:

composer require laravel-notification-channels/twilio

You must install the service provider:

// 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:

// config/services.php
...
'twilio' => [
    'account_sid' => env('TWILIO_ACCOUNT_SID'),
    'auth_token' => env('TWILIO_AUTH_TOKEN'),
    'from' => env('TWILIO_FROM'), // optional
],
...

Usage

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

use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioSmsMessage;
use Illuminate\Notifications\Notification;

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

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

You can also create a Twilio call:

use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioCallMessage;
use Illuminate\Notifications\Notification;

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

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

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.

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.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

twilio's People

Contributors

casperboone avatar freekmurze avatar gregoriohc avatar mikemclin avatar mpociot avatar oyed avatar themsaid avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.