Skip to content

Instantly share code, notes, and snippets.

@takshaktiwari
Last active March 3, 2022 15:11
Show Gist options
  • Save takshaktiwari/ef9a2d86d4c2300dc9b346020ed1b0dc to your computer and use it in GitHub Desktop.
Save takshaktiwari/ef9a2d86d4c2300dc9b346020ed1b0dc to your computer and use it in GitHub Desktop.
Textlocal Sms Gateway

Sample Use Case

(new \App\Gateways\TextlocalSms)->message(
    'send_otp', 
    [
        'name'      => $user->name, 
        'otp'       => $otp, 
        'timeout'   =>  '15 Minutes'
    ]
)
->send($mobile)->output();

Edit Namespace, API Keys and other details according to your need.

<?php
namespace App\Gateways;
use Illuminate\Support\Facades\Http;
class TextlocalSms
{
public $apikey = 'NDQ3MjYxNTczORYjdsusdTYIUSJTesting=';
public $sender = 'TSTING';
public $message;
public $mobiles;
public $output;
public function __construct($mobiles=null)
{
if ($mobiles) {
$this->mobiles = is_array($mobiles) ? $mobiles : [$mobiles];
}else{
$this->mobiles = [];
}
}
public function mobiles($mobiles)
{
$this->mobiles = is_array($mobiles) ? $mobiles : [$mobiles];
}
public function message($template, $params)
{
$templateFun = 'sms_'.$template;
$this->message = $this->$templateFun($params);
return $this;
}
public function send($mobiles=null)
{
if ($mobiles) {
$this->mobiles($mobiles);
}
$this->output = Http::asForm()
->post('https://api.textlocal.in/send/', [
'apikey' => $this->apikey,
'numbers' => implode(',', $this->mobiles),
'sender' => $this->sender,
'message' => urlencode($this->message)
])
->json();
return $this;
}
public function output()
{
return $this->output;
}
public function sms_booking_complete($params)
{
return "Hi ".$params['name'].", you have successfully booked a vehicle having Reg No ".$params['regNo']." for ".$params['bookingDate'].". We will inform you for further updates. Company PVT. LTD.";
}
public function sms_vehicle_approved($params)
{
return "Hi ".$params['name'].", your vehicle , Reg No ".$params['regNo']." has been approved. Please wait for your bookings, we will inform you when you have any booking. Company PVT. LTD.";
}
public function sms_vehicle_registered($params)
{
return "Hi ".$params['name'].", your vehicle , Reg No ".$params['regNo']." has been registered. We will inform you when the details will be checked and verified. Company PVT. LTD.";
}
public function sms_send_otp($params)
{
return "Hi ".$params['name'].", the OTP to login to your Bmyroad account is ".$params['otp'].". Valid till ".$params['timeout'].". Do not share this to anyone. Company PVT. LTD.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment