GithubHelp home page GithubHelp logo

fre5h / sinchbundle Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 1.0 149 KB

๐Ÿ“ฆ Provides integration with Sinch.com SMS API.

Home Page: https://www.sinch.com/docs/sms-rest/index.html

License: MIT License

PHP 100.00%
symfony symfony-bundle sinch sms php bundle

sinchbundle's Introduction

SinchBundle

๐Ÿ“ฆ 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.

sinchbundle's People

Contributors

fre5h avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dexit

sinchbundle'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.