hasanalyazidi / laravel-sendables
Send SMS and OTP
Package info
github.com/HasanAlyazidi/laravel-sendables
pkg:composer/hasanalyazidi/laravel-sendables
Requires
- php: >=7.1|^8.0
- adrii/whatsapp-api: ^0.7.0
- guzzlehttp/guzzle: ^7.3|^8.0
- illuminate/contracts: ^6|^7|^8|^9|^10|^11|^12|^13
- illuminate/support: ^6|^7|^8|^9|^10|^11|^12|^13
Requires (Dev)
- laravel/framework: ^6|^7|^8|^9|^10|^11|^12|^13
- orchestra/testbench: ^6|^7|^8|^9|^10|^11
- phpunit/phpunit: ^6|^7|^8|^9|^10|^11|^12
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Install
- Add package to your
composer.json
composer require hasanalyazidi/laravel-sendables
- Migrate package tables or publish migrations first then migrate
php artisan migrate
Publish package files
Publish config file (Required)
php artisan vendor:publish --provider="HasanAlyazidi\Sendables\Providers\SendablesServiceProvider" --tag="config"
Publish migrations (Optional)
php artisan vendor:publish --provider="HasanAlyazidi\Sendables\Providers\SendablesServiceProvider" --tag="migrations"
Publish language resources (Optional)
English
php artisan vendor:publish --provider="HasanAlyazidi\Sendables\Providers\SendablesServiceProvider" --tag="resources-lang-en"
Arabic
php artisan vendor:publish --provider="HasanAlyazidi\Sendables\Providers\SendablesServiceProvider" --tag="resources-lang-ar"
All supported languages
php artisan vendor:publish --provider="HasanAlyazidi\Sendables\Providers\SendablesServiceProvider" --tag="resources-lang-all"
Usage
SMS
$sms = new SMSNotification('SMS Message', '966000000000'); $sms->send();
OTP
$otp = new OtpVerifier('966000000000'); $otp->send();
- WhatsApp:
Add a message template namedotp_code, type (Authentication) with your app supported languages.
OTP limits
Codes sent by the server (WhatsApp, SMS) are limited per mobile number. Set them in
config/sendables.php under otp.limits; a provider takes its own value first, then the
default one, then OtpProvider::DEFAULT_LIMITS.
| Limit | Default | Meaning |
|---|---|---|
resendAfterSeconds |
[60, 120, 300] |
Wait after the 1st, 2nd, 3rd... code of the last hour; the last value repeats. A single number means the same wait every time. |
maxSendsPerHour |
10 |
Codes per hour per mobile number. |
maxWrongAttempts |
5 |
Wrong guesses allowed per code, then a new code is needed. |
verifiedForMinutes |
60 |
How long a verified code proves the number to isAuthenticated(). |
'limits' => [ 'default' => OtpProvider::DEFAULT_LIMITS, 'providers' => [ OurSMSV2OtpProvider::class => [ 'resendAfterSeconds' => [120, 300], 'maxSendsPerHour' => 5, ], ], ],
Tell the client when it may ask for another code, and pass it in your send response:
$otp->getResendAfter(); // seconds
A refused send returns false with the error too-many-requests, and too many wrong
guesses return too-many-attempts; both have messages in the package language files.
Limits apply to providers that send from the server, not to Firebase (the phone sends
it), testers or password logins.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email hassanx220@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.