2017 © Pedro Peláez
 

library sms-bundle

Provide email and SMS sending functions

image

headsnet/sms-bundle

Provide email and SMS sending functions

  • Wednesday, October 18, 2017
  • by benr77
  • Repository
  • 1 Watchers
  • 0 Stars
  • 371 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 19 % Grown

The README.md

Symfony SMS Bundle

Symfony bundle to send and receive SMS messages. Currently only the Esendex SMS gateway is supported - https://www.esendex.com/. Other gateways may be added in the future., (*1)

Greatly inspired by the excellent tomazahlin/symfony-mailer-bundle https://github.com/tomazahlin/symfony-mailer-bundle, (*2)

Installation

Requires Symfony >= 3.3 and PHP >= 7.0, (*3)

Install with Composer, (*4)

composer require headsnet/sms-bundle, (*5)

Add bundle to AppKernel.php, (*6)

public function registerBundles()
{
    $bundles = array(
        // ...
        new Headsnet\SmsBundle\HeadsnetSmsBundle(),
    );
}

If you need to receive SMS then add the routing configuration in app/config/routing.yml, (*7)

headsnet_sms:
  resource: '@HeadsnetSmsBundle/Resources/config/routing.yml'
  prefix:   '/sms'

Configuration

Add required configuration in app/config.yml, (*8)

headsnet_sms:
  dispatcher:          esendex
  esendex:
    account_reference: ~
    username:          ~
    password:          ~
    vmn:               ~  # Virtual Mobile Number

To simulate SMS sending, you can use the DummyDispatcher - for example in your when running your test suite - add the following to app/config_test.yml, (*9)

headsnet_sms:
  dispatcher: dummy

To override the recipient phone number, for example in development, add the following to app/config_dev.yml, (*10)

headsnet_sms:
  delivery_override:   '+33123456789'

Define SMS message templates

Create a mapping service to link template path definitions to template names, (*11)

<?php
declare(strict_types=1);

namespace AppBundle\Sms;

use Headsnet\Sms\Mapping\TemplateMappingInterface;

/**
 * Map template reference names to template paths
 */
class Mapping implements TemplateMappingInterface
{
    /**
     * @return array
     */
    public function getMappings()
    {
        return [
            'customer.confirm' => '@AppBundle/sms/customer.confirm.text.twig',
            'customer.reminder' => '@AppBundle/sms/customer.reminder.text.twig'
        ];
    }
}

Sending SMS

To send SMS, inject the SMS sender service in to your code. From here you can access the SMS message factory, or the SMS sender, (*12)

namespace Company\App;

use Headsnet\Sms\SmsSendingInterface;

class MyService
{
    private $smsSending;

    public function __construct(SmsSendingInterface $smsSending)
    {
        $this->smsSending = $smsSending;
    }

    public function doSomething()
    {
        // How to access factory to create SMS instances
        $factory = $this->smsSending->getFactory();

        // How to access sender to send or queue the SMS
        $smsSender = $this->smsSending->getSmsSender();
    }
}

Setting up Push Notifications

If you want the EsendexEventDispatcher gateway to phone home with delivery notifications etc, you must ensure you have added the bundle's routing in your routing.yml file., (*13)

Then, in your EsendexEventDispatcher control panel, configure the Push Notifications routes with the following URLs:, (*14)

SMS received, (*15)

https://app.your-domain.com/sms/esendex/message-received, (*16)

SMS delivered, (*17)

https://app.your-domain.com/sms/esendex/delivery-notify, (*18)

SMS failed, (*19)

https://app.your-domain.com/sms/esendex/delivery-error, (*20)

Opt-out, (*21)

https://app.your-domain.com/sms/esendex/opt-out, (*22)

These end-points will receive the payload from EsendexEventDispatcher and dispatch one of the following events:, (*23)

  • headsnet.sms.delivered
  • headsnet.sms.error
  • headsnet.sms.received
  • headsnet.sms.opt_out

Listeners to these events will receive a Headsnet\SmsBundle\Event\SmsEvent instance which contains the message data., (*24)

View an example Event Subscriber for these events., (*25)

Contributing

Pull requests and other contributions are very welcome., (*26)

The Versions

18/10 2017

v0.1.11

0.1.11.0

Provide email and SMS sending functions

  Sources   Download

MIT

The Requires

 

18/10 2017

dev-develop

dev-develop

Provide email and SMS sending functions

  Sources   Download

MIT

The Requires

 

18/10 2017

v0.1.10

0.1.10.0

Provide email and SMS sending functions

  Sources   Download

MIT

The Requires

 

17/10 2017

v0.1.9

0.1.9.0

Provide email and SMS sending functions

  Sources   Download

MIT

The Requires

 

10/10 2017

v0.1.8

0.1.8.0

Provide email and SMS sending functions

  Sources   Download

MIT

The Requires

 

10/10 2017

v0.1.7

0.1.7.0

Provide email and SMS sending functions

  Sources   Download

MIT

The Requires

 

10/10 2017

v0.1.6

0.1.6.0

Provide email and SMS sending functions

  Sources   Download

MIT

The Requires