Giter VIP home page Giter VIP logo

smsapi's Introduction

Smsapi notifications channel for Laravel

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.5+, 6.x, & 7.x

Contents

Installation

You can install the package via composer:

composer require laravel-notification-channels/smsapi

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. There is a polish version and an international version which have separated accounts. 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
    ],
    // Service of smsapi. Can be SmsapiClient::SERVICE_PL or SmsapiClient::SERVICE_COM.
    'service' => SmsapiClient::SERVICE_PL,
],
'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 [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.

smsapi's People

Contributors

atymic avatar freekmurze avatar gorczakw avatar mdrost avatar mpociot avatar mtawil avatar pxlrbt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

smsapi's Issues

Config from defaults isn't working

Preparing configuration values in SmsapiServiceProvider.php isn't compatible with implementation in SmsapiClient.php. Common and channel specific values are not set correctly like 'from', 'test', 'partner'.

Maintenance

Hi @mdrost

Are you still interested in maintaining this package?

If so, could we add support for laravel 5.5+ and 6.0?

Thanks!

Not Working with Laravel 9 & Php 8

Hi,
Please update package to work with Laravel 9 & PHP 8.
Possible solution:
composer.json (...)
"require": {
"php": ">=7.2",
"illuminate/notifications": "~6.0 || ~7.0 || ~8.0 || ~9.0",
"illuminate/support": "~6.0 || ~7.0 || ~8.0 || ~9.0",
"smsapi/php-client": "^1.8"
},

Messages are not sending when configuration test is set to true

Hi,

I recently updated this library to it's latest version (from 0.3.0 to 0.5.2) and I ran into this problem: when in configuration file 'test' is set to true messages are not send - no exception is throwing. It works perefectly fine with older version and in this one when test is set to false. Could you help me with this stuff? Thanks in advance.

Authorization failed

Hello,

I always get the error "Authorization failed" even when i try with api-token or with password.
I use the token from here: https://imgur.com/hnHZwyE

  • added the provider to config/app.php
  • published the config

config/smsapi.php

'auth' => [
	'method' => 'token',

	'credentials' => [
		'token' => env('SMSAPI_AUTH_TOKEN'),
	],
  • added this line to .env file
    SMSAPI_AUTH_TOKEN=b0ixlNxxxxxxxxxxxUJkHR1E

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.