Package Data | |
---|---|
Maintainer Username: | rahulhaque |
Maintainer Contact: | rahulhaque07@gmail.com (Rahul Haque) |
Package Create Date: | 2021-02-06 |
Package Last Update: | 2022-06-02 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-23 15:08:30 |
Package Statistics | |
---|---|
Total Downloads: | 272 |
Monthly Downloads: | 3 |
Daily Downloads: | 0 |
Total Stars: | 7 |
Total Watchers: | 2 |
Total Forks: | 2 |
Total Open Issues: | 0 |
ADN SMS gateway API package for Laravel.
You can install the package via composer in your Laravel or Lumen application.
composer require rahulhaque/adn-sms
Publish the configuration file config/adn-sms.php
where you can tweak some default options.
php artisan vendor:publish --provider="RahulHaque\AdnSms\AdnSmsServiceProvider"
Define your ADN_SMS_KEY
and ADN_SMS_SECRET
in the .env
file or update the config/adn-sms.php
file of your application.
Laravel comes pre-installed with Guzzle HTTP Client however Lumen does not. Install guzzle as this package depends on it to make the API calls.
composer require guzzlehttp/guzzle
Enable use of Facades
in your Lumen application by uncommenting the $app->withFacades();
call in the bootstrap/app.php
file.
Register the service provider in the Register Service Providers section of the bootstrap/app.php
file.
$app->register(RahulHaque\AdnSms\AdnSmsServiceProvider::class);
Define your ADN_SMS_KEY
and ADN_SMS_SECRET
in the .env
file of your application.
Or publish the config by copying the vendor/rahulhaque/adn-sms/config/adn-sms.php
file to config/adn-sms.php
of your Lumen application. Create the directory if doesn't exist. Register the config in the bootstrap/app.php
file in the Register Config Files section.
$app->configure('adn-sms');
Send single SMS to single recipient.
To send a single SMS, call the send()
method after providing to()
and message()
info. The send()
method will always return Illuminate\Http\Client\Response
object to interact further. See Laravel's HTTP Client documentation page for more details.
use RahulHaque\AdnSms\Facades\AdnSms;
class SomeController
{
public function someFunction()
{
$response = AdnSms::to('01XXXXXXXXX')
->message('Send SMS Test.')
->send();
dd($response->json());
}
}
Send OTP SMS to single recipient.
To send a OTP SMS, call the send()
method after providing otp()
and message()
info. The send()
method will always return Illuminate\Http\Client\Response
object to interact further. See Laravel's HTTP Client documentation page for more details.
use RahulHaque\AdnSms\Facades\AdnSms;
class SomeController
{
public function someFunction()
{
$response = AdnSms::otp('01XXXXXXXXX')
->message('Send OTP SMS Test.')
->send();
dd($response->json());
}
}
Send single SMS to multiple recipients.
To send bulk SMS, call the send()
method after providing array of recipients in the bulk()
method. Bulk SMS sending also require you to provide a campaignTitle()
. The send()
method will always return Illuminate\Http\Client\Response
object. See Laravel's HTTP Client documentation page for more details.
use RahulHaque\AdnSms\Facades\AdnSms;
class SomeController
{
public function someFunction()
{
$response = AdnSms::bulk(['01XXXXXXXXX', '02XXXXXXXXX'])
->campaignTitle('Bulk SMS Test')
->message('Send Bulk SMS Test.')
->send();
dd($response->json());
}
}
To add sending SMS to Laravel queue, call the queue()
method after calling all the required methods. The queue()
method accepts an optional callback function. The $response
from the API call will be automatically passed to the callback function which can be used to continue further process.
use RahulHaque\AdnSms\Facades\AdnSms;
use Illuminate\Http\Client\Response;
use App\Models\Table;
class SomeController
{
public function someFunction()
{
AdnSms::bulk(['01XXXXXXXXX', '02XXXXXXXXX'])
->campaignTitle('Bulk SMS Test')
->message('Send Bulk SMS Test.')
->queue(function (Response $response) {
// Process the $response further
$model = new Table();
$model->data = $response->body();
$model->save();
});
}
}
Do not forget to run php artisan queue:work
to send the queued SMS.
IMPORTANT: SMS queue()
method will not work in Lumen as it does not supports queueable closer. But don't lose hope. Create a queueable job in your Lumen application. Call the send()
method from there and process the returned response further.
To check ADN SMS balance, simply call the checkBalance()
method.
use RahulHaque\AdnSms\Facades\AdnSms;
class SomeController
{
public function someFunction()
{
$response = AdnSms::checkBalance();
dd($response->json());
}
}
To check already sent SMS status, simply call the checkSmsStatus()
method with SMS UID.
use RahulHaque\AdnSms\Facades\AdnSms;
class SomeController
{
public function someFunction()
{
$response = AdnSms::checkSmsStatus('SXXXXXXXXXXXXXXXX');
dd($response->json());
}
}
To check already sent SMS campaign status, simply call the checkCampaignStatus()
method with campaign UID.
use RahulHaque\AdnSms\Facades\AdnSms;
class SomeController
{
public function someFunction()
{
$response = AdnSms::checkCampaignStatus('CXXXXXXXXXXXXXXXX');
dd($response->json());
}
}
You can also set ADN SMS key and secret on runtime by calling the key()
and secret()
method which will override the settings from config file. There is a format()
method to set message format to TEXT|UNICODE
as well.
Set recipient number in tests/Feature/AdnSmsTest.php
and run.
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email at rahulhaque07@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.