Skip to content

Commit 44abcf3

Browse files
committed
Move encoding type from client to message
1 parent 2528cb7 commit 44abcf3

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,11 @@ Add your CMSMS Product Token and default originator (name or number of sender) t
5757
'cmsms' => [
5858
'product_token' => env('CMSMS_PRODUCT_TOKEN'),
5959
'originator' => env('CMSMS_ORIGINATOR'),
60-
'encoding_detection_type' => env('CMSMS_ENCODING_DETECTION_TYPE', 'AUTO'),
6160
],
6261
...
6362
```
6463

65-
Notice:
66-
- The originator can contain a maximum of 11 alphanumeric characters.
67-
- Read about encoding detection here: https://developers.cm.com/messaging/docs/sms#auto-detect-encoding
64+
Notice: The originator can contain a maximum of 11 alphanumeric characters.
6865

6966
## Usage
7067

@@ -105,6 +102,7 @@ public function routeNotificationForCmsms()
105102
- `body('')`: Accepts a string value for the message body.
106103
- `originator('')`: Accepts a string value between 1 and 11 characters, used as the message sender name.
107104
- `reference('')`: Accepts a string value for your message reference. This information will be returned in a status report so you can match the message and it's status. Restrictions: 1 - 32 alphanumeric characters. Reference will not work for demo accounts.
105+
- `encodingDetectionType('')`: Read about encoding detection here: https://developers.cm.com/messaging/docs/sms#auto-detect-encoding
108106
- `multipart($minimum, $maximum)`: Accepts a 0 to 8 integer range which allows multipart messages. See the [documentation from CM](https://dashboard.onlinesmsgateway.com/docs#send-a-message-multipart) for more information.
109107

110108
### Available events

src/CmsmsClient.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ public function send(CmsmsMessage $message, string $recipient): void
6262
*/
6363
public function buildMessageJson(CmsmsMessage $message, string $recipient): string
6464
{
65-
$encodingDetectionType = config('services.cmsms.encoding_detection_type', 'AUTO');
66-
6765
$body = [];
6866
$body['content'] = $message->getBody();
69-
if (strtoupper($encodingDetectionType) === 'AUTO') {
67+
if (strtoupper($message->getEncodingDetectionType()) === 'AUTO') {
7068
$body['type'] = 'AUTO';
7169
}
7270

@@ -94,7 +92,7 @@ public function buildMessageJson(CmsmsMessage $message, string $recipient): stri
9492
'to' => [[
9593
'number' => $recipient,
9694
]],
97-
'dcs' => strtoupper($encodingDetectionType) === 'AUTO' ? 0 : $encodingDetectionType,
95+
'dcs' => strtoupper($message->getEncodingDetectionType()) === 'AUTO' ? '0' : $message->getEncodingDetectionType(),
9896
'from' => $message->getOriginator(),
9997
...$minimumNumberOfMessageParts,
10098
...$maximumNumberOfMessageParts,

src/CmsmsMessage.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class CmsmsMessage
1212

1313
protected string $reference = '';
1414

15+
protected string $encodingDetectionType = 'AUTO';
16+
1517
protected ?int $minimumNumberOfMessageParts = null;
1618

1719
protected ?int $maximumNumberOfMessageParts = null;
@@ -88,6 +90,18 @@ public function getMaximumNumberOfMessageParts(): ?int
8890
return $this->maximumNumberOfMessageParts;
8991
}
9092

93+
public function encodingDetectionType(string|int $encodingDetectionType): self
94+
{
95+
$this->encodingDetectionType = (string) $encodingDetectionType;
96+
97+
return $this;
98+
}
99+
100+
public function getEncodingDetectionType(): string
101+
{
102+
return $this->encodingDetectionType;
103+
}
104+
91105
public static function create(string $body = ''): self
92106
{
93107
return new static($body);

tests/CmsmsClientTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,35 @@ public function it_includes_reference_data()
113113
$this->assertEquals('ABC', $messageJsonObject->messages->msg[0]->reference);
114114
}
115115

116+
/** @test */
117+
public function it_includes_encoding_detection_type_data_in_body()
118+
{
119+
$message = clone $this->message;
120+
$message->encodingDetectionType('AUTO');
121+
122+
$messageJson = $this->client->buildMessageJson($message, '00301234');
123+
124+
$messageJsonObject = json_decode($messageJson);
125+
126+
$this->assertTrue(isset($messageJsonObject->messages->msg[0]->body->type));
127+
$this->assertEquals('AUTO', $messageJsonObject->messages->msg[0]->body->type);
128+
$this->assertEquals('0', $messageJsonObject->messages->msg[0]->dcs);
129+
}
130+
131+
/** @test */
132+
public function it_includes_encoding_detection_type_data_in_message()
133+
{
134+
$message = clone $this->message;
135+
$message->encodingDetectionType(1);
136+
137+
$messageJson = $this->client->buildMessageJson($message, '00301234');
138+
139+
$messageJsonObject = json_decode($messageJson);
140+
141+
$this->assertFalse(isset($messageJsonObject->messages->msg[0]->body->type));
142+
$this->assertEquals('1', $messageJsonObject->messages->msg[0]->dcs);
143+
}
144+
116145
/** @test */
117146
public function it_dispatches_a_success_event()
118147
{

0 commit comments

Comments
 (0)