msonowal / laravel-notification-channel-textlocal
Textlocal Notifications Channel for Laravel
Installs: 18 763
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 188
Open Issues: 0
Requires
- php: >=7.0
- ext-json: *
- illuminate/notifications: ~5.5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0
- illuminate/support: ~5.5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0
Requires (Dev)
- mockery/mockery: ^0.9.5|^1.0
- phpunit/phpunit: ~5|^8.0|^9.0|^10.0|~11.0
This package is auto-updated.
Last update: 2024-11-11 10:00:12 UTC
README
This package allows to send SMS using Textlocal API using laravel notifications channel textlocal sms
Supports Laravel 5.5 upto 10.x
This package makes it easy to send notifications using textlocal with Laravel 5.3.+
To use version ^2.3.0 onwards will require PHP 8.0
for other PHP version use upto ^2.2.0
Contents
Installation
Create an account in textlocal then create an API key or hash(password).
composer require msonowal/laravel-notification-channel-textlocal
Setting up the textlocal service
default config textlocal.php
update where desired
Important Either specify a Key OR a Hash - don't enter both!
return [
'username' => env('TEXTLOCAL_USERNAME'),
'password' => env('TEXTLOCAL_PASSWORD'),
'hash' => env('TEXTLOCAL_HASH'), //optional if api_key is set
'api_key' => env('TEXTLOCAL_API_KEY'), //optional if hash is set
'sender' => env('TEXTLOCAL_SENDER'),
'request_urls' => [
'IN' => 'https://api.textlocal.in/',
'UK' => 'https://api.txtlocal.com/'
],
'country' => env('TEXTLOCAL_COUNTRY', 'IN'),
'extra' => [
// extra config define keys as desired for use within the textlocal client config
// if you want to use the custom client config for each notification or notifiable
// INotificationUsesTextlocalClientConfig
]public function getSenderId($notifiable)
### Configuring .env
TEXTLOCAL_USERNAME=Your email id or api key
TEXTLOCAL_HASH=get it from url '/docs/' under your API KEYS section
TEXTLOCAL_API_KEY get it from url '/docs/' under your API KEYS section
TEXTLOCAL_SENDER=Name of the Sender that will be displayed to the recipient (max 6 Characters).
TEXTLOCAL_COUNTRY=Your Two letter(ISO-3166-alpha-2) Country Code. It should be the Country of the TEXTLOCAL account. defaults to IN
### Publish Config
php artisan vendor:publish --tag=textlocal
Currently, only textlocal of two country is supported IN(India) and UK(United Kingdom).
## Usage
Implement this method `routeNotificationForTextlocal()` in your notifiable class/model which will return array of mobile numbers. Please make sure the mobile number contains the dial code as well (e.g +91 for India). And lastly implement `toSms()` method in the notification class which will return the (string) sms or template that is defined in textlocal account that needs to be send.
## Usage
You can use the channel in your `via()` method inside the notification:
```php
use Illuminate\Notifications\Notification;
use NotificationChannels\Textlocal\TextlocalChannel;
class TestOTPNotification extends Notification
{
public function via($notifiable)
{
return [TextlocalChannel::class];
}
public function toSms($notifiable)
{
return 'Use 1234 as OTP for resetting your password.';
}
}
In your notifiable model, make sure to include a routeNotificationForTextlocal()
method, which returns a phone number or multiple numbers in array
or an array of phone numbers.
public function routeNotificationForTextlocal(): array { return [$this->mobile_no]; }
Annoynmous Notifable when say mobile no is not added to a notifiable model you can directly send to mobile no by using that
Notification::route('Textlocal', $mobileNo')->notify(new VerifyMobileNotification($otp));
Available Message methods
And if you want to have a specific sender based on Notification, e.g. like you are sending promotional notification using one and another for transaction then you can just define this method in your notification class which will return your sender id for that notification only
public function getSenderId($notifiable)
{
return 'YOUR_SENDER_ID';
}
Unicode support If you want to send the notification content to have unicode support. Define this method in your notification which will return boolean based on which the sms will set the unicode mode in textlocal API
public function getUnicodeMode()
{
return true;
}
A list of all available options
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email manash149@gmail.com instead of using the issue tracker.
Found any bugs or improvement open an issue or send me a PR
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
TODO
Need to convert to Guzzle Http as a Client in core Add more countries add tests