tipytechnique/laravel-ovh-sms

Use the OVH SMS API in your Laravel 5.8 application.

0.1.2 2019-10-14 10:32 UTC

This package is auto-updated.

Last update: 2025-03-14 22:31:13 UTC


README

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.