Skip to content

Commit b021595

Browse files
authored
Merge pull request #154 from MarcEspiard/feat/more-sms-params
Added support for more SMS Message optional params
2 parents ee3fff9 + 90e3689 commit b021595

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

src/Twilio.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa
8181
'maxPrice',
8282
'provideFeedback',
8383
'validityPeriod',
84+
'attempt',
85+
'contentRetention',
86+
'addressRetention',
87+
'smartEncoded',
88+
'persistentAction',
89+
'scheduleType',
90+
'sendAt',
91+
'sendAsMms',
92+
'contentVariables',
93+
'riskCheck',
8494
]);
8595

8696
if ($message instanceof TwilioMmsMessage) {

src/TwilioSmsMessage.php

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ class TwilioSmsMessage extends TwilioMessage
1818

1919
public ?int $validityPeriod = null;
2020

21+
public ?int $attempt = null;
22+
23+
public ?string $contentRetention = null;
24+
25+
public ?string $addressRetention = null;
26+
27+
public ?bool $smartEncoded = null;
28+
29+
public ?array $persistentAction = null;
30+
31+
public ?string $scheduleType = null;
32+
33+
public ?string $sendAt = null;
34+
35+
public ?bool $sendAsMms = null;
36+
37+
public ?string $contentVariables = null;
38+
39+
public ?string $riskCheck = null;
40+
2141
/**
2242
* Get the from address of this message.
2343
*/
@@ -111,4 +131,120 @@ public function validityPeriod(int $validityPeriodSeconds): self
111131

112132
return $this;
113133
}
134+
135+
/**
136+
* Total number of attempts made to send the message (including the current one).
137+
*/
138+
public function attempt(int $attempt): self
139+
{
140+
$this->attempt = $attempt;
141+
142+
return $this;
143+
}
144+
145+
/**
146+
* Determines if the message content can be stored or redacted based on privacy settings
147+
* Possible values:
148+
* - retain
149+
* - discard
150+
*/
151+
public function contentRetention(string $contentRetention): self
152+
{
153+
$this->contentRetention = $contentRetention;
154+
155+
return $this;
156+
}
157+
158+
/**
159+
* Determines if the address can be stored or obfuscated based on privacy settings
160+
* Possible values:
161+
* - retain
162+
* - obfuscate
163+
*/
164+
public function addressRetention(string $addressRetention): self
165+
{
166+
$this->addressRetention = $addressRetention;
167+
168+
return $this;
169+
}
170+
171+
/**
172+
* Whether to detect Unicode characters that have a similar GSM-7 character and replace them
173+
*/
174+
public function smartEncoded(bool $smartEncoded): self
175+
{
176+
$this->smartEncoded = $smartEncoded;
177+
178+
return $this;
179+
}
180+
181+
/**
182+
* Rich actions for non-SMS/MMS channels. Used for sending location in WhatsApp messages.
183+
* @param array<string> $persistentAction
184+
* @return $this
185+
*/
186+
public function persistentAction(array $persistentAction): self
187+
{
188+
$this->persistentAction = $persistentAction;
189+
190+
return $this;
191+
}
192+
193+
/**
194+
* For Messaging Services only: Include this parameter with a value of fixed in conjunction with the send_time parameter in order to schedule a Message.
195+
* Possible values:
196+
* - fixed
197+
*/
198+
public function scheduleType(string $scheduleType): self
199+
{
200+
$this->scheduleType = $scheduleType;
201+
202+
return $this;
203+
}
204+
205+
/**
206+
* The time that Twilio will send the message.
207+
* Must be in ISO 8601 format.
208+
*/
209+
public function sendAt(string $sendAt): self
210+
{
211+
$this->sendAt = $sendAt;
212+
213+
return $this;
214+
}
215+
216+
/**
217+
* If set to true, Twilio delivers the message as a single MMS message, regardless of the presence of media.
218+
*/
219+
public function sendAsMms(bool $sendAsMms): self
220+
{
221+
$this->sendAsMms = $sendAsMms;
222+
223+
return $this;
224+
}
225+
226+
/**
227+
* For Content Editor/API only: Key-value pairs of Template variables and their substitution values.
228+
* content_sid parameter must also be provided.
229+
* If values are not defined in the content_variables parameter, the Template's default placeholder values are used.
230+
*/
231+
public function contentVariables(string $contentVariables): self
232+
{
233+
$this->contentVariables = $contentVariables;
234+
235+
return $this;
236+
}
237+
238+
/**
239+
* Include this parameter with a value of "disable" to skip any kind of risk check on the respective message request.
240+
* Possible values:
241+
* - enable (default)
242+
* - disable
243+
*/
244+
public function riskCheck(string $riskCheck): self
245+
{
246+
$this->riskCheck = $riskCheck;
247+
248+
return $this;
249+
}
114250
}

tests/Unit/TwilioSmsMessageTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,32 @@ public function it_can_set_optional_parameters()
6767
$message->maxPrice(0.05);
6868
$message->provideFeedback(true);
6969
$message->validityPeriod(120);
70+
$message->attempt(3);
71+
$message->contentRetention('retain');
72+
$message->addressRetention('obfuscate');
73+
$message->smartEncoded(true);
74+
$message->persistentAction(['action1', 'action2']);
75+
$message->scheduleType('fixed');
76+
$message->sendAt('2021-01-01 00:00:00');
77+
$message->sendAsMms(true);
78+
$message->contentVariables('{"name": "John"}');
79+
$message->riskCheck('disable');
7080

7181
$this->assertEquals('http://example.com', $message->statusCallback);
7282
$this->assertEquals('PUT', $message->statusCallbackMethod);
7383
$this->assertEquals('ABCD1234', $message->applicationSid);
7484
$this->assertEquals(0.05, $message->maxPrice);
7585
$this->assertEquals(true, $message->provideFeedback);
7686
$this->assertEquals(120, $message->validityPeriod);
87+
$this->assertEquals(3, $message->attempt);
88+
$this->assertEquals('retain', $message->contentRetention);
89+
$this->assertEquals('obfuscate', $message->addressRetention);
90+
$this->assertEquals(true, $message->smartEncoded);
91+
$this->assertEquals(['action1', 'action2'], $message->persistentAction);
92+
$this->assertEquals('fixed', $message->scheduleType);
93+
$this->assertEquals('2021-01-01 00:00:00', $message->sendAt);
94+
$this->assertEquals(true, $message->sendAsMms);
95+
$this->assertEquals('{"name": "John"}', $message->contentVariables);
96+
$this->assertEquals('disable', $message->riskCheck);
7797
}
7898
}

0 commit comments

Comments
 (0)