GithubHelp home page GithubHelp logo

laravel-ovh-sms's Introduction

Build Status

laravel-ovh-sms

Installation

You can install the package via composer:

composer require tipytechnique/laravel-ovh-sms

Usage

Credentials

First you need to set your OVH credentials on your .env file :

OVHSMS_APP_KEY = "your-app-key"
OVHSMS_APP_SECRET = "your-app-secret"
OVHSMS_CONSUMER_KEY = "your-consumer-key"
OVHSMS_ACCOUNT = "your-sms-account"
OVHSMS_SENDER = "your-sms-sender"

To create your credentials, you can visit https://api.ovh.com/createToken/index.cgi?GET=/sms&GET=/sms/*&PUT=/sms/*&DELETE=/sms/*&POST=/sms/*

Optionally, you can publish this package's configuration file on your config folder by running

php artisan vendor:publish --provider="TipyTechnique\LaravelOvhSms\SmsServiceProvider"

If you are using the Themosis framework, run

php console vendor:publish --provider="TipyTechnique\LaravelOvhSms\SmsServiceProvider"

Examples

Dependency injection vs Facade

You can either use the depency injection or the Facade to manage your sms.

// Using depency injection

use Illuminate\Routing\Controller as BaseController;
use TipyTechnique\LaravelOvhSms\Contracts\Sms;

class SmsController extends BaseController
{
    /**
     * Get all outgoing messages
     *
     * @param Sms $sms
     *
     * @return array
     */
    public function getAllSms(Sms $sms): array
    {
        return $sms->getMessages('incoming');
    }
}
// Using Facade

use Illuminate\Routing\Controller as BaseController;
use TipyTechnique\LaravelOvhSms\Facades\Sms;

class SmsController extends BaseController
{
    /**
     * Get all outgoing messages
     *
     * @param Sms $sms
     *
     * @return array
     */
    public function getAllSms(Sms $sms): array
    {
        return Sms::getMessages('incoming');
    }
}

Create a message

/**
 * First parameter  : receivers, can be a single one (string) or multiple (array)
 * Second parameter : isMarketing, true or false
 * Thir parameter   : allowResponse, true or false
 */
$message = Sms::createMessage('+33654213566', false, false);
$message = Sms::createMessage(['+33654213566', '+33652147895'], false, true);

Send a message

$message = Sms::createMessage('+33654213566', false, false);
$message->send('Hello world');

// Or with a single line
Sms::createMessage('+33654213566', false, false)->send('Hello world');

Get messages

// get ongoing messages
$messages = Sms::getMessages('ongoing');

// get incoming messages
$messages = Sms::getMessages('incoming');

// get planned messages
$messages = Sms::getMessages('planned');

// for ongoing and incoming messages, you can use a second argument to set filters
// all filters are optionals
$messages = Sms::getMessages(
    'ongoing', 
    [
        'dateStart' => '2019-07-01 12:00:00',    // using date as a string
        'dateEnd' => new DateTime('2019-08-01'), // using DateTime object
        'sender' => 'your-sender',
        'receiver' => 'a-receiver',
        'tag'  => 'a-tag'   
    ]
);

Handle blacklisted numbers

// get all blacklisted numbers
$blasklisted = Sms::getBlacklistedNumbers(); // array

// remove a given number from the blacklist
Sms::removeBlacklistedNumber('+33654632544');

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Issue

Please submit your issue using the issue tracker.

Credits

License

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

laravel-ovh-sms's People

Contributors

tipytechnique avatar

laravel-ovh-sms's Issues

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.