Skip to content

Commit

Permalink
added isDebug mode, so can have option to enable it and send to parti…
Browse files Browse the repository at this point in the history
…cular testing number
  • Loading branch information
shiroamada committed May 14, 2022
1 parent d1d2f2c commit ebbf82c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ Add your ultrasms instanceId and token to your `config/services.php`:
// config/services.php
...
'ultrasms' => [
'instanceId' => env('ULTRASMS_INSTANCEID'),
'token' => env('ULTRASMS_TOKEN'),
'instanceId' => env('ULTRASMS_INSTANCEID'),
'token' => env('ULTRASMS_TOKEN'),
'isDebug' => env('ULTRASMS_DEBUG_ENABLE') ?? 0,
'debugReceiveNumber' => env('ULTRASMS_DEBUG_RECEIVE_NUMBER'),
],
...
```
Expand Down
11 changes: 11 additions & 0 deletions src/UltraSmsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class UltraSmsApi
/** @var string */
protected $token;

/** @var integer */
public $isDebug;

/** @var string */
public $debugReceiveNumber;


/** @var string */
protected $action = '/messages/chat';

Expand All @@ -34,6 +41,10 @@ public function __construct($config)
$this->instanceId = $config['instanceId'];
$this->token = $config['token'];

$this->isDebug = $config['isDebug'];
$this->debugReceiveNumber = $config['debugReceiveNumber'];


$this->httpClient = new HttpClient([
'base_uri' => $this->apiUrl.$this->instanceId.$this->action,
'timeout' => 2.0,
Expand Down
25 changes: 18 additions & 7 deletions src/UltraSmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,31 @@ protected function sendMessage($recipient, UltraSmsMessage $message)
$message->content = html_entity_decode($message->content, ENT_QUOTES, 'utf-8');
$message->content = urlencode($message->content);

//the sms format must start with 6
//the sms format must start with 6 (for malaysia)
$valid_mobile = '';

if ($recipient[0] == '6') {
$valid_mobile = '+'.$recipient;
//debug mode is to avoid send whatsapp to your real customer
if ($this->ultrasms->isDebug)
{
$valid_mobile = $this->ultrasms->debugReceiveNumber;
}

if ($recipient[0] == '0') {
$valid_mobile = '+6'.$recipient;
else
{
//this is for malaysia number use case, other country kindly fork your version
if ($recipient[0] == '6')
{
$valid_mobile = '+' . $recipient;
}

if ($recipient[0] == '0')
{
$valid_mobile = '+6' . $recipient;
}
}

$params = [
'to' => $valid_mobile,
'body' => $message->content,
'mesg' => $message->content,
];

if ($message->sendAt instanceof \DateTimeInterface) {
Expand Down

0 comments on commit ebbf82c

Please sign in to comment.