ibnuhalimm/laravel-thai-bulk-sms

Thai Bulk SMS Wrapper for Laravel
1,043 1
Install
composer require ibnuhalimm/laravel-thai-bulk-sms
Latest Version:v1.2.1
PHP:^7.3|^8.0
License:MIT
Last Updated:Apr 23, 2022
Links: GitHub  ·  Packagist
Maintainer: ibnuhalimm

Laravel - Thai Bulk SMS

Latest Version on Packagist Total Downloads

Laravel wrapper for Thai Bulk SMS.

Contents

Requirements

  1. Sign Up for the Thai Bulk SMS Account
  2. Create a Api Key and Secret Key in Setting section

Installation

You can install the package via composer:

composer require ibnuhalimm/laravel-thai-bulk-sms

Optionally, you can publish the config file of this package with this command:

php artisan vendor:publish --provider="Ibnuhalimm\LaravelThaiBulkSms\ThaiBulkSmsServiceProvider"

Setting up

Put your API Key, Secret Key, and THAI_BULK_SENDER to .env file:

THAI_BULK_API_KEY=
THAI_BULK_SECRET_KEY=
THAI_BULK_SENDER=

Usage

  1. You can directly use the ThaiBulkSms Facade (the alias or class itself):

    use Ibnuhalimm\LaravelThaiBulkSms\Facades\ThaiBulkSms;
    
    // Send the sms to single recipient
    $phoneNumber = '+6612345678';
    $message = 'Hi, our message here.';
    ThaiBulkSms::send($phoneNumber, $message);
    
    // Send the sms to multiple phone number
    $phoneNumber = [
        '+6612345678',
        '+6690111213',
    ];
    $message = 'Hi, our message here.';
    ThaiBulkSms::send($phoneNumber, $message);
    

    The response format of this method will be like Thai Bulk SMS API's Response.

  2. Notifications Let's take a look at the implementation as Notifications Channel.

    use Ibnuhalimm\LaravelThaiBulkSms\ThaiBulkSmsChannel;
    use Ibnuhalimm\LaravelThaiBulkSms\ThaiBulkSmsMessage;
    use Illuminate\Notifications\Notification;
    
    class VerifyMobileNumber extends Notification
    {
        public function via()
        {
            return [ThaiBulkSmsChannel::class];
        }
    
        public function toThaiBulkSms($notifiable)
        {
            return (new ThaiBulkSmsMessage())
                ->message("Your OTP to complete the registration is {$this->otp}");
        }
    }
    

    In order to let the notification know which mobile phone number are you sending to, by default the channel will look for the mobile_number attribute of Notifiable model. If you want to override this behaviour, add the routeNotificationForThaiBulkSms method in your Notifiable model.

    public function routeNotificationForThaiBulkSms()
    {
        return $this->phone;
    }
    

    or set the recipient mobile number directly to the notifiable instance using to method

    ...
    public function toThaiBulkSms($notifiable)
    {
        return (new ThaiBulkSmsMessage())
            ->message("Your OTP to complete the registration is {$notifiable->otp}")
            ->to($notifiable->phone); // add this
    }
    ...
    

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email ibnuhalim@pm.me instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

9,089,784 258
rinvex/laravel-authy

Rinvex Authy is a simple wrapper for Authy TOTP, the best rated Two-Factor Authe...

78,132 32
toplan/laravel-sms

A mobile phone number validation solution based on laravel

80,664 835
laravel-notification-channels/authy

Authy notification channel for Laravel, with the ability to send in-app, sms, an...

46,701 57
kavenegar/laravel

laravel 4 and 5 kavenegar integration

368,693 86