Connect your Application with bulk sms in Tanzania using Beem
Are you developing a web application or web service in Tanzania and you are in need to connect with bulk sms this could be for various reasons i.e OTP , Sending notification to your subscribers or users via sms or simply you need to broadcast an sms to the public using a database that you either own or outsource.
As a software engineer, this need has popped up a lot in the past 8 years of my development experience to the fact that i found my self re-writing codes almost everytime when a new project pops up.
Hence i recently started to follow the code reuserbility modal mainly to help me focus on the business logic or business case of the project that am working on.
On this article am going to introduce to you a laravel package that i have published days ago that can help you as a developer to easily integrate with a bulk sms provider bongolive and start sending sms to your users.
Please do note that below instructions are mainly on intergration and not how to get registered with the service.
- Set Up.
Package requirement
- PHP version ^7.0
- Laravel version ^5.0 - Download the package in your project by running the code below.
composer require epmnzava/bongolivesms-laravel
3. If your using laravel version 5.4 and below please follow the following instructions
Add the service provider to the providers array in config/app.php:
Epmnzava\BongolivesmsLaravel\BongolivesmsLaravelServiceProvider::class,
Add the facade to the aliases array in config/app.php:
'BongolivesmsLaravel'=>Epmnzava\BongolivesmsLaravel\BongolivesmsLaravelFacade::class,
4.Then publish the library as below
Publish the configuration file and migrations by running the provided console command:
php artisan vendor:publish — provider=”Epmnzava\BongolivesmsLaravel\BongolivesmsLaravelServiceProvider”
5. Add environment variables as given by bongolive dashboard.
BONGO_LIVE_KEY your provided bongolive api key
BONGO_LIVE_SECRET your provided bongolive secret
How to use the library
Please see the code snippet below on how to use the library on your own controller.
Usage
Sending to one msisdn at a time <?php
use BongolivesmsLaravel;class DashboardController extends Controller
{
//
public function runSms(){//assuming $recipient_msisdn is your receipient number
//we need to change it from 0XXXX to 255XXXif(substr($recipient_msisdn, 0, 1)==0){
$msisdn = ltrim($recipient_msisdn, "0"); $recipient_msisdn="255"."".$msisdn;
}else{}
$response=BongolivesmsLaravel::send__single_recipient($source_addr,$message,$recipient_msisdn); }
Sending multiple msisdn at one by passing an array of numbers<?php
use BongolivesmsLaravel;class DashboardController extends Controller
{
//
public function runSms(){//assuming $recipient_msisdn is your receipient number
//we need to change it from 0XXXX to 255XXX
$recipient_array=["255679079774","2556789909"];
$response=BongolivesmsLaravel::send__multiple_recipient($source_addr,$message,$recipient_array); }
For more information about this package please visit the repository
see: https://github.com/dbrax/bongolive-sms-laravel
Before you go… Thanks for reading the article! If you enjoyed it, please don’t forget to show your appreciation by clicking 👏 below!
Any questions or comments hit me up on
Mail: epmnzava@gmail.com
Twitter: https://twitter.com/epmnzava
Github: https://github.com/dbrax