2017 © Pedro Peláez
 

symfony-bundle sinch-bundle

Provides integration with Sinch.com SMS API.

image

fresh/sinch-bundle

Provides integration with Sinch.com SMS API.

  • Tuesday, January 2, 2018
  • by Fresh
  • Repository
  • 1 Watchers
  • 8 Stars
  • 665 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

SinchBundle

:package: Provides integration with Sinch.com SMS API., (*1)

Currently in development process! Things can be changed at any moment!, (*2)

Sinch Logo, (*3)

Scrutinizer Quality Score Build Status CodeCov License Latest Stable Version Total Downloads StyleCI Gitter, (*4)

SensioLabsInsight knpbundles.com, (*5)

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., (*6)

Add dependency via Composer

composer req fresh/sinch-bundle='dev-master', (*7)

Add key and secret to parameters.yml

Add the following lines to your parameters.yml.dist file:, (*8)

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., (*9)

Update config.yml

Add the following lines to config.yml file:, (*10)

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., (*11)

The Versions

02/01 2018
02/01 2018
04/12 2017
15/06 2016