Skip to content

Commit

Permalink
Newly Gateway TruboSms Added
Browse files Browse the repository at this point in the history
  • Loading branch information
arif98741 committed Feb 18, 2023
1 parent 1466756 commit 7a885e4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ $status = $sender->send();
| SmartLabSMS | user, password, sender | Done | - |
| Sslsms | api_token, sid, csms_id | Done | - |
| Tense | user, password, campaign, masking | Done | - |
| Trubosms | api_token, sender_id | Done | - |
| TwentyFourSmsBD | apiKey, sender_id | Done | - |
| Viatech | api_key, mask | Done | - |

Expand Down
6 changes: 6 additions & 0 deletions src/Config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use Xenon\LaravelBDSms\Provider\SMSNoc;
use Xenon\LaravelBDSms\Provider\Ssl;
use Xenon\LaravelBDSms\Provider\Tense;
use Xenon\LaravelBDSms\Provider\TruboSms;
use Xenon\LaravelBDSms\Provider\TwentyFourSmsBD;
use Xenon\LaravelBDSms\Provider\Viatech;

Expand Down Expand Up @@ -207,6 +208,11 @@
'campaign' => env('SMS_TENSE_CAMPAIGN', ''),
'masking' => env('SMS_TENSE_MASKING', ''),
],
TruboSms::class => [
'sender_id' => env('SMS_TRUBOSMS_SENDER_ID', ''),
'api_token' => env('SMS_TRUBOSMS_API_TOKEN', ''),
'type' => env('SMS_TRUBOSMS_TYPE', 'string'),
],
TwentyFourSmsBD::class => [
'apiKey' => env('SMS_TWENTYFOURSMSBD_APIKEY', ''),
'sender_id' => env('SMS_TWENTYFOURSMSBD_SENDER_ID', ''),
Expand Down
81 changes: 81 additions & 0 deletions src/Provider/TruboSms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/*
* Last Modified: 6/29/21, 12:06 AM
* Copyright (c) 2021
* -created by Ariful Islam
* -All Rights Preserved By
* -If you have any query then knock me at
* [email protected]
* See my profile @ https://github.com/arif98741
*/

namespace Xenon\LaravelBDSms\Provider;

use Xenon\LaravelBDSms\Handler\ParameterException;
use Xenon\LaravelBDSms\Handler\RenderException;
use Xenon\LaravelBDSms\Request;
use Xenon\LaravelBDSms\Sender;

class TruboSms extends AbstractProvider
{
/**
* Trubosms constructor.
* @param Sender $sender
*/
public function __construct(Sender $sender)
{
$this->senderObject = $sender;
}

/**
* Send Request To Api and Send Message
* @throws RenderException
*/
public function sendRequest()
{
$number = $this->senderObject->getMobile();
$text = $this->senderObject->getMessage();
$config = $this->senderObject->getConfig();
$queue = $this->senderObject->getQueue();

$query = [
'recipient' => '+88'.$number,
'sender_id' => $config['sender_id'],
'message' => $text,
];

$headers = [
'Authorization' => 'Bearer ' . $config['api_token'],
'Content-Type' => 'application/json'
];

$requestObject = new Request('https://panel.trubosms.com/api/v3/sms/send', $query, $queue);
$requestObject->setHeaders($headers)->setContentTypeJson(true);
$response = $requestObject->post();
if ($queue) {
return true;
}

$body = $response->getBody();
$smsResult = $body->getContents();

$data['number'] = $number;
$data['message'] = $text;
return $this->generateReport($smsResult, $data)->getContent();
}

/**
* @throws ParameterException
*/
public function errorException()
{
if (!array_key_exists('api_token', $this->senderObject->getConfig())) {
throw new ParameterException('api_token is absent in configuration');
}

if (!array_key_exists('sender_id', $this->senderObject->getConfig())) {
throw new ParameterException('sender_id key is absent in configuration');
}
}

}

0 comments on commit 7a885e4

Please sign in to comment.