Skip to content

Commit

Permalink
sms api added
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Apr 9, 2024
1 parent 3cb03dc commit 0d387b7
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 20 deletions.
11 changes: 10 additions & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Please follow this steps and you are live with in a mere seconds.
Depending on driver option you choose, add these API credentials
after existing general configuration variables.

### Global SMS API Providers

| Driver | Credentials | Region | Configured | Tested |
|-------------------|-------------------------------------------------------------------------|:------:|:------------------:|:------:|
| `africastalking` | `SMS_AFRICA_TALKING_API_KEY=null`<br>`SMS_AFRICA_TALKING_USERNAME=null` | GLOBAL | :white_check_mark: | :x: |
Expand All @@ -34,7 +36,14 @@ after existing general configuration variables.
| `smsbroadcast` | `SMS_SMSBROADCAST_USERNAME=null`<br>`SMS_SMSBROADCAST_PASSWORD=null` | GLOBAL | :white_check_mark: | :x: |
| `telnyx` | `SMS_TELNYX_API_TOKEN=null` | GLOBAL | :white_check_mark: | :x: |
| `twilio` | `SMS_TWILIO_USERNAME=null`<br>`SMS_TWILIO_PASSWORD=null` | GLOBAL | :white_check_mark: | :x: |
| `adn` | `SMS_TWILIO_USERNAME=null`<br>`SMS_TWILIO_PASSWORD=null` | BAN | :x: | :x: |
| `smsapi` | `SMS_SMSAPI_API_TOKEN=null` | GLOBAL | :white_check_mark: | :x: |


### Bangladesh only SMS API Providers

| Driver | Credentials | Region | Configured | Tested |
|-------------------|-------------------------------------------------------------------------|:------:|:------------------:|:------:|
| `adn` | `SMS_ADN_API_KEY=null`<br>`SMS_ADN_API_SECRET=null` | BAN | :white_check_mark: | :x: |
| `ajuratech` | `SMS_TWILIO_USERNAME=null`<br>`SMS_TWILIO_PASSWORD=null` | BAN | :x: | :x: |
| `alpha` | `SMS_TWILIO_USERNAME=null`<br>`SMS_TWILIO_PASSWORD=null` | BAN | :x: | :x: |
| `banglalink` | `SMS_TWILIO_USERNAME=null`<br>`SMS_TWILIO_PASSWORD=null` | BAN | :x: | :x: |
Expand Down
19 changes: 11 additions & 8 deletions config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,25 @@
'password' => env('SMS_TWILIO_PASSWORD'),
],
],
Providers::SMS_API => [
'driver' => \Laraflow\Sms\Drivers\SmsApi::class,
'live' => [
'api_token' => env('SMS_SMSAPI_API_TOKEN', ''),
],
'sandbox' => [
'api_token' => env('SMS_SMSAPI_API_TOKEN', ''),
],
],
//Bangladesh
Providers::ADN => [
'driver' => \Laraflow\Sms\Drivers\Adn::class,
'live' => [
'senderid' => env('SMS_ADN_SENDER_ID', ''),
'api_key' => env('SMS_ADN_API_KEY', ''),
'api_secret' => env('SMS_ADN_API_SECRET', ''),
'request_type' => env('SMS_ADN_API_REQUEST_TYPE', ''),
'message_type' => env('SMS_ADN_API_MESSAGE_TYPE', ''),
'api_secret' => env('SMS_ADN_API_SECRET', '')
],
'sandbox' => [
'senderid' => env('SMS_ADN_SENDER_ID', ''),
'api_key' => env('SMS_ADN_API_KEY', ''),
'api_secret' => env('SMS_ADN_API_SECRET', ''),
'request_type' => env('SMS_ADN_API_REQUEST_TYPE', ''),
'message_type' => env('SMS_ADN_API_MESSAGE_TYPE', ''),
'api_secret' => env('SMS_ADN_API_SECRET', '')
]
],
Providers::AJURA_TECH => [
Expand Down
24 changes: 13 additions & 11 deletions src/Drivers/Adn.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Laraflow\Sms\SmsMessage;

/**
* @reference
* @reference https://portal.adnsms.com/client/api/documentation
*/
class Adn extends SmsDriver
{
Expand All @@ -22,6 +22,8 @@ protected function mergeConfig(): array
{
return [
'url' => 'https://portal.adnsms.com/api/v1/secure/send-sms',
'request_type' => 'SINGLE_SMS',
'message_type' => 'UNICODE'
];
}

Expand All @@ -34,8 +36,8 @@ public function rules(): array
{
return [
'url' => 'required|url:http,https',
'apiKey' => 'required|string',
'username' => 'required|string',
'api_key' => 'required|string',
'api_secret' => 'required|string'
];
}

Expand All @@ -48,20 +50,20 @@ public function rules(): array
public function send(SmsMessage $message): Response
{
$this->payload = [
'username' => $this->config['username'],
'to' => $message->getReceiver(),
'from' => $message->getSender(),
'message' => $message->getContent(),
'api_key' => $this->config['api_key'],
'api_secret' => $this->config['api_secret'],
'request_type' => $this->config['request_type'],
'message_type' => $this->config['message_type'],
'mobile' => $message->getReceiver(),
'message_body' => $message->getContent(),
];

$this->removeEmptyParams();

return Http::withoutVerifying()
->timeout(30)
->withHeader('Content-Type', 'application/json')
->withHeader('Accept', 'application/json')
->withHeader('apiKey', $this->config['apiKey'])
->get($this->config['url'], $this->payload);
->withHeaders(['Content-Type'=>'application/json','Accept'=>'application/json'])
->post($this->config['url'], $this->payload);

}
}
66 changes: 66 additions & 0 deletions src/Drivers/SmsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Laraflow\Sms\Drivers;

use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Laraflow\Sms\Contracts\SmsDriver;
use Laraflow\Sms\SmsMessage;

/**
* @reference https://www.smsapi.com/docs/#2-single-sms
*/
class SmsApi extends SmsDriver
{
/**
* this function allow programmer to append more config
* that may or may be needed in the configuration file
*
* @return string[]
*/
protected function mergeConfig(): array
{
return [
'url' => 'https://api.smsapi.com/sms.do',
'format' =>'json'
];
}

/**
* Return validation rules for
* that sms driver to operate.
*/
public function rules(): array
{
return [
'url' => 'required|url:http,https',
'api_token' => 'required|string'
];
}

/**
* Execute the sms sending request to api provider
*
* @param SmsMessage $message
* @return Response
*/
public function send(SmsMessage $message): Response
{
$this->payload = [
'to' => $message->getReceiver(),
'from' => $message->getSender(),
'message' => $message->getContent(),
'format' => $this->config['format']
];

$this->removeEmptyParams();

return Http::withoutVerifying()
->timeout(30)
->withToken($this->config['api_token'])
->withHeader('Content-Type', 'application/json')
->withHeader('Accept', 'application/json')
->post($this->config['url'], $this->payload);

}
}
1 change: 1 addition & 0 deletions src/Providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Providers
public const SMSINBD = 'smsinbd';
public const SMSNETBD = 'smsnetbd';
public const SMSQ = 'smsq';
public const SMS_API = 'smsapi';
public const SSL = 'ssl';
public const TENSE = 'tense';
public const TRUBO_SMS = 'trubosms';
Expand Down

0 comments on commit 0d387b7

Please sign in to comment.