lbhurtado / missive
Add SMS domain to a Laravel project - route, models, migrations, jobs, notifications, etc.
Requires
- php: ^7.2||^8.0.1
- eloquent/enumeration: ^6.0
- illuminate/support: ^8.0||^9.0
- laravel/legacy-factories: ^1.1
- lbhurtado/common: ^2.0
- lbhurtado/tactician: ^2.2
- opis/pattern: ^1.0
- prettus/l5-repository: ^2.6
- spatie/laravel-schemaless-attributes: ^1.4||2.*
- spomky-labs/otphp: ^10.0
Requires (Dev)
- orchestra/testbench-browser-kit: ^6.2
- phpunit/phpunit: ^9.3.3
Suggests
- lbhurtado/engagespark: This package makes it easy to send SMS notifications and topups via engageSPARK with Laravel.
README
Add SMS domain to a Laravel project - route, models, migrations, events, jobs, actions, etc.
Installation
You can install the package via composer:
composer require lbhurtado/missive
publish vendor files:
php artisan vendor:publish --provider="LBHurtado\Missive\MissiveServiceProvider"
php artisan notifications:table
php artisan migrate
optionally, if you want sms charging:
composer dumpautoload php artisan db:seed --class=AirtimeSeeder
then uncomment the middleware in missive.php
inherit models:
namespace App; use LBHurtado\EngageSpark\Traits\HasEngageSpark; use LBHurtado\Missive\Models\Contact as BaseContact; class Contact extends BaseContact { use HasEngageSpark; }
customize the tables and classes e.g. App\Contact:
[ 'table_names' => [ 'smss' => 's_m_s_s', 'contacts' => 'contacts', 'relays' => 'relays', 'topups' => 'topups', ], 'classes' => [ 'models' => [ 'airtime' => \LBHurtado\Missive\Models\Airtime::class, 'contact' => \App\Contact::class, 'relay' => \LBHurtado\Missive\Models\Relay::class, 'sms' => \LBHurtado\Missive\Models\SMS::class ], 'commands' => [ 'sms' => [ 'create' => \LBHurtado\Missive\Commands\CreateSMSCommand::class ] ], 'handlers' => [ 'sms' => [ 'create' => \LBHurtado\Missive\Handlers\CreateSMSHandler::class ] ], 'middlewares' => [ 'sms' => [ 'relay' => [ \LBHurtado\Missive\Validators\CreateSMSValidator::class, \LBHurtado\Missive\Responders\CreateSMSResponder::class, // \LBHurtado\Missive\Actions\Middleware\ChargeSMSMiddleware::class, ], 'verify' => [ \LBHurtado\Missive\Validators\CreateSMSValidator::class, \LBHurtado\Missive\Responders\CreateSMSResponder::class, \LBHurtado\Missive\Actions\Middleware\VerifyContactHandler::class, // \LBHurtado\Missive\Actions\Middleware\ChargeSMSMiddleware::class, ], 'topup' => [ \LBHurtado\Missive\Validators\CreateSMSValidator::class, \LBHurtado\Missive\Responders\CreateSMSResponder::class, \LBHurtado\Missive\Actions\Middleware\TopupMobileHandler::class, // \LBHurtado\Missive\Actions\Middleware\ChargeSMSMiddleware::class, ], ], ] ] ]
customize the routes in routes/sms.php:
use LBHurtado\EngageSpark\Notifications\Adhoc; $router = resolve('missive:router'); $router->register('LOG {message}', function (string $path, array $values) use ($router) { \Log::info($values['message']); tap($router->missive->getSMS()->origin, function ($contact) use ($values) { $message = $values['message']; $contact->notify(new Adhoc("{$contact->mobile}: $message")); }); });
Usage
use LBHurtado\Missive\Models\SMS; use LBHurtado\Missive\Jobs\CreateSMS; use LBHurtado\Missive\Repositories\SMSRepository; CreateSMS::dispatch($attributes); $sms = SMS::first(); $smss = app(SMSRepository::class); $sms = $smss->first();
use LBHurtado\Missive\Models\Contact;
use LBHurtado\Missive\Jobs\CreateContact;
use LBHurtado\Missive\Repositories\ContactRepository;
CreateContact::dispatch($mobile);
$contact = Contact::first();
$contacts = app(ContactRepository::class);
$contact = $contacts->first();
use LBHurtado\Missive\Models\Relay; use LBHurtado\Missive\Jobs\CreateRelay; use LBHurtado\Missive\Repositories\RelayRepository; CreateRelay::dispatch($mobile); $relay = Relay::first(); $relays = app(RelayRepository::class); $relay = $relays->first();
add otp verification to your contacts:
use LBHurtado\Missive\Traits\HasOTP; use LBHurtado\Missive\Models\Contact; $contact = Contact::find(1); $otp = $contact->challenge()->now(); //default period for OTP is 360 seconds //modify it in .env i.e. DEFAULT_OTP_PERIOD=1000 if ($contact->verify($otp) == true) { //code here }
sms relay
curl -X POST \ http://laravel.app/api/sms/relay \ -H 'Accept: */*' \ -H 'Cache-Control: no-cache' \ -H 'Connection: keep-alive' \ -H 'Content-Type: application/json' \ -H 'Host: laravel.app' \ -d '{ "secret": "CFAWG4KCE44XWACTZZX24Z7LPW99XTWT", "from": "+639171234567", "to": "+639187654321", "message": "LOG test message" }'
sms OTP verification
curl -X POST \ http://laravel.app/api/sms/verify \ -H 'Accept: */*' \ -H 'Cache-Control: no-cache' \ -H 'Connection: keep-alive' \ -H 'Content-Type: application/json' \ -H 'Host: laravel.app' \ -d '{ "secret": "CFAWG4KCE44XWACTZZX24Z7LPW99XTWT", "from": "+639171234567", "to": "+639187654321", "message": "123456" }'
sms topup
curl -X POST \ http://laravel.app/api/sms/topup \ -H 'Accept: */*' \ -H 'Cache-Control: no-cache' \ -H 'Connection: keep-alive' \ -H 'Content-Type: application/json' \ -H 'Host: laravel.app' \ -d '{ "secret": "CFAWG4KCE44XWACTZZX24Z7LPW99XTWT", "from": "+639171234567", "to": "+639187654321", "message": "09171234567 25" }'
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 lester@hurtado.ph instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.