tzsk / sms

Laravel SMS Gateway Integration Package
MIT License
289 stars 79 forks source link

Multiple Sender ID use case #278

Closed mohdfayeem closed 3 years ago

mohdfayeem commented 3 years ago

As I've multiple sender ID in my textlocal account, I want to use these sender ID dynamically when sending SMS. How to achieve this with this package by using TextLocal as default SMS Gateway. Thanks.

tzsk commented 3 years ago

@mohdfayeem In the config/sms.php file add another configuration for Text Local. And add a handler map for that custom driver to TextLocal class.

'drivers' => [
  ...
  'backup' => [...]
  ...
],

'map' => [
  ...
  'backup' => \Tzsk\Sms\Drivers\Textlocal::class,
  ...
],

// Now send using 
Sms::via('backup')->send("Hello")->to([******])->dispatch();

Keep the backup driver settings the same as textlocal with your necessary changes.

mohdfayeem commented 3 years ago

Thanks for your help. It really helpful.

nxmndr commented 1 year ago

For the record, if one wants to have dynamic configuration that doesn't require to edit config, the Tzsk\Sms\Sms class accepts config as constructor parameter.

You need to create your own App\Channels\SmsChannel :

(new Sms($smsOptions))
    ->send($msg)
    ->to([$phone])
    ->dispatch();

You can them store your custom $smsOptions in the options column of your businesses table or equivalent.