From effbd5938e85515798b3738bbb9f9b1d53201896 Mon Sep 17 00:00:00 2001 From: MarcEspiard <32894646+MarcEspiard@users.noreply.github.com> Date: Mon, 3 Feb 2025 11:09:51 +1300 Subject: [PATCH 1/4] Add missing Twilio Message optional params --- src/Twilio.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Twilio.php b/src/Twilio.php index a764712..f3fec27 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -81,6 +81,19 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa 'maxPrice', 'provideFeedback', 'validityPeriod', + 'provideFeedback', + 'attempt', + 'validityPeriod', + 'forceDelivery', + 'contentRetention', + 'addressRetention', + 'smartEncoded', + 'shortenUrls', + 'scheduleType', + 'sendAt', + 'sendAsMms', + 'contentVariables', + 'riskCheck', ]); if ($message instanceof TwilioMmsMessage) { From 111f69b58ae4a6a69f1565a88632ad90d993e609 Mon Sep 17 00:00:00 2001 From: Marc Espiard Date: Mon, 3 Feb 2025 11:38:38 +1300 Subject: [PATCH 2/4] Added new params and associated tests --- src/Twilio.php | 1 - src/TwilioSmsMessage.php | 134 ++++++++++++++++++++++++++++ tests/Unit/TwilioSmsMessageTest.php | 20 +++++ 3 files changed, 154 insertions(+), 1 deletion(-) diff --git a/src/Twilio.php b/src/Twilio.php index f3fec27..dc0c993 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -81,7 +81,6 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa 'maxPrice', 'provideFeedback', 'validityPeriod', - 'provideFeedback', 'attempt', 'validityPeriod', 'forceDelivery', diff --git a/src/TwilioSmsMessage.php b/src/TwilioSmsMessage.php index 5479bb1..73d01b2 100755 --- a/src/TwilioSmsMessage.php +++ b/src/TwilioSmsMessage.php @@ -18,6 +18,26 @@ class TwilioSmsMessage extends TwilioMessage public ?int $validityPeriod = null; + public ?int $attempt = null; + + public ?string $contentRetention = null; + + public ?string $addressRetention = null; + + public ?bool $smartEncoded = null; + + public ?array $persistentAction = null; + + public ?string $scheduleType = null; + + public ?string $sendAt = null; + + public ?bool $sendAsMms = null; + + public ?string $contentVariables = null; + + public ?string $riskCheck = null; + /** * Get the from address of this message. */ @@ -111,4 +131,118 @@ public function validityPeriod(int $validityPeriodSeconds): self return $this; } + + /** + * Total number of attempts made to send the message (including the current one). + */ + public function attempt(int $attempt): self + { + $this->attempt = $attempt; + + return $this; + } + + /** + * Determines if the message content can be stored or redacted based on privacy settings + * Possible values: + * - retain + * - discard + */ + public function contentRetention(string $contentRetention): self + { + $this->contentRetention = $contentRetention; + + return $this; + } + + /** + * Determines if the address can be stored or obfuscated based on privacy settings + * Possible values: + * - retain + * - obfuscate + */ + public function addressRetention(string $addressRetention): self + { + $this->addressRetention = $addressRetention; + + return $this; + } + + /** + * Whether to detect Unicode characters that have a similar GSM-7 character and replace them + */ + public function smartEncoded(bool $smartEncoded): self + { + $this->smartEncoded = $smartEncoded; + + return $this; + } + + /** + * Rich actions for non-SMS/MMS channels. Used for sending location in WhatsApp messages. + * @param array $persistentAction + * @return $this + */ + public function persistentAction(array $persistentAction): self + { + $this->persistentAction = $persistentAction; + + return $this; + } + + /** + * 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. + */ + public function scheduleType(string $scheduleType): self + { + $this->scheduleType = $scheduleType; + + return $this; + } + + /** + * The time that Twilio will send the message. + * Must be in ISO 8601 format. + */ + public function sendAt(string $sendAt): self + { + $this->sendAt = $sendAt; + + return $this; + } + + /** + * If set to true, Twilio delivers the message as a single MMS message, regardless of the presence of media. + */ + public function sendAsMms(bool $sendAsMms): self + { + $this->sendAsMms = $sendAsMms; + + return $this; + } + + /** + * For Content Editor/API only: Key-value pairs of Template variables and their substitution values. + * content_sid parameter must also be provided. + * If values are not defined in the content_variables parameter, the Template's default placeholder values are used. + */ + public function contentVariables(string $contentVariables): self + { + $this->contentVariables = $contentVariables; + + return $this; + } + + /** + * Include this parameter with a value of "disable" to skip any kind of risk check on the respective message request. + * Possible values: + * - enable (default) + * - disable + */ + public function riskCheck(string $riskCheck): self + { + $this->riskCheck = $riskCheck; + + return $this; + } } diff --git a/tests/Unit/TwilioSmsMessageTest.php b/tests/Unit/TwilioSmsMessageTest.php index 1e919bc..ed3e38e 100644 --- a/tests/Unit/TwilioSmsMessageTest.php +++ b/tests/Unit/TwilioSmsMessageTest.php @@ -66,6 +66,16 @@ public function it_can_set_optional_parameters() $message->maxPrice(0.05); $message->provideFeedback(true); $message->validityPeriod(120); + $message->attempt(3); + $message->contentRetention('retain'); + $message->addressRetention('obfuscate'); + $message->smartEncoded(true); + $message->persistentAction(['action' => 'action', 'value' => 'value']); + $message->scheduleType('fixed'); + $message->sendAt('2021-01-01 00:00:00'); + $message->sendAsMms(true); + $message->contentVariables('{"name": "John"}'); + $message->riskCheck('disable'); $this->assertEquals('http://example.com', $message->statusCallback); $this->assertEquals('PUT', $message->statusCallbackMethod); @@ -73,5 +83,15 @@ public function it_can_set_optional_parameters() $this->assertEquals(0.05, $message->maxPrice); $this->assertEquals(true, $message->provideFeedback); $this->assertEquals(120, $message->validityPeriod); + $this->assertEquals(3, $message->attempt); + $this->assertEquals('retain', $message->contentRetention); + $this->assertEquals('obfuscate', $message->addressRetention); + $this->assertEquals(true, $message->smartEncoded); + $this->assertEquals(['action' => 'action', 'value' => 'value'], $message->persistentAction); + $this->assertEquals('fixed', $message->scheduleType); + $this->assertEquals('2021-01-01 00:00:00', $message->sendAt); + $this->assertEquals(true, $message->sendAsMms); + $this->assertEquals('{"name": "John"}', $message->contentVariables); + $this->assertEquals('disable', $message->riskCheck); } } From 349078ce9b016a8bdf9388ed7d19fb6ec93db46a Mon Sep 17 00:00:00 2001 From: Marc Espiard Date: Mon, 3 Feb 2025 11:41:52 +1300 Subject: [PATCH 3/4] Cleanup --- src/Twilio.php | 4 +--- src/TwilioSmsMessage.php | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Twilio.php b/src/Twilio.php index dc0c993..3cf44f4 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -82,12 +82,10 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa 'provideFeedback', 'validityPeriod', 'attempt', - 'validityPeriod', - 'forceDelivery', 'contentRetention', 'addressRetention', 'smartEncoded', - 'shortenUrls', + 'persistentAction', 'scheduleType', 'sendAt', 'sendAsMms', diff --git a/src/TwilioSmsMessage.php b/src/TwilioSmsMessage.php index 73d01b2..b52a44b 100755 --- a/src/TwilioSmsMessage.php +++ b/src/TwilioSmsMessage.php @@ -192,6 +192,8 @@ public function persistentAction(array $persistentAction): self /** * 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. + * Possible values: + * - fixed */ public function scheduleType(string $scheduleType): self { From 90e36894522ded0dc22dc8f65c765efd797da716 Mon Sep 17 00:00:00 2001 From: Marc Espiard Date: Mon, 3 Feb 2025 11:46:46 +1300 Subject: [PATCH 4/4] Updated tests to reflect actual param values --- tests/Unit/TwilioSmsMessageTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/TwilioSmsMessageTest.php b/tests/Unit/TwilioSmsMessageTest.php index ed3e38e..95a3085 100644 --- a/tests/Unit/TwilioSmsMessageTest.php +++ b/tests/Unit/TwilioSmsMessageTest.php @@ -70,7 +70,7 @@ public function it_can_set_optional_parameters() $message->contentRetention('retain'); $message->addressRetention('obfuscate'); $message->smartEncoded(true); - $message->persistentAction(['action' => 'action', 'value' => 'value']); + $message->persistentAction(['action1', 'action2']); $message->scheduleType('fixed'); $message->sendAt('2021-01-01 00:00:00'); $message->sendAsMms(true); @@ -87,7 +87,7 @@ public function it_can_set_optional_parameters() $this->assertEquals('retain', $message->contentRetention); $this->assertEquals('obfuscate', $message->addressRetention); $this->assertEquals(true, $message->smartEncoded); - $this->assertEquals(['action' => 'action', 'value' => 'value'], $message->persistentAction); + $this->assertEquals(['action1', 'action2'], $message->persistentAction); $this->assertEquals('fixed', $message->scheduleType); $this->assertEquals('2021-01-01 00:00:00', $message->sendAt); $this->assertEquals(true, $message->sendAsMms);