Skip to content

Unified SMS library package for Laravel 5 and PHP (Non-Laravel) to send text messages.

License

Notifications You must be signed in to change notification settings

victorybiz/unified-sms

Repository files navigation

Unified SMS

GitHub release Software License Build Status Packagist

Unified SMS library package for Laravel and PHP (Non-Laravel) to send text messages through multiple swappable drivers.

Supported Drivers and Services

It currently ships with the following drivers:

Installation

Install using composer, from the command line run:

$ composer require victorybiz/unified-sms

Laravel Project

Alternatively, you can add "victorybiz/unified-sms": "^1.1" to your composer.json file's require section and then you'll then need to run composer install or composer update to download it and have the autoloader updated.

If you use Laravel >= 5.5 you can skip this step and go to configuration

If you use Laravel < 5.5, you need to register the service provider with the application. Open up config/app.php and locate the providers key.

'providers' => [

    Victorybiz\UnifiedSMS\UnifiedSMSServiceProvider::class,

]

And add the UnifiedSMS alias to config/app.php:

'aliases' => [

	'UnifiedSMS' => Victorybiz\UnifiedSMS\Facades\UnifiedSMSFacade::class,

]

Configuration (Laravel)

You must publish the package's configuration files, (unified-sms.php also published with this) And add the UnifiedSMS alias to config/app.php:

php artisan vendor:publish --tag=unified-sms

Open up config/unified-sms.php use the env variables to set your DEFAULT DRIVER and API Credentials.

Usage in Laravel Project

Please use the UnifiedSMS Facade

use UnifiedSMS;

You're good to go, send sms

$msg = [
			'from' => 'Your sender ID here', // default_sender_id set in config file will be used if this line is removed or comment out
			'to' => 'The recipent mobile number, international format without the leading plus ( )',
			'text' => 'Your text message here.',
	   ];
$response = UnifiedSMS::sendSMS($msg);

Usage in PHP (Non-Laravel) Project

Require the vendor autoload file in your php script.

require_once 'path/to/vendor/autoload.php';

Create a unified_sms_config.php file anywhere in your project directory. Enter the following block into your unified_sms_config.php and set your DEFAULT DRIVER and API Credentials.

<?php
$unified_sms_config = [
    /*
    |--------------------------------------------------------------------------
    | Default SMS driver
    |--------------------------------------------------------------------------
    | This option controls the default SMS driver to use.
    |
    | Supported: "null", "routemobile", "nexmo", "moreify", "betasms", "multitexter"
    */
    'default_sms_driver' => 'null',
	
	/*
    |--------------------------------------------------------------------------
    | Default VOICE SMS driver
    |--------------------------------------------------------------------------
    | This option controls the default Voice SMS driver to use.
    |
    | Supported: "null"
    */
    'default_voice_sms_driver' => 'null',
	
    /*
    |--------------------------------------------------------------------------
    | Drivers
    |--------------------------------------------------------------------------
    | Here you can define the settings for each driver. 
    */
    'drivers' => [
		'null' => [
			'sms' => [
				'default_sender_id' => 'Null',
				'api_key' => 'null'
			],
			'voice' => [
				'default_caller_id' => ' 1000',
				'api_key' => 'null',
			],            
		],
		'routemobile' => [
			'sms' => [
				'default_sender_id' => 'INFO',
				'server' => '',
				'port' => '8080',
				'username' => '',
				'password' => '',
			],          
		],
		'nexmo' => [
			'sms' => [
				'default_sender_id' => 'INFO',
				'api_key' => '',
				'api_secret' => '',
				'callback_url' => null, // The webhook endpoint the delivery receipt for this sms is sent to. 
									// If set, it overrides the webhook endpoint you set in Dashboard 
			], 
		],
		'moreify' => [
			'sms' => [
				'project' => '',
				'password' => '',
			], 
		],
		'betasms' => [
			'sms' => [
				'default_sender_id' => 'INFO',
				'username' => '',
				'password' => '',
			], 
		],
		'multitexter' => [
			'sms' => [
				'default_sender_id' => 'INFO',
				'email' => '',
				'password' => '',
				'force_dnd' => true,
			], 
        ],
	],
];

Require the config file in your php script.

require_once 'path/to/unified_sms_config.php';
use Victorybiz\UnifiedSMS\UnifiedSMS;

$unifiedSMS = new UnifiedSMS($unified_sms_config); 

Alternatively

$unifiedSMS = new \Victorybiz\UnifiedSMS\UnifiedSMS($unified_sms_config);

You're good to go, send sms

$msg = [
			'from' => 'Your sender ID here', // default_sender_id set in config file will be used if this line is removed or comment out
			'to' => 'The recipent mobile number, international format without the leading plus ( )',
			'text' => 'Your text message here.',
	   ];
$response = $unifiedSMS->sendSMS($msg);

Response from Drivers

On successful, $response will return json data

{
	"status":true,
	"statusCode":200,
	"statusDescription":"Success",
	"data": {
		"to":"Recipient phone number",
		"messageId":"The Message ID from the driver service provider",
		"_comment":"May include additional data but depends on the response from the driver service provider"
	},
	"driver":"the default driver used"
}

On failure, $response will return json data

{
	"status":false,
	"statusCode":"status error code here",
	"statusDescription":"Status description / message",
	"data":null,
	"driver":"the default driver used"
}

The failure status codes are

200				Success
1001			Invalid URL or Missing Params
1002			Invalid credentials
1003			Invalid recipient
1004			Invalid sender
1005			Invalid message
1006			Invalid message type
1007			Invalid delivery
1008			Insufficient credit
1009			Response timeout
1010			Internal error
1011			Account Suspended

Bug Reports and Issue tracking

Kindly make use of the issue tracker for bug reports, feature request, additional web service request and security issues.

License

MIT

About

Unified SMS library package for Laravel 5 and PHP (Non-Laravel) to send text messages.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages