This is a guide on what files you have to create/edit to implement a new driver for sending out SMS messages using this platform.
Notice · Work in progress
This guide is intended for developers who wish to implement a new carrier provider API.
This could be some combination of:
username
password
api_key
account_id
secret_token
application_id
- etc..
This will vary from API to API
Create a new migration by running the Laravel command:
php artisan make:migration add_example_fields_to_carrier --table=carriers
Implement the up()
and down()
functions to include the fields needed
to authenticate and make API calls for the API in question.
up()
:
Schema::table('carriers', function (Blueprint $table) {
$table->string('example_api_username')->nullable();
$table->text('example_api_password')->nullable();
$table->text('example_api_account_id')->nullable();
$table->text('example_api_application_id')->nullable();
});
down()
:
Schema::table('carriers', function (Blueprint $table) {
$table->dropColumn([
'example_api_username',
'example_api_password',
'example_api_account_id',
'example_api_application_id'
]);
});
Use the text field type for secrets that should be encrypted
- Copy
app/Drivers/WebhookDriver.php
toapp/Drivers/ExampleSMSDriver.php
- Rename the class name to
ExampleSMSDriver
- Re-implement the methods based on the
SMSDriver
class interface
- Copy
app/Jobs/SendWebhookSMS.php
toapp/Jobs/SendExampleSMS.php
- Rename the class name to
SendExampleSMS
- Re-implement the job-class to send the SMS using the example API.
public static array $supportedDrivers = [
'twilio' => TwilioSMSDriver::class,
'thinq' => ThinQSMSDriver::class,
'webhook' => WebhookSMSDriver::class,
'sunwire' => SunwireSMSDriver::class,
'bandwidth' => BandwidthSMSDriver::class,
+ 'example' => ExampleSMSDriver::class
];
Add the ExampleSMSDriver
to the return types of the loadDriver()
function:
- public function loadDriver(): TwilioSMSDriver|ThinQSMSDriver|WebhookSMSDriver|SunwireSMSDriver|BandwidthSMSDriver
+ public function loadDriver(): TwilioSMSDriver|ThinQSMSDriver|WebhookSMSDriver|SunwireSMSDriver|BandwidthSMSDriver|ExampleSMSDriver
This section walks through adding the UI portions of adding/managing a carrier.
Add an image (SVG/PNG) to be used for the carrier:
public/images/example-badge.svg
- Copy
resources/views/carriers/webhook-verify.blade.php
toresources/views/carriers/example-verify.blade.php
- Change the form to match the authentication values created
- Copy
resources/views/carriers/modals/forms/webhook.blade.php
toresources/views/carriers/modals/forms/example.blade.php
- Change the form to match the authentication values created
- Copy
resources/views/carriers/modals/nav/webhook.blade.php
toresources/views/carriers/modals/nav/example.blade.php
- Change the nav to customize the header shown on the UI carrier creation
Create a slug, like example
, to refer to the API driver
and correlate it to the ExampleSMSDriver::class
you copied:
Add the carriers.modals.nav.example
and carriers.modals.forms.example
views:
<ul class="nav nav-pills mb-3 nav-justified text-center" id="carriers-tab" role="tablist">
@include('carriers.modals.nav.twilio')
@include('carriers.modals.nav.thinq')
@include('carriers.modals.nav.bandwidth')
@include('carriers.modals.nav.sunwire')
@include('carriers.modals.nav.webhook')
+ @include('carriers.modals.nav.example')
</ul>
<div class="tab-content" id="pills-tabContent">
@include('carriers.modals.forms.twilio')
@include('carriers.modals.forms.thinq')
@include('carriers.modals.forms.bandwidth')
@include('carriers.modals.forms.sunwire')
@include('carriers.modals.forms.webhook')
+ @include('carriers.modals.forms.example')
</div>