Smsapi Notifications Channel for Laravel
57,459
22
7
Package Data
Maintainer Username: laravel-notification-channels
Maintainer Contact: mat.drost@gmail.com (Mateusz Drost)
Package Create Date: 2017-04-24
Package Last Update: 2024-10-24
Home Page: http://laravel-notification-channels.com
Language: PHP
License: MIT
Last Refreshed: 2024-11-19 03:10:08
Package Statistics
Total Downloads: 57,459
Monthly Downloads: 1,033
Daily Downloads: 55
Total Stars: 22
Total Watchers: 7
Total Forks: 18
Total Open Issues: 2

Smsapi notifications channel for Laravel 5.3+

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

This package makes it easy to send notifications using Smsapi with Laravel 5.3+.

Contents

Installation

You can install the package via composer:

composer require laravel-notification-channels/smsapi

You must install the service provider:

// config/app.php
...
'providers' => [
    ...
    NotificationChannels\Smsapi\SmsapiServiceProvider::class,
],
...

You can also publish the config file with:

php artisan vendor:publish --provider="NotificationChannels\Smsapi\SmsapiServiceProvider"

Setting up the Smsapi service

Log in to your Smsapi dashboard and configure your preferred authentication method. Set your credentials and defaults in config/smsapi.php:

'auth' => [
    'method' => 'token',
    // 'method' => 'password',
    'credentials' => [
        'token' => env('SMSAPI_AUTH_TOKEN'),
        // 'username' => env('SMSAPI_AUTH_USERNAME'),
        // 'password' => env('SMSAPI_AUTH_PASSWORD'), // Hashed by MD5
    ],
],
'defaults' => [
    'common' => [
        // 'notify_url' => env('SMSAPI_NOTIFY_URL'),
        // 'partner' => env('SMSAPI_PARTNER'),
        // 'test' => env('SMSAPI_TEST', true),
    ],
    'sms' => [
        // 'from' => env('SMSAPI_FROM'),
        // 'fast' => false,
        // 'flash' => false,
        // 'encoding' => 'utf-8',
        // 'normalize' => false,
        // 'nounicode' => false,
        // 'single' => false,
    ],
    'mms' => [
    ],
    'vms' => [
        // 'from' => env('SMSAPI_FROM'),
        // 'tries' => 2,
        // 'interval' => 300,
        // 'tts_lector' => 'Agnieszka',
        // 'skip_gsm' => false,
    ],
],

Usage

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

use Illuminate\Notifications\Notification;
use NotificationChannels\Smsapi\SmsapiChannel;
use NotificationChannels\Smsapi\SmsapiSmsMessage;

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

    public function toSmsapi($notifiable)
    {
        return (new SmsapiSmsMessage())->content("Buy now your flight!");
    }
}
use Illuminate\Notifications\Notification;
use NotificationChannels\Smsapi\SmsapiChannel;
use NotificationChannels\Smsapi\SmsapiMmsMessage;

class AnimalTrespassed extends Notification
{
    public $photoId;

    public function via($notifiable)
    {
        return [SmsapiChannel::class];
    }

    public function toSmsapi($notifiable)
    {
        return (new SmsapiMmsMessage())->subject('Animal!')->smil($this->smil());
    }

    private function smil()
    {
        $url = route('photos', ['id' => $this->photoId]);
        $smil =
            "<smil>" .
                "<head>" .
                    "<layout>" .
                        "<root-layout height='100%' width='100%'/>" .
                        "<region id='Image' width='100%' height='100%' left='0' top='0'/>" .
                    "</layout>" .
                "</head>" .
                "<body><par><img src='{$url}' region='Image' /></par></body>" .
            "</smil>";
        return $smil;
    }
}

Add a routeNotificationForSmsapi method to your Notifiable model to return the phone number(s):

public function routeNotificationForSmsapi()
{
    return $this->phone_number;
}

Or add a routeNotificationForSmsapiGroup method to return the contacts group:

public function routeNotificationForSmsapiGroup()
{
    return $this->contacts_group;
}

Available Message methods

SmsapiSmsMessage

  • to(string|string[] $to)
  • group(string $group)
  • content(string $content)
  • template(string $template)
  • from(string $from)
  • fast(bool $fast = true)
  • flash(bool $flash = true)
  • encoding(string $encoding)
  • normalize(bool $normalize = true)
  • nounicode(bool $nounicode = true)
  • single(bool $single = true)
  • date(int|string $date)
  • notifyUrl(string $notifyUrl)
  • partner(string $partner)
  • test(bool $test = true)

SmsapiMmsMessage

  • to(string|string[] $to)
  • group(string $group)
  • subject(string $subject)
  • smil(string $smil)
  • date(int|string $date)
  • notifyUrl(string $notifyUrl)
  • partner(string $partner)
  • test(bool $test = true)

SmsapiVmsMessage

  • to(string|string[] $to)
  • group(string $group)
  • file(string $file)
  • tts(string $tts)
  • ttsLector(string $ttsLector)
  • from(string $from)
  • tries(int $tries)
  • interval(int $interval)
  • skipGsm(bool $skipGsm = true)
  • date(int|string $date)
  • notifyUrl(string $notifyUrl)
  • partner(string $partner)
  • test(bool $test = true)

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email mat.drost@gmail.com 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.