GithubHelp home page GithubHelp logo

tzsk / sms Goto Github PK

View Code? Open in Web Editor NEW
276.0 11.0 78.0 1.38 MB

Laravel SMS Gateway Integration Package

License: MIT License

PHP 100.00%
sms-gateway laravel twilio textlocal link-mobility kavenegar melipayamak smsir sns driver

sms's Introduction

🎁 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 want 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',
        'from' => 'Your AWS SNS Sender ID', //sender
        '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 or Melipayamakpattern Configuration:

In case you want to use Melipayamak or Melipayamakpattern, 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();

# Change the from|sender|sim value with from() option:

sms()->via('gateway')->send("this message")->from('Your From Number | Sender Value | Sim Value ')->to(['Number 1', 'Number 2'])->dispatch();

# Sending argument and pattern code in pattern drivers such as melipayamakpattern and farazsmspattern.

#Note: The first argument is always known as the pattern code.

sms()->via('melipayamakpattern')->send("patterncode=123 \n arg1=name \n arg2=family")->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 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 Should implement these methods:
    *
    * 1. boot() -> (optional) Initialize any variable or configuration that you need.
    * 2. send() -> Main method to send messages.
    *
    * Note: settings array will be automatically assigned in Driver class' constructor.
    *
    * Example Given below:
    */

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

    protected function boot() : void
    {
        $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.

sms's People

Contributors

andvenaa avatar cedroux avatar dependabot-preview[bot] avatar dependabot[bot] avatar dijonneto avatar emanuelecoppola avatar hebrahimzadeh avatar khanzadimahdi avatar kopitar avatar laravel-shift avatar matthiez avatar mohammadhsn avatar mohaphez avatar moosti avatar nikitospush avatar omalizadeh avatar roshedgostarandev1 avatar sae13 avatar scrutinizer-auto-fixer avatar srustamov avatar tzsk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

sms's Issues

sfgsdfgsfg

fgsdfgsdfgsdfsdfsdfg
sdf
sdf
gsdf
sdf
sfg
sdf
dfg
sdf
sdfsfsdf
gsd
fsdfs
df

How to use farazsms pattern

Hi
I want to use farazsms pattern driver, but where I can set the template id and fill variables in the pattern?
Sms::via('farazsmspattern')->send($text)->to([$user->mobile])->dispatch();

Multiple Sender ID use case

As I've multiple sender ID in my textlocal account, I want to use these sender ID dynamically when sending SMS. How to achieve this with this package by using TextLocal as default SMS Gateway.
Thanks.

laravel 6 support

not support laravel 6 !
the below error has showed in composer:

  • don't install illuminate/support v5.8.8|don't install laravel/framework v6.0.3
  • don't install illuminate/support v5.8.9|don't install laravel/framework v6.0.3
  • Installation request for laravel/framework (locked at v6.0.3, required as ^6.0) -> satisfiable by laravel/framework[v6.0.3].
  • Installation request for tzsk/sms ^2.0 -> satisfiable by tzsk/sms[2.0.0, 2.0.1, 2.0.2].

gateway settings

Can set the gateway settings manually in controller?
something like this:
$chosenGateway = $request->gateway;
/* $request->gateway == twilio */
$chosenGateway->sid = $request->twilio_sid;
$chosenGateway->token= $request->twilio_token;
$chosenGateway->from= $request->twilio_from;
Sms::via($chosenGateway)->send("this message")->to(['Number 1', 'Number 2'])->dispatch();

array_merge(): Argument #1 is not an array

array_merge(): Argument #1 is not an array

Hi,
Am getting the following error
On /opt/lampp/htdocs/laravel/vendor/tzsk/sms/src/Drivers/Textlocal.php line number 56

screenshot from 2018-01-30 00-01-25

Details

  • Laravel version 5.6

No sms.php after php artisan vendor:publish

I required the package via composer, added the class to providers array and alias as stated in instructions. after that when I did php artisan vendor:publish I get no sms.php in my config folder.

Context

I am running a laravel 5.4 project

new release

please add new release for new features and update composer. tnx.

store sms in db

hi
thank you for this good package . i need event after send sms then store sms in db .

textlocal configuration

Detailed description

It is a request, I need textlocal configuration

Context

I am using this for 1 of my client, so I need configuration details.

How can it benefit other users?
Would help to all textlocal implementers

Possible implementation

Centos, PHP 7.4, Mysql
http://290px.com/elearn/public/

smsir package configuration

hi,
I want to use smsir package but there is not its configuration!!
and I have a question, this package support Laravel v7?

Error trying to use the Nexmo provider

Detailed description

I installed the client using composer, set up everything following the package documentation, but, when I run this line of code
Sms::send("Test 123")->to(['*********', '*********'])->dispatch();
I get this error:
Call to undefined method Nexmo\Application\Client::message()

Edit: from Whoops i can see that the error is thrown in file vendor/tzsk/sms/src/Drivers/Nexmo.php on line 50, but I really can't understand where the problem is, since there isn't any static call.

Your environment

  • Version used: PHP 7.2.1, Laravel 5.5.34
  • Operating system and version: OSX 10.14.3

Selecting Number in controller

Hello,
I was given two different numbers by my provider and I'm now trying to add the usage in my controller, in usage I can select which driver to send my message from, but there is no an option to select the number.

This package doesn't work on laravel 8.63

I just tried to install the package with "composer require tzsk/sms"
but it doesn't install and get this error :

Using version ^4.0 for tzsk/sms
./composer.json has been updated
Running composer update tzsk/sms
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- tzsk/sms[4.0.0, ..., 4.0.1] require illuminate/support ~5.7|~5.8|^6.0|^7.0 -> found illuminate/support[v5.7.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but these
were not loaded, likely because it conflicts with another require.
- Root composer.json requires tzsk/sms ^4.0 -> satisfiable by tzsk/sms[4.0.0, 4.0.1].

Installation failed, reverting ./composer.json and ./composer.lock to their original content.
Untitled

To Fix array_merge(): Argument #1 is not an array laravel 5.4

To Fix array_merge(): Argument #1 is not an array

please remove array_merge() functionality on Textlocal.php send() as it's the case which arises response as error on when the mobile number to send SMS is registered as dnd on Trai.
Code has to be changed as mentioned below
public function send()
{
$numbers = implode(",", $this->recipients);

$response = $this->client->request("POST", $this->settings->url, [
    "form_params" => [
        "username" => $this->settings->username,
        "hash" => $this->settings->hash,
        "numbers" => $numbers,
        "sender" => urlencode($this->settings->sender),
        "message" => $this->body,
    ],
]);

$data = $this->getResponseData($response);

return (object) $data;

}
Note: As I am using this package on my Laravel project when vendor folder get updated error arises so to fix this issue please change as soon as possible

sfgsdfg

fgsdfgsdfgsdfsdfsdfg
sdf
sdf
gsdf
sdf
sfg
sdf
dfg
sdf
sdfsfsdf
gsd
fsdfs
df

tzsk/sms "message": "Undefined index: gateway",

"message": "Undefined index: gateway",
"exception": "ErrorException",
"file": "C:\Users\saber\Documents\saberprojects\behplus\messaging-service\vendor\tzsk\sms\src\Sms.php",
"line": 96,

this is not work on windows

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

Call to undefined function App\Services\sms() in file

this code:

            return sms()->via($gateway)->send($message, function ($sms) use ($phones) {
                $sms->to($phones);
            });

had this error

<!doctype html>
<html class="theme-light">
<!--
Error: Call to undefined function App\Services\sms() in file /home/debug/public_html/messaging-service/app/Services/SmsService.php on line 11

class does not exist

i have taken following steps:

  1. composer require tzsk/sms

  2. php artisan vendor:publish --tag=config

  3. changes config file in config/sms.php

  4. calling these codes in required controller gives error:

`<?php
namespace App\Http\Controllers;
use App\Helper\Reply;
use App\Http\Requests\Sms\SendVerificationCode;
use App\Http\Requests\Sms\VerifyOTPCode;
use App\Notifications\NewUser;
use App\Traits\SmsSettings;
use App\User;
use Illuminate\Http\Request;
use Tzsk\Sms\Facades\Sms;

class VerifyMobileController extends Controller
{
use SmsSettings;

public function __construct()
{
    parent::__construct();
    $this->setSmsConfigs();
}

public function sendVerificationCode(SendVerificationCode $request)
{
      sms()->send("this message")->to(['9999999999'])->dispatch();
  }

}

OUTPUT:

{
"message": "Class does not exist",
"exception": "ReflectionException",
"file": "E:\wamp\www\laravael_project\vendor\tzsk\sms\src\SmsManager.php",
"line": 153,
"trace": [
{
"file": "E:\wamp\www\laravael_project\vendor\tzsk\sms\src\SmsManager.php",
"line": 153,
"function": "__construct",
"class": "ReflectionClass",
"type": "->"
},
{
"file": "E:\wamp\www\laravael_project\vendor\tzsk\sms\src\SmsManager.php",
"line": 69,
"function": "validateDriver",
"class": "Tzsk\Sms\SmsManager",
"type": "->"
},
{
"file": "E:\wamp\www\laravael_project\vendor\tzsk\sms\src\SmsManager.php",
"line": 45,
"function": "via",
"class": "Tzsk\Sms\SmsManager",
"type": "->"
},
{
"file": "E:\wamp\www\laravael_project\vendor\tzsk\sms\src\Provider\SmsServiceProvider.php",
......

    ................... so ON

`
please help me asap, i am stuck here
Thanks

I think some drivers need to be refactored

Why is foreach used in most drivers to send SMS to multiple numbers?
While 90% of the providers support simultaneous reception of several receivers.

In this case, to send SMS to 100 recipients, 100 connections must be created.
While it is easily sent with a connection.

On the other hand, an array of 100 items should be returned to the user as a response.
And the user parses it again with foreach.
While one answer is enough for all 100 item.

what is your opinion ?
If you agree, I will refactor the drivers that support this feature.

SNS message type - Transactional throwing an invalid message type error

image

I am using SNS and I have followed the installation guide. Messaging works well with the message type Promotional however when switched to transactional, it throws the aforementioned error.

Sms::send("Your Code")->to(['Number 1'])->dispatch();

Tried to encode the Message attribute as a JSON object, but still threw the error. Any help would be greatly appreciated.

Using Laravel V7 with SMS version 5.2

Works in localhost but does not work with cpanel host

Thanks for your great package
I noticed this package works on localhost but it throws error on host cpanel

syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST)

That is my code:

        $valid = $this->valid($number);
        if (!$valid) {
            return response()->json(['errors' => [
                'phone' => [
                    'شماره تلفن نامعتبر است'
                ]
            ]], 422);
        }
        $user = User::wherePhone($number)->first();
        $user = $this->addUserIfDoesNotExist($user, $number);
        $code = $this->addCode($user);
        Sms::send("کد فعالسازی شما $code میباشد ")->to([$number])->dispatch();

I tried this also:

        Sms::send("کد فعالسازی شما $code میباشد ")->to($number)->dispatch();

Thanks in advance!

About SMS configuration settings

How can I manually add configuration settings from here,

Sms::via('twilio')->send("this message")->to(['+9196*********'])->dispatch();

Twilio has Account SID, Auth Token, and Twilio number, instead of configuring config/sms.php
If I wanted to set it from the same chain, is it possible? if yes, please give me a short code for it.

Thank you

conflict with laravel 9

Hi .
tzsk/sms has an error on upgrading laravel 8 to laravel 9
that is "illuminate/support" dependency used in tzsk/sms and can not used in laravel 9.
please check yourself.

sfgsdfgsfgsdf

fgsdfgsdfgsdfsdfsdfg
sdf
sdf
gsdf
sdf
sfg
sdf
dfg
sdf
sdfsfsdf
gsd
fsdfs
df

add some features to each driver if they support.

Hi, what's your opinion about adding some features to each driver and a feature checking ability to the package?
for example, some SMS gateways can send bulk messages and some of them doesn't support bulk messages.
I can create the below syntax:

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

or something like the below syntax:

// check if given gateway supports bulk sending messages.
if (Sms::via('gateway')->supportsBulkMessage()) { 
       //
}

if I add this feature, would you merge it ?

Access manager object using a helper function

Add A helper function that returns the SmsManager object, Some people prefer helper functions instead of Laravel Facades.

The helper allow people to use package throught this way:

sms()->to($someOne)-> ...

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.