All Projects → tzsk → Sms

tzsk / Sms

Licence: mit
Laravel SMS Gateway Integration Package

Projects that are alternatives of or similar to Sms

Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (+184.82%)
Mutual labels:  laravel, driver, composer
Plus
💝The Plus (ThinkSNS+) is a powerful, easy-to-develop social system built with Laravel.
Stars: ✭ 2,148 (+1817.86%)
Mutual labels:  sns, laravel, composer
Laravel Restify
The fastest way to make a powerful JSON:API compatible Rest API with Laravel.
Stars: ✭ 62 (-44.64%)
Mutual labels:  laravel, composer
Easy Short Url
ESU 短网址,可在 Laravel、Yii、ThinkPHP 等框架 Composer 包引入,也可以独立搭建短网址站点
Stars: ✭ 71 (-36.61%)
Mutual labels:  laravel, composer
Project
⭐️ Antares Project Application Skeleton. This is the very first place you should start. It allows you to create a brand new awesome project in easy few steps.
Stars: ✭ 84 (-25%)
Mutual labels:  laravel, composer
Laravel Dropbox Driver
A storage extension for Dropbox.
Stars: ✭ 42 (-62.5%)
Mutual labels:  laravel, driver
Datagrid
Datagrid for Laravel v5
Stars: ✭ 44 (-60.71%)
Mutual labels:  laravel, composer
Laravel Sitemap
Laravelium Sitemap generator for Laravel.
Stars: ✭ 1,231 (+999.11%)
Mutual labels:  laravel, composer
Easyhttp
A Laravel HTTP-client to make HTTP request easier and log requests and responses
Stars: ✭ 20 (-82.14%)
Mutual labels:  laravel, composer
Laravel Bandwagon
Social proof package for Laravel
Stars: ✭ 93 (-16.96%)
Mutual labels:  laravel, composer
Elastic Scout Driver Plus
Extension for Elastic Scout Driver
Stars: ✭ 90 (-19.64%)
Mutual labels:  laravel, driver
Laravel Alert
A Bootstrap alert helper for Laravel
Stars: ✭ 110 (-1.79%)
Mutual labels:  laravel, composer
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-65.18%)
Mutual labels:  laravel, composer
Htmlcache
Laravel middleware to cache the rendered html
Stars: ✭ 35 (-68.75%)
Mutual labels:  laravel, composer
Larrock Core
Core components for LarrockCMS
Stars: ✭ 46 (-58.93%)
Mutual labels:  laravel, composer
Nem Php
NEM Blockchain NIS API Wrapper and Software Development Kit for PHP
Stars: ✭ 32 (-71.43%)
Mutual labels:  laravel, composer
Elastic Scout Driver
Elasticsearch driver for Laravel Scout
Stars: ✭ 74 (-33.93%)
Mutual labels:  laravel, driver
Thumbnail
Thumbnail for a given video using FFMpeg
Stars: ✭ 96 (-14.29%)
Mutual labels:  laravel, composer
Package Skeleton
📦 My base for PHP packages.
Stars: ✭ 6 (-94.64%)
Mutual labels:  laravel, composer
Aliyun Sts
基于阿里云openapi系列接口中STS最新版本的SDK进行封装的composer package,解耦其他产品SDK,各个产品SDK功能使用组件化加载,减少代码臃肿。
Stars: ✭ 19 (-83.04%)
Mutual labels:  laravel, composer

🎁 Laravel SMS Gateway

SMS Cover

GitHub License Latest Version on Packagist GitHub Tests Action Status Total Downloads

This is a Laravel Package for SMS Gateway Integration. Now Sending SMS is easy.

List of supported gateways:

📦 Install

Via Composer

$ composer require tzsk/sms

⚡️ Configure

Publish the config file

$ php artisan sms:publish

In the config file you can set the default driver to use for all your SMS. But you can also change the driver at runtime.

Choose what gateway you would like to use for your application. Then make that as default driver so that you don't have to specify that everywhere. But, you can also use multiple gateways in a project.

// Eg. if you wan to use SNS.
'default' => 'sns',

Then fill the credentials for that gateway in the drivers array.

// Eg. for SNS.
'drivers' => [
    'sns' => [
        // Fill all the credentials here.
        'key' => 'Your AWS SNS Access Key',
        'secret' => 'Your AWS SNS Secret Key',
        'region' => 'Your AWS SNS Region',
        'sender' => 'Your AWS SNS Sender ID',
        'type' => 'Tansactional', // Or: 'Promotional'
    ],
    ...
]

Textlocal Configuration:

Textlocal is added by default. You just have to change the creadentials in the textlocal driver section.

AWS SNS Configuration:

In case you want to use AWS SNS. Then you have to pull a composer library first.

composer require aws/aws-sdk-php

Clockwork Configuration:

In case you want to use Clockwork. Then you have to pull a composer library first.

composer require mediaburst/clockworksms

Twilio Configuration:

In case you want to use Twilio. Then you have to pull a composer library first.

composer require twilio/sdk

Then you just have to change the creadentials in the twilio driver section.

Melipayamak Configuration:

In case you want to use Melipayamak. Then you have to pull a composer library first.

composer require melipayamak/php

Kavenegar Configuration:

In case you want to use Kavenegar. Then you have to pull a composer library first.

composer require kavenegar/php

SMS Gateway Me Configuration:

In case you want to use SMS Gateway Me. Then you have to pull a composer library first.

composer require smsgatewayme/client

🔥 Usage

In your code just use it like this.

# On the top of the file.
use Tzsk\Sms\Facades\Sms;

...

# In your Controller.
Sms::send("this message", function($sms) {
    $sms->to(['Number 1', 'Number 2']); # The numbers to send to.
});
# OR...
Sms::send("this message")->to(['Number 1', 'Number 2'])->dispatch();

# If you want to use a different driver.
Sms::via('gateway')->send("this message", function($sms) {
    $sms->to(['Number 1', 'Number 2']);
});
# OR...
Sms::via('gateway')->send("this message")->to(['Number 1', 'Number 2'])->dispatch();

# Here gateway is explicit : 'twilio' or 'textlocal' or any other driver in the config.
# The numbers can be a single string as well.

# If you are not a Laravel's facade fan, you can use sms helper:

sms()->send("this message", function($sms) {
    $sms->to(['Number 1', 'Number 2']); # The numbers to send to.
});

sms()->send("this message")->to(['Number 1', 'Number 2'])->dispatch();

sms()->via('gateway')->send("this message", function($sms) {
    $sms->to(['Number 1', 'Number 2']);
});

sms()->via('gateway')->send("this message")->to(['Number 1', 'Number 2'])->dispatch();

😍 Channel Usage

First you have to create your notification using php artisan make:notification command. then SmsChannel::class can be used as channel like the below:

namespace App\Notifications;

use Tzsk\Sms\Builder;
use Illuminate\Bus\Queueable;
use Tzsk\Sms\Channels\SmsChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;

class InvoicePaid extends Notification
{
    use Queueable;

    /**
     * Get the notification channels.
     *
     * @param  mixed  $notifiable
     * @return array|string
     */
    public function via($notifiable)
    {
        return [SmsChannel::class];
    }

    /**
     * Get the repicients and body of the notification.
     *
     * @param  mixed  $notifiable
     * @return Builder
     */
    public function toSms($notifiable)
    {
        return (new Builder)->via('gateway') # via() is Optional
            ->send('this message')
            ->to('some number');
    }
}

Tip: You can use the same Builder Instance in the send method.

$builder = (new Builder)->via('gateway') # via() is Optional
    ->send('this message')
    ->to('some number');

Sms::send($builder);

# OR...
$builder = (new Builder)->send('this message')
    ->to(['some number']);

Sms::via('gateway')->send($builder);

Custom Made Driver, How To:

First you have to name your driver in the drivers array and also you can specify any config params you want.

'drivers' => [
    'textlocal' => [...],
    'twilio' => [...],
    'my_driver' => [
        ... # Your Config Params here.
    ]
]

Now you have to create a Driver Map Class that will be used to send the SMS. In your driver, You just have to extend Tzsk\Sms\Contracts\Driver.

Ex. You created a class : App\Packages\SMSDriver\MyDriver.

namespace App\Packages\SMSDriver;

use Tzsk\Sms\Contracts\Driver;

class MyDriver extends Driver 
{
    # You will have to make 2 methods.
    /**
    * 1. __constructor($settings) # {Mandatory} This settings is your Config Params that you've set.
    * 2. send() # (Mandatory) This is the main message that will be sent.
    *
    * Example Given below:
    */

    /**
    * @var array
    */
    protected $settings;

    /**
    * @var mixed
    */
    protected $client;

    /**
    * Your Driver Config.
    *
    * @var array $settings
    */
    public function __construct($settings)
    {
        $this->settings = $settings;
        # Initialize any Client that you want.
        $this->client = new Client(); # Guzzle Client for example.
    }

    /**
    * @return object Ex.: (object) ['status' => true, 'data' => 'Client Response Data'];
    */
    public function send()
    {
        $this->recipients; # Array of Recipients.
        $this->body; # SMS Body.

        # Main logic of Sending SMS.
        ...
    }

}

Once you crate that class you have to specify it in the sms.php Config file map section.

'map' => [
    ...
    'my_driver' => App\Packages\SMSDriver\MyDriver::class,
]

Note:- You have to make sure that the key of the map array is identical to the key of the drivers array.

🔬 Testing

composer test

📅 Changelog

Please see CHANGELOG for more information on what has changed recently.

❤️ Contributing

Please see CONTRIBUTING for details.

🔒 Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

👑 Credits

👮 License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].