Skip to content

Latest commit

 

History

History
executable file
·
133 lines (104 loc) · 3.92 KB

README.md

File metadata and controls

executable file
·
133 lines (104 loc) · 3.92 KB

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.