Developed with love by KnpLabs Hire us for your project!
30

SinchBundle

by fre5h

SinchBundle

:package: Provides integration with Sinch.com SMS API.

Currently in development process! Things can be changed at any moment!

Sinch Logo

Scrutinizer Quality Score
Build Status
CodeCov
License
Latest Stable Version
Total Downloads
StyleCI
Gitter

SensioLabsInsight
knpbundles.com

Requirements

  • PHP 7.1 and later
  • Symfony 4.0 and later

Installation

Create application for Sinch

Sing up in Sinch.com and create a new app.

Add dependency via Composer

composer req fresh/sinch-bundle='dev-master'

Add key and secret to parameters.yml

Add the following lines to your parameters.yml.dist file:

parameters:
    sinch.key: EnterKeyForYourSinchApp
    sinch.secret: EnterSecretForYourSinchApp

During the composer update you have to enter your own key and secret for your Sinch application,
which you can find in your Sinch dashboard.

Update config.yml

Add the following lines to config.yml file:

fresh_sinch:
    key: "%sinch.key%"
    secret: "%sinch.secret%"

Usage

Example of sending SMS

use Fresh\SinchBundle\Service\Sinch;

class Foo {
    public function bar(Sinch $sinch) {
        // Set the outbound number where you want to send the SMS
        $messageId = $sinch->sendSMS('+13155555552', 'Your message');

        // If success then the ID of sent message is returned (it is an integer value)
        echo $messageId;
    }
}

Example of checking SMS status

use Fresh\SinchBundle\Service\Sinch;

class Foo {
    public function bar(Sinch $sinch) {
        $messageId = 123456789; // The ID of Sinch message you get after successful SMS sending

        // Status is a string with one of these values: pending, successful, faulted, unknown
        $status = $sinch->getStatusOfSMS($messageId);

        // Other helper methods, return true of false
        $sinch->smsIsSentSuccessfully($messageId);
        $sinch->smsIsPending($messageId);
        $sinch->smsIsFaulted($messageId);
        $sinch->smsInUnknownStatus($messageId);
    }
}

Catching and processing Sinch exceptions

use Fresh\SinchBundle\Exception\PaymentRequired\SinchPaymentRequiredException;
use Fresh\SinchBundle\Service\Sinch;

class Foo {
    public function bar(Sinch $sinch) {
        try {
            $messageId = $sinch->sendSMS($phoneNumber, 'Your message');
            // Some logic related to SMS processing...
        } catch (SinchPaymentRequiredException $e) {
            $logger->error('SMS was not sent. Looks like your Sinch account run out of money.');
            // Here you can, for example, send urgent emails to admin users
            // to notify that your Sinch account run out of money
        }
    }
}

Contributing

See CONTRIBUTING file.

The MIT License (MIT)

Copyright (c) 2015-2020 Artem Henvald

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

  • Create CODEOWNERS
    By web-flow, 4 months ago
  • Update LICENSE
    By web-flow, 4 months ago
  • Update README.md
    By web-flow, 5 months ago
  • Update .travis.yml
    By web-flow, 5 months ago
  • Create FUNDING.yml
    By web-flow, 11 months ago
  • Update .travis.yml
    By web-flow, 11 months ago
  • Update LICENSE
    By web-flow, 1 year ago
  • Update .travis.yml
    By web-flow, 1 year ago
  • Update .travis.yml
    By web-flow, 1 year ago
  • Update README.md
    By web-flow, 2 years ago
  • Merge pull request #2 from fre5h/develop
    By web-flow, 2 years ago
  • Switch to Symfony 4.0
    By Artem Henvald, 2 years ago
  • Update year in license
    By web-flow, 2 years ago
  • Refactoring
    By web-flow, 2 years ago
  • Update composer.json
    By web-flow, 2 years ago
  • Update composer.json
    By web-flow, 2 years ago
  • Update README.md
    By web-flow, 3 years ago
  • Update .gitattributes
    By web-flow, 3 years ago
  • Update LICENSE
    By web-flow, 3 years ago
  • Fix some StyleCI issues
    By fre5h, 3 years ago
  • Fix some StyleCI issues
    By fre5h, 3 years ago
  • Add StyleCI checks
    By fre5h, 3 years ago
  • Fix event in SinchService
    By fre5h, 3 years ago
  • Update dev requirements
    By web-flow, 3 years ago
  • Update .travis.yml
    By web-flow, 3 years ago
  • Refactoring
    By web-flow, 3 years ago
  • Update composer.json
    By web-flow, 3 years ago
  • Fix Gitter badge
    By web-flow, 3 years ago
  • Split docs
    By fre5h, 3 years ago
  • Change guzzle version
    By fre5h, 3 years ago