Skip to content

Commit bc6b438

Browse files
Update docs
2 parents d11c106 + 2d63179 commit bc6b438

16 files changed

+534
-109
lines changed

docs/.vitepress/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import shofySidebar from '../shofy/sidebar'
1919
import athenaSidebar from '../athena/sidebar'
2020
import cloudifySidebar from '../cloudify/sidebar'
2121
import homzenSidebar from '../homzen/sidebar'
22+
import smsGatewaySidebar from '../sms-gateway/sidebar'
2223

2324
export default defineConfig({
2425
title: 'Botble Documentation',
@@ -83,6 +84,7 @@ export default defineConfig({
8384
{ text: 'Athena', link: '/athena/'},
8485
{ text: 'Cloudify', link: '/cloudify/'},
8586
{ text: 'Homzen', link: '/homzen/'},
87+
{ text: 'SMS Gateway', link: '/sms-gateway/'},
8688
],
8789
},
8890
{ text: 'Support', link: 'https://botble.ticksy.com' },
@@ -114,6 +116,7 @@ export default defineConfig({
114116
athena: athenaSidebar,
115117
cloudify: cloudifySidebar,
116118
homzen: homzenSidebar,
119+
'sms-gateway': smsGatewaySidebar,
117120
},
118121

119122
socialLinks: [{ icon: 'github', link: 'https://github.com/botble' }],

docs/sms-gateway/extending.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Extending the Plugin
2+
3+
The SMS Gateway plugin for Botble CMS allows you to extend its functionality by adding custom SMS drivers. This guide explains how to create a custom SMS driver by extending the plugin with your own implementation, including setting up a configuration form.
4+
5+
## Overview
6+
7+
To extend the SMS Gateway plugin, you'll need to:
8+
9+
1. **Create a New Driver Class**: Extend the `AbstractDriver` class to define your custom SMS provider.
10+
2. **Implement Required Methods**: Implement the abstract methods and provide additional configuration and functionality.
11+
3. **Create a Configuration Form**: Define a form for configuring the SMS provider settings.
12+
4. **Register Your Custom Driver**: Integrate your custom driver with the SMS Gateway plugin.
13+
14+
## Creating a Custom SMS Driver
15+
16+
### Step 1: Define Your Driver Class
17+
18+
Create a new PHP class that extends the `AbstractDriver` class. This class will implement the specific functionality for your SMS provider.
19+
20+
```php
21+
<?php
22+
23+
namespace FriendsOfBotble\Sms\Drivers;
24+
25+
use Botble\Base\Forms\FormAbstract;
26+
use FriendsOfBotble\Sms\DataTransferObjects\SmsResponse;
27+
use FriendsOfBotble\Sms\Facades\Sms as SmsFacade;
28+
use FriendsOfBotble\Sms\Forms\NexmoGatewayForm;
29+
use Vonage\Client;
30+
use Vonage\Client\Credentials\Basic;
31+
use Vonage\SMS\Message\SMS;
32+
33+
class Nexmo extends AbstractDriver
34+
{
35+
protected Client $client;
36+
37+
public function __construct()
38+
{
39+
$key = SmsFacade::getSetting('key', 'nexmo');
40+
$secret = SmsFacade::getSetting('secret', 'nexmo');
41+
42+
if (empty($key) || empty($secret)) {
43+
return;
44+
}
45+
46+
$this->client = new Client(new Basic($key, $secret));
47+
}
48+
49+
protected function performSend(string $to, string $message): SmsResponse
50+
{
51+
$response = $this->client->sms()->send(
52+
new SMS($to, $this->getFrom(), $message)
53+
);
54+
55+
$message = $response->current();
56+
57+
return new SmsResponse(
58+
success: $message->getStatus() === 0,
59+
messageId: $message->getMessageId(),
60+
response: $response->getAllMessagesRaw(),
61+
);
62+
}
63+
64+
public function getLogo(): string
65+
{
66+
return asset('vendor/core/plugins/sms/images/nexmo.png');
67+
}
68+
69+
public function getInstructions(): string
70+
{
71+
return view('plugins/sms::instructions.nexmo');
72+
}
73+
74+
public function getSettingForm(): FormAbstract
75+
{
76+
return NexmoGatewayForm::create();
77+
}
78+
}
79+
```
80+
81+
### Step 2: Implement Required Methods
82+
83+
- **`performSend(string $to, string $message): SmsResponse`**: Implement the logic for sending an SMS message. This method should interact with the SMS provider’s API and return an `SmsResponse` object.
84+
- **`getLogo(): string`**: Provide the URL to the logo image of your SMS provider. This image will be used in the plugin’s UI.
85+
- **`getInstructions(): string`**: Return a view or string with instructions for configuring the SMS provider.
86+
- **`getSettingForm(): FormAbstract`**: Return a form for configuring the SMS provider settings.
87+
88+
### Step 3: Create a Configuration Form
89+
90+
Define a form for configuring the settings of your SMS provider. This form will be used in the admin panel to set up the provider.
91+
92+
#### Example: Nexmo Gateway Form
93+
94+
```php
95+
<?php
96+
97+
namespace FriendsOfBotble\Sms\Forms;
98+
99+
use Botble\Base\Facades\Html;
100+
use Botble\Base\Forms\FieldOptions\TextFieldOption;
101+
use Botble\Base\Forms\Fields\TextField;
102+
103+
class NexmoGatewayForm extends SmsGatewayForm
104+
{
105+
protected array $sensitiveFields = [
106+
'key',
107+
'secret',
108+
];
109+
110+
public function setup(): void
111+
{
112+
parent::setup();
113+
114+
$this
115+
->add(
116+
'key',
117+
TextField::class,
118+
TextFieldOption::make()
119+
->label(trans('plugins/sms::nexmo.key'))
120+
->required()
121+
)
122+
->add(
123+
'secret',
124+
TextField::class,
125+
TextFieldOption::make()
126+
->label(trans('plugins/sms::nexmo.secret'))
127+
->required()
128+
)
129+
->add(
130+
'from',
131+
TextField::class,
132+
TextFieldOption::make()
133+
->label(trans('plugins/sms::nexmo.from'))
134+
->helperText(trans('plugins/sms::nexmo.from_help', [
135+
'link' => Html::link(
136+
'https://developer.vonage.com/en/messaging/sms/guides/custom-sender-id?source=messaging',
137+
trans('plugins/sms::nexmo.here'),
138+
['target' => '_blank']
139+
),
140+
]))
141+
->required()
142+
);
143+
}
144+
}
145+
```
146+
147+
- **`$sensitiveFields`**: Define sensitive fields that should be protected or masked.
148+
- **`setup()`**: Configure the form fields, including labels, helper text, and validation requirements.
149+
150+
### Step 4: Register Your Custom Driver
151+
152+
To integrate your custom driver with the SMS Gateway plugin, register it in your plugin's service provider.
153+
154+
```php
155+
// In your plugin’s service provider
156+
public function boot()
157+
{
158+
Sms::extend('nexmo', Nexmo::class);
159+
}
160+
```
161+
162+
## Example Usage
163+
164+
Once your custom driver is registered, you can use it as follows:
165+
166+
```php
167+
// Sending an SMS message
168+
Sms::driver('nexmo')->send('+11234567890', 'Your OTP code is: 123456');
169+
```
170+
171+
## Troubleshooting
172+
173+
- **Check Logs**: Review the SMS logs to ensure messages are sent correctly and diagnose any issues.
174+
- **Verify Configuration**: Ensure that your API credentials and settings are correctly configured in the admin panel.
175+
- **Consult Documentation**: Refer to the documentation of your SMS provider for details on API usage and error codes.
Loading

docs/sms-gateway/images/nexmo.png

27.7 KB
Loading
Loading
72.9 KB
Loading
Loading

docs/sms-gateway/images/twilio.png

40.1 KB
Loading

docs/sms-gateway/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SMS Gateway Plugin
2+
3+
The SMS Gateway Plugin for Botble CMS integrates with popular SMS services to send SMS messages directly to your users. This plugin is versatile and supports both Twilio and Nexmo services, providing you with a reliable way to reach your customers.
4+
5+
## Features
6+
7+
- **Twilio & Nexmo Support**: Easily configure and use Twilio or Nexmo to send SMS messages.
8+
- **Phone Number Verification**: Verify your customer's phone numbers to ensure accurate delivery.
9+
- **Extendable**: The plugin is designed to be extendable. You can add custom SMS service providers by extending the SMS service.

docs/sms-gateway/installation.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Installation
2+
3+
Follow these steps to install the SMS Gateway Plugin for Botble CMS:
4+
5+
### Download the Plugin
6+
7+
* Purchase and download the plugin package from CodeCanyon.
8+
* Extract the downloaded zip file to your local machine.
9+
10+
### Upload the Plugin
11+
12+
* Connect to your web server using FTP, SFTP, or your preferred method.
13+
* Navigate to the `/platform/plugins` directory of your Botble CMS installation.
14+
* Upload the extracted plugin folder to the `/platform/plugins` directory.
15+
16+
### Activate the Plugin
17+
18+
* Log in to your Botble CMS admin panel.
19+
* Go to **Plugins** in the sidebar menu.
20+
* Find the **SMS Gateway** plugin in the list and click the **Activate** button.
21+
22+
### Configure the Plugin
23+
24+
Once activated, navigate to **SMS Gateway** in the sidebar menu to configure the plugin.
25+
Choose your preferred SMS service (Twilio or Nexmo) and enter the necessary credentials:
26+
27+
* **Twilio**: Account SID, Auth Token, and From Number.
28+
* **Nexmo**: API Key, API Secret, and From Number.
29+
30+
Save the settings.

0 commit comments

Comments
 (0)