This package makes it easy to send notifications using Textlocal with Laravel 5.6+
Supports using both Transactional and Promotional accounts with Textlocal at the same time.
composer require thinkstudeo/textlocal-notification-channel
Taking advantage of automatic package discovery available since Laravel 5.5, the service provider will be registered automatically.
Add your textlocal accounts, api url and credentials in the config/services.php
file.
The url is required to be set in the config file because, textlocal has different urls for different countries.
Atleast for India, its different. https://api/textlocal.in/send/
...
'textlocal' => [
'url' => 'https://api.textlocal.com/send/' //or 'https://api.textlocal.in/send/ - for India
//Textlocal Transactional Account
'transactional' => [
'apiKey' => env('TEXTLOCAL_TRANSACTIONAL_KEY'),
'from' => env('TEXTLOCAL_TRANSACTIONAL_FROM', 'TXTLCL')
],
//Textlocal Promotional Account
'promotional' => [
'apiKey' => env('TEXTLOCAL_PROMOTIONAL_KEY'),
'from' => env('TEXTLOCAL_PROMOTIONAL_FROM', 'TXTLCL')
]
],
...
Don't forget to add the keys to your .env
file
...
TEXTLOCAL_TRANSACTIONAL_KEY= <Your Textlocal Transactional Account API KEY>
TEXTLOCAL_TRANSACTIONAL_FROM= <Registered/Approved sender for your Textlocal Transactional Account>
TEXTLOCAL_PROMOTIONAL_KEY= <Your Textlocal Promotional Account API KEY>
TEXTLOCAL_PROMOTIONAL_FROM= <Registered/Approved sender for your Textlocal Promotional Account>
...
To use the channel, include the NotificationChannels\Textlocal\TextlocalChannel
class in the via()
method of your notification class.
use Illuminate\Notifications\Notification;
use NotificationChannels\Textlocal\TextlocalChannel;
use NotificationChannels\Textlocal\TextlocalMessage;
class SendBlackFridaySaleAnnouncement extends Notification
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [TextlocalChannel::class];
}
/**
* Get the Textlocal / SMS representation of the notification.
*
* @param mixed $notifiable
* @return NexmoMessage
*/
public function toTextlocal($notifiable)
{
return (new TextlocalMessage())
//Required
// To send sms via your Textlocal promotional account
//or transactional() to sent via Textlocal transactional account
->promotional()
//Optional
//If you don't provide a from, it will pick up the value from the config
->from('TXTLCL')
//Optional
//If you want to send a copy of the sms to another number eg an Admin
->cc('914545454545')
//Required
->content('We are running a BlackFriday sale from tomorrow for 3 days with 40% off. Hurry !!! Grab the opportunity!');
}
}
use Illuminate\Notifications\Notification;
use NotificationChannels\Textlocal\TextlocalChannel;
use NotificationChannels\Textlocal\TextlocalMessage;
class SendLoginOtp extends Notification
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [TextlocalChannel::class];
}
/**
* Get the Textlocal / SMS representation of the notification.
*
* @param mixed $notifiable
* @return NexmoMessage
*/
public function toTextlocal($notifiable)
{
return (new TextlocalMessage())
//Required
// To send sms via your Textlocal transactional account
//or promotional() to sent via Textlocal promotional account
->transactional()
//Optional
//If you don't provide a from, it will pick up the value from the config
->from('TXTLCL')
//Optional
//If you want to send a copy of the sms to another number eg an Admin
->cc('914545454545')
//Required
//When sending through Textlocal transactional account, the content must conform to one of your approved templates.
->content('Your OTP for Application is 234567. It is valid for the next 10 minutes only.');
}
}
Please see CHANGELOG for more information what has changed recently.
Fill in the env
values in the phpunit.xml.dist
. The tests depends on these values.
<php>
<env name="APP_ENV" value="Testing"/>
<env name="TEXTLOCAL_TRANSACTIONAL_KEY" value="API_KEY for transactional account"/>
<env name="TEXTLOCAL_TRANSACTIONAL_FROM" value="TXTLCL"/>
<env name="TEXTLOCAL_PROMOTIONAL_KEY" value="API_KEY for transactional account"/>
<env name="TEXTLOCAL_PROMOTIONAL_FROM" value="TXTLCL"/>
<env name="TEST_TEXTLOCAL_TRANSACTIONAL_TEMPLATE" value="Your approved template for Textlocal transactional account"/>
<env name="TEST_TEXTLOCAL_TRANSACTIONAL_MOBILE" value="Valid phone number"/>
<env name="TEST_TEXTLOCAL_TRANSACTIONAL_CC" value="Another Valid Phone number"/>
</php>
$ composer test
If you discover any security related issues, please email neerav@thinkstudeo.com instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.