escolalms / templates-sms
Escola Headless LMS Templates for sms
Installs: 7 127
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:package
Requires
- php: >=7.4
- escolalms/core: ^1.2.2
- escolalms/settings: >=0.1.2
- escolalms/templates: ^0
- laravel/framework: >=8.0
- twilio/sdk: ^6.42
- tzsk/sms: 6.0.0
Requires (Dev)
- escolalms/auth: ^0
- escolalms/cart: ^0
- escolalms/consultations: ^0
- escolalms/courses: ^0.4
- nunomaduro/larastan: ^2.0
- orchestra/testbench: >=5.0
- phpunit/phpunit: ^9.0
README
What does it do
Package for sms notifications with editable templates (for important user-related events). This package supports sending sms via twilio.
Installing
composer require escolalms/templates-sms
php artisan db:seed --class="EscolaLms\Templates-SMS\Database\Seeders\TemplateSmsSeeder"
Configuration
You can configure the connection to Twilio through keys in the .env
file:
TWILIO_SID
- twilio SID unique keyTWILIO_TOKEN
- twilio auth tokenTWILIO_FROM
- twilio phone numberTWILIO_SSL_VERIFY
- twilio ssl verify
You can also change the default driver in SMS_DRIVER
Example
Sending SMS
Sending an SMS using the Sms
facade
Sms::driver('twilio')->send('123456789', 'SMS message');
or
Sms::send('123456789', 'SMS message');
Custom driver
You can define your own driver for sending sms. The driver must implement the interface \EscolaLms\TemplatesSms\Drivers\Contracts\SmsDriver
.
interface SmsDriver { public function send(string $to, string $content, array $mediaUrls = [], array $params = []): bool; }
Example custom driver:
class CustomDriver implements \EscolaLms\TemplatesSms\Drivers\Contracts\SmsDriver { public function send(string $to, string $content, array $mediaUrls = [], $params = []): bool { // Implement send() method. } }
Register a new driver, we would do the following:
Sms::extend('custom', function($app) { return new CustomDriver($app); });
Tests
Run ./vendor/bin/phpunit
to run tests. See tests folder as it's quite good staring point as documentation appendix.
This package has a facade for testing. The Sms facade's fake method allows you to easily a fake sms driver.
public function testSms() { Sms::fake(); ... $service->sendSms($phone1); ... Sms::assertSent($phone1); Sms::assertNotSent($phone2); }
public function testSms() { Sms::fake(); ... Sms::assertSent($phone1, fn($sms) => $sms->content === 'Sms message'); }