Skip to content

Commit 10f84cf

Browse files
committed
feat: add 10 new SMS gateway drivers
1 parent b6a2003 commit 10f84cf

19 files changed

+1143
-0
lines changed

config/kotha.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,56 @@
2626
'api_key' => env('KOTHA_MIMSMS_API_KEY'),
2727
'sender_id' => env('KOTHA_MIMSMS_SENDER_ID'),
2828
],
29+
'ssl' => [
30+
'api_token' => env('KOTHA_SSL_TOKEN'),
31+
'sender_id' => env('KOTHA_SSL_SENDER_ID'),
32+
'csms_id' => env('KOTHA_SSL_CSMS_ID'),
33+
],
34+
'grameenphone' => [
35+
'username' => env('KOTHA_GP_USERNAME'),
36+
'password' => env('KOTHA_GP_PASSWORD'),
37+
'cli' => env('KOTHA_GP_CLI', '2222'),
38+
'message_type' => env('KOTHA_GP_MESSAGE_TYPE', 1),
39+
],
40+
'banglalink' => [
41+
'user_id' => env('KOTHA_BL_USER_ID'),
42+
'password' => env('KOTHA_BL_PASSWORD'),
43+
'sender_id' => env('KOTHA_BL_SENDER_ID'),
44+
],
45+
'robi' => [
46+
'username' => env('KOTHA_ROBI_USERNAME'),
47+
'password' => env('KOTHA_ROBI_PASSWORD'),
48+
],
49+
'infobip' => [
50+
'base_url' => env('KOTHA_INFOBIP_BASE_URL'),
51+
'username' => env('KOTHA_INFOBIP_USERNAME'),
52+
'password' => env('KOTHA_INFOBIP_PASSWORD'),
53+
'sender_id' => env('KOTHA_INFOBIP_SENDER_ID'),
54+
],
55+
'adnsms' => [
56+
'api_key' => env('KOTHA_ADNSMS_API_KEY'),
57+
'api_secret' => env('KOTHA_ADNSMS_API_SECRET'),
58+
'sender_id' => env('KOTHA_ADNSMS_SENDER_ID'),
59+
'request_type' => env('KOTHA_ADNSMS_REQUEST_TYPE', 'SINGLE_SMS'),
60+
'message_type' => env('KOTHA_ADNSMS_MESSAGE_TYPE', 'TEXT'),
61+
],
62+
'alphasms' => [
63+
'api_key' => env('KOTHA_ALPHASMS_API_KEY'),
64+
'sender_id' => env('KOTHA_ALPHASMS_SENDER_ID'),
65+
],
66+
'greenweb' => [
67+
'token' => env('KOTHA_GREENWEB_TOKEN'),
68+
],
69+
'bulksms' => [
70+
'api_key' => env('KOTHA_BULKSMS_API_KEY'),
71+
'sender_id' => env('KOTHA_BULKSMS_SENDER_ID'),
72+
],
73+
'elitbuzz' => [
74+
'url' => env('KOTHA_ELITBUZZ_URL'),
75+
'api_key' => env('KOTHA_ELITBUZZ_API_KEY'),
76+
'sender_id' => env('KOTHA_ELITBUZZ_SENDER_ID'),
77+
'type' => env('KOTHA_ELITBUZZ_TYPE', 'text'),
78+
],
2979
],
3080

3181
/*

src/Drivers/AdnsmsDriver.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Larament\Kotha\Drivers;
6+
7+
use Illuminate\Support\Facades\Http;
8+
use Larament\Kotha\Data\ResponseData;
9+
use Larament\Kotha\Exceptions\KothaException;
10+
11+
final class AdnsmsDriver extends AbstractDriver
12+
{
13+
private string $baseUrl = 'https://portal.adnsms.com/api/v1/secure';
14+
15+
public function send(): ResponseData
16+
{
17+
$this->validate();
18+
19+
$response = Http::baseUrl($this->baseUrl)
20+
->timeout($this->timeout)
21+
->retry($this->retry, $this->retryDelay, throw: false)
22+
->acceptJson()
23+
->asForm()
24+
->post('/send-sms', [
25+
'api_key' => $this->config['api_key'],
26+
'api_secret' => $this->config['api_secret'],
27+
'request_type' => $this->config['request_type'] ?? 'SINGLE_SMS',
28+
'message_type' => $this->config['message_type'] ?? 'TEXT',
29+
'senderid' => $this->config['sender_id'] ?? null,
30+
'mobile' => implode(',', $this->recipients),
31+
'message_body' => $this->message,
32+
])
33+
->json();
34+
35+
if (($response['api_response_code'] ?? 0) !== 200) {
36+
throw new KothaException($response['api_response_message'] ?? 'ADN SMS API error');
37+
}
38+
39+
return new ResponseData(
40+
success: true,
41+
data: $response,
42+
);
43+
}
44+
45+
protected function validate(): void
46+
{
47+
parent::validate();
48+
49+
if (empty($this->config['api_key'])) {
50+
throw new KothaException('Please set api_key for ADN in config/kotha.php.');
51+
}
52+
53+
if (empty($this->config['api_secret'])) {
54+
throw new KothaException('Please set api_secret for ADN in config/kotha.php.');
55+
}
56+
}
57+
}

src/Drivers/AlphasmsDriver.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Larament\Kotha\Drivers;
6+
7+
use Illuminate\Support\Facades\Http;
8+
use Larament\Kotha\Data\ResponseData;
9+
use Larament\Kotha\Exceptions\KothaException;
10+
11+
final class AlphasmsDriver extends AbstractDriver
12+
{
13+
private string $baseUrl = 'https://api.sms.net.bd';
14+
15+
public function send(): ResponseData
16+
{
17+
$this->validate();
18+
19+
$params = [
20+
'api_key' => $this->config['api_key'],
21+
'msg' => $this->message,
22+
'to' => implode(',', $this->recipients),
23+
];
24+
25+
if (! empty($this->config['sender_id'])) {
26+
$params['sender_id'] = $this->config['sender_id'];
27+
}
28+
29+
if (! empty($this->config['schedule'])) {
30+
$params['schedule'] = $this->config['schedule'];
31+
}
32+
33+
$response = Http::baseUrl($this->baseUrl)
34+
->timeout($this->timeout)
35+
->retry($this->retry, $this->retryDelay)
36+
->acceptJson()
37+
->post('/sendsms', $params)
38+
->json();
39+
40+
if (($response['error'] ?? 0) !== 0) {
41+
throw new KothaException($response['msg'] ?? 'Alpha SMS API error');
42+
}
43+
44+
return new ResponseData(
45+
success: ($response['error'] ?? 1) === 0,
46+
data: $response,
47+
);
48+
}
49+
50+
protected function validate(): void
51+
{
52+
parent::validate();
53+
54+
if (empty($this->config['api_key'])) {
55+
throw new KothaException('Please set api_key for Alpha in config/kotha.php.');
56+
}
57+
}
58+
}

src/Drivers/BanglalinkDriver.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Larament\Kotha\Drivers;
6+
7+
use Illuminate\Support\Facades\Http;
8+
use Larament\Kotha\Data\ResponseData;
9+
use Larament\Kotha\Exceptions\KothaException;
10+
11+
final class BanglalinkDriver extends AbstractDriver
12+
{
13+
private string $baseUrl = 'https://vas.banglalink.net/sendSMS';
14+
15+
public function send(): ResponseData
16+
{
17+
$this->validate();
18+
19+
$response = Http::baseUrl($this->baseUrl)
20+
->timeout($this->timeout)
21+
->retry($this->retry, $this->retryDelay)
22+
->asForm()
23+
->post('/sendSMS', [
24+
'userID' => $this->config['user_id'],
25+
'passwd' => $this->config['password'],
26+
'sender' => $this->config['sender_id'],
27+
'msisdn' => implode(',', $this->recipients),
28+
'message' => $this->message,
29+
]);
30+
31+
$body = $response->body();
32+
33+
// Banglalink returns XML/text response
34+
if (str_contains(mb_strtolower($body), 'error') || str_contains(mb_strtolower($body), 'fail')) {
35+
throw new KothaException($body ?: 'Banglalink API error');
36+
}
37+
38+
return new ResponseData(
39+
success: true,
40+
data: ['response' => $body],
41+
);
42+
}
43+
44+
protected function validate(): void
45+
{
46+
parent::validate();
47+
48+
if (empty($this->config['user_id'])) {
49+
throw new KothaException('Please set user_id for Banglalink in config/kotha.php.');
50+
}
51+
52+
if (empty($this->config['password'])) {
53+
throw new KothaException('Please set password for Banglalink in config/kotha.php.');
54+
}
55+
56+
if (empty($this->config['sender_id'])) {
57+
throw new KothaException('Please set sender_id for Banglalink in config/kotha.php.');
58+
}
59+
}
60+
}

src/Drivers/BulksmsDriver.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Larament\Kotha\Drivers;
6+
7+
use Illuminate\Support\Facades\Http;
8+
use Larament\Kotha\Data\ResponseData;
9+
use Larament\Kotha\Exceptions\KothaException;
10+
11+
final class BulksmsDriver extends AbstractDriver
12+
{
13+
private string $baseUrl = 'https://bulksmsbd.net/api';
14+
15+
public function send(): ResponseData
16+
{
17+
$this->validate();
18+
19+
$response = Http::baseUrl($this->baseUrl)
20+
->timeout($this->timeout)
21+
->retry($this->retry, $this->retryDelay)
22+
->get('/smsapi', [
23+
'api_key' => $this->config['api_key'],
24+
'senderid' => $this->config['sender_id'],
25+
'type' => 'text',
26+
'number' => implode(',', $this->recipients),
27+
'message' => $this->message,
28+
])
29+
->json();
30+
31+
if (($response['response_code'] ?? 0) !== 202) {
32+
throw new KothaException($response['error_message'] ?? 'BulkSMS BD API error');
33+
}
34+
35+
return new ResponseData(success: true, data: $response);
36+
}
37+
38+
protected function validate(): void
39+
{
40+
parent::validate();
41+
42+
if (empty($this->config['api_key'])) {
43+
throw new KothaException('Please set api_key for BulkSMS in config/kotha.php.');
44+
}
45+
if (empty($this->config['sender_id'])) {
46+
throw new KothaException('Please set sender_id for BulkSMS in config/kotha.php.');
47+
}
48+
}
49+
}

src/Drivers/ElitbuzzDriver.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Larament\Kotha\Drivers;
6+
7+
use Illuminate\Support\Facades\Http;
8+
use Larament\Kotha\Data\ResponseData;
9+
use Larament\Kotha\Exceptions\KothaException;
10+
11+
final class ElitbuzzDriver extends AbstractDriver
12+
{
13+
public function send(): ResponseData
14+
{
15+
$this->validate();
16+
17+
$response = Http::timeout($this->timeout)
18+
->retry($this->retry, $this->retryDelay)
19+
->asForm()
20+
->post($this->config['url'].'/smsapi', [
21+
'api_key' => $this->config['api_key'],
22+
'type' => $this->config['type'] ?? 'text',
23+
'senderid' => $this->config['sender_id'],
24+
'contacts' => implode(',', $this->recipients),
25+
'msg' => $this->message,
26+
]);
27+
28+
$body = $response->body();
29+
30+
if (str_contains(mb_strtolower($body), 'error') || str_contains(mb_strtolower($body), 'fail')) {
31+
throw new KothaException($body ?: 'ElitBuzz API error');
32+
}
33+
34+
return new ResponseData(
35+
success: true,
36+
data: ['response' => $body],
37+
);
38+
}
39+
40+
protected function validate(): void
41+
{
42+
parent::validate();
43+
44+
if (empty($this->config['url'])) {
45+
throw new KothaException('Please set url for ElitBuzz in config/kotha.php.');
46+
}
47+
48+
if (empty($this->config['api_key'])) {
49+
throw new KothaException('Please set api_key for ElitBuzz in config/kotha.php.');
50+
}
51+
52+
if (empty($this->config['sender_id'])) {
53+
throw new KothaException('Please set sender_id for ElitBuzz in config/kotha.php.');
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)