From b1399d32a151624f468475010d80e6a61ae5312f Mon Sep 17 00:00:00 2001 From: James Seconde Date: Thu, 31 Oct 2024 11:50:28 +0000 Subject: [PATCH] Added validation logic for e164 (#521) --- src/Messages/Channel/MMS/MMSAudio.php | 6 ++++++ src/Messages/Channel/MMS/MMSImage.php | 6 ++++++ src/Messages/Channel/MMS/MMSVideo.php | 6 ++++++ src/Messages/Channel/MMS/MMSvCard.php | 6 ++++++ src/Messages/Channel/Message.php | 1 + src/Messages/Channel/Messenger/MessengerAudio.php | 6 ++++++ src/Messages/Channel/Messenger/MessengerFile.php | 6 ++++++ src/Messages/Channel/Messenger/MessengerImage.php | 6 ++++++ .../Channel/Messenger/MessengerObjectTrait.php | 7 ------- src/Messages/Channel/Messenger/MessengerText.php | 6 ++++++ src/Messages/Channel/Messenger/MessengerVideo.php | 6 ++++++ src/Messages/Channel/RCS/RcsCustom.php | 6 ++++++ src/Messages/Channel/RCS/RcsFile.php | 6 ++++++ src/Messages/Channel/RCS/RcsImage.php | 6 ++++++ src/Messages/Channel/RCS/RcsText.php | 6 ++++++ src/Messages/Channel/RCS/RcsVideo.php | 6 ++++++ src/Messages/Channel/SMS/SMSText.php | 6 ++++++ src/Messages/Channel/Viber/ViberFile.php | 6 ++++++ src/Messages/Channel/Viber/ViberImage.php | 6 ++++++ src/Messages/Channel/Viber/ViberText.php | 6 ++++++ src/Messages/Channel/Viber/ViberVideo.php | 6 ++++++ src/Messages/Channel/WhatsApp/WhatsAppAudio.php | 6 ++++++ src/Messages/Channel/WhatsApp/WhatsAppCustom.php | 6 ++++++ src/Messages/Channel/WhatsApp/WhatsAppFile.php | 6 ++++++ src/Messages/Channel/WhatsApp/WhatsAppImage.php | 6 ++++++ src/Messages/Channel/WhatsApp/WhatsAppSticker.php | 6 ++++++ src/Messages/Channel/WhatsApp/WhatsAppTemplate.php | 6 ++++++ src/Messages/Channel/WhatsApp/WhatsAppText.php | 6 ++++++ src/Messages/Channel/WhatsApp/WhatsAppVideo.php | 6 ++++++ src/Messages/Client.php | 14 +++++++++----- test/Messages/ClientTest.php | 2 +- 31 files changed, 173 insertions(+), 13 deletions(-) diff --git a/src/Messages/Channel/MMS/MMSAudio.php b/src/Messages/Channel/MMS/MMSAudio.php index c9a34c9e..2d1b6056 100644 --- a/src/Messages/Channel/MMS/MMSAudio.php +++ b/src/Messages/Channel/MMS/MMSAudio.php @@ -12,6 +12,7 @@ class MMSAudio extends BaseMessage protected string $channel = 'mms'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_AUDIO; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -22,6 +23,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/MMS/MMSImage.php b/src/Messages/Channel/MMS/MMSImage.php index a92c76a3..47855f26 100644 --- a/src/Messages/Channel/MMS/MMSImage.php +++ b/src/Messages/Channel/MMS/MMSImage.php @@ -12,6 +12,7 @@ class MMSImage extends BaseMessage protected string $channel = 'mms'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_IMAGE; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -22,6 +23,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/MMS/MMSVideo.php b/src/Messages/Channel/MMS/MMSVideo.php index 5aaaa5cc..0d276609 100644 --- a/src/Messages/Channel/MMS/MMSVideo.php +++ b/src/Messages/Channel/MMS/MMSVideo.php @@ -13,6 +13,7 @@ class MMSVideo extends BaseMessage protected string $channel = 'mms'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VIDEO; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -23,6 +24,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/MMS/MMSvCard.php b/src/Messages/Channel/MMS/MMSvCard.php index 54e6e927..9124b428 100644 --- a/src/Messages/Channel/MMS/MMSvCard.php +++ b/src/Messages/Channel/MMS/MMSvCard.php @@ -12,6 +12,7 @@ class MMSvCard extends BaseMessage protected string $channel = 'mms'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VCARD; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -22,6 +23,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/Message.php b/src/Messages/Channel/Message.php index 004370be..d5da6c0d 100644 --- a/src/Messages/Channel/Message.php +++ b/src/Messages/Channel/Message.php @@ -19,6 +19,7 @@ public function getWebhookUrl(): ?string; public function setWebhookUrl(string $url): void; public function getWebhookVersion(): ?string; public function setWebhookVersion(string $version): void; + public function validatesE164(): bool; /** * All message types have shared outputs required by the endpoint. diff --git a/src/Messages/Channel/Messenger/MessengerAudio.php b/src/Messages/Channel/Messenger/MessengerAudio.php index d7f77812..6e3ab8f4 100644 --- a/src/Messages/Channel/Messenger/MessengerAudio.php +++ b/src/Messages/Channel/Messenger/MessengerAudio.php @@ -11,6 +11,7 @@ class MessengerAudio extends BaseMessage protected string $channel = 'messenger'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_AUDIO; + protected bool $validatesE164 = false; public function __construct( string $to, @@ -25,6 +26,11 @@ public function __construct( $this->tag = $tag; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/Messenger/MessengerFile.php b/src/Messages/Channel/Messenger/MessengerFile.php index 00bb5fe6..8cad886e 100644 --- a/src/Messages/Channel/Messenger/MessengerFile.php +++ b/src/Messages/Channel/Messenger/MessengerFile.php @@ -11,6 +11,7 @@ class MessengerFile extends BaseMessage protected string $channel = 'messenger'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE; + protected bool $validatesE164 = false; public function __construct( string $to, @@ -36,4 +37,9 @@ public function toArray(): array return $returnArray; } + + public function validatesE164(): bool + { + return $this->validatesE164; + } } diff --git a/src/Messages/Channel/Messenger/MessengerImage.php b/src/Messages/Channel/Messenger/MessengerImage.php index 6aefb065..a17658f4 100644 --- a/src/Messages/Channel/Messenger/MessengerImage.php +++ b/src/Messages/Channel/Messenger/MessengerImage.php @@ -11,6 +11,7 @@ class MessengerImage extends BaseMessage protected string $channel = 'messenger'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_IMAGE; + protected bool $validatesE164 = false; public function __construct( string $to, @@ -36,4 +37,9 @@ public function toArray(): array return $returnArray; } + + public function validatesE164(): bool + { + return $this->validatesE164; + } } diff --git a/src/Messages/Channel/Messenger/MessengerObjectTrait.php b/src/Messages/Channel/Messenger/MessengerObjectTrait.php index 66cefa24..288a9a92 100644 --- a/src/Messages/Channel/Messenger/MessengerObjectTrait.php +++ b/src/Messages/Channel/Messenger/MessengerObjectTrait.php @@ -7,15 +7,11 @@ trait MessengerObjectTrait private ?string $category; private ?string $tag; - /** - * @return string - */ public function getCategory(): ?string { return $this->category; } - public function requiresMessengerObject(): bool { return $this->getTag() || $this->getCategory(); @@ -26,9 +22,6 @@ public function setCategory(string $category): void $this->category = $category; } - /** - * @return string - */ public function getTag(): ?string { return $this->tag; diff --git a/src/Messages/Channel/Messenger/MessengerText.php b/src/Messages/Channel/Messenger/MessengerText.php index 53568572..584d3a1f 100644 --- a/src/Messages/Channel/Messenger/MessengerText.php +++ b/src/Messages/Channel/Messenger/MessengerText.php @@ -12,6 +12,7 @@ class MessengerText extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_TEXT; protected string $channel = 'messenger'; + protected bool $validatesE164 = false; public function __construct( string $to, @@ -27,6 +28,11 @@ public function __construct( $this->tag = $tag; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/Messenger/MessengerVideo.php b/src/Messages/Channel/Messenger/MessengerVideo.php index a88f4e6b..900ed3a7 100644 --- a/src/Messages/Channel/Messenger/MessengerVideo.php +++ b/src/Messages/Channel/Messenger/MessengerVideo.php @@ -11,6 +11,7 @@ class MessengerVideo extends BaseMessage protected string $channel = 'messenger'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VIDEO; + protected bool $validatesE164 = false; public function __construct( string $to, @@ -25,6 +26,11 @@ public function __construct( $this->tag = $tag; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/RCS/RcsCustom.php b/src/Messages/Channel/RCS/RcsCustom.php index b94c733d..2ac0ae40 100644 --- a/src/Messages/Channel/RCS/RcsCustom.php +++ b/src/Messages/Channel/RCS/RcsCustom.php @@ -16,6 +16,7 @@ class RcsCustom extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE; protected string $channel = 'rcs'; protected array $custom; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -27,6 +28,11 @@ public function __construct( $this->custom = $custom; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function getCustom(): array { return $this->custom; diff --git a/src/Messages/Channel/RCS/RcsFile.php b/src/Messages/Channel/RCS/RcsFile.php index 1dc575cb..f9d476bd 100644 --- a/src/Messages/Channel/RCS/RcsFile.php +++ b/src/Messages/Channel/RCS/RcsFile.php @@ -16,6 +16,7 @@ class RcsFile extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE; protected string $channel = 'rcs'; protected FileObject $file; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -27,6 +28,11 @@ public function __construct( $this->file = $file; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function setTtl(?int $ttl): void { $range = [ diff --git a/src/Messages/Channel/RCS/RcsImage.php b/src/Messages/Channel/RCS/RcsImage.php index 25031298..ffacd672 100644 --- a/src/Messages/Channel/RCS/RcsImage.php +++ b/src/Messages/Channel/RCS/RcsImage.php @@ -16,6 +16,7 @@ class RcsImage extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_IMAGE; protected string $channel = 'rcs'; protected ImageObject $image; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -27,6 +28,11 @@ public function __construct( $this->image = $image; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function setTtl(?int $ttl): void { $range = [ diff --git a/src/Messages/Channel/RCS/RcsText.php b/src/Messages/Channel/RCS/RcsText.php index f907d22e..22a74d00 100644 --- a/src/Messages/Channel/RCS/RcsText.php +++ b/src/Messages/Channel/RCS/RcsText.php @@ -16,6 +16,7 @@ class RcsText extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_TEXT; protected string $channel = 'rcs'; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -27,6 +28,11 @@ public function __construct( $this->text = $message; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function setTtl(?int $ttl): void { $range = [ diff --git a/src/Messages/Channel/RCS/RcsVideo.php b/src/Messages/Channel/RCS/RcsVideo.php index 254fba31..b9976424 100644 --- a/src/Messages/Channel/RCS/RcsVideo.php +++ b/src/Messages/Channel/RCS/RcsVideo.php @@ -16,6 +16,7 @@ class RcsVideo extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VIDEO; protected string $channel = 'rcs'; protected VideoObject $video; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -27,6 +28,11 @@ public function __construct( $this->video = $videoObject; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function setTtl(?int $ttl): void { $range = [ diff --git a/src/Messages/Channel/SMS/SMSText.php b/src/Messages/Channel/SMS/SMSText.php index c25c7c9b..bf137d71 100644 --- a/src/Messages/Channel/SMS/SMSText.php +++ b/src/Messages/Channel/SMS/SMSText.php @@ -21,6 +21,7 @@ class SMSText extends BaseMessage protected ?string $encodingType = null; protected ?string $contentId = null; protected ?string $entityId = null; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -32,6 +33,11 @@ public function __construct( $this->text = $message; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function getEncodingType(): ?string { return $this->encodingType; diff --git a/src/Messages/Channel/Viber/ViberFile.php b/src/Messages/Channel/Viber/ViberFile.php index 56cbe206..4dbd42e2 100644 --- a/src/Messages/Channel/Viber/ViberFile.php +++ b/src/Messages/Channel/Viber/ViberFile.php @@ -11,6 +11,7 @@ class ViberFile extends BaseMessage protected string $channel = 'viber_service'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -21,6 +22,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/Viber/ViberImage.php b/src/Messages/Channel/Viber/ViberImage.php index f231a7b9..f01d8bc7 100644 --- a/src/Messages/Channel/Viber/ViberImage.php +++ b/src/Messages/Channel/Viber/ViberImage.php @@ -12,6 +12,7 @@ class ViberImage extends BaseMessage protected string $channel = 'viber_service'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_IMAGE; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -30,6 +31,11 @@ public function __construct( $this->action = $viberActionObject; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/Viber/ViberText.php b/src/Messages/Channel/Viber/ViberText.php index 0313eb3b..760bd090 100644 --- a/src/Messages/Channel/Viber/ViberText.php +++ b/src/Messages/Channel/Viber/ViberText.php @@ -13,6 +13,7 @@ class ViberText extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_TEXT; protected string $channel = 'viber_service'; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -32,6 +33,11 @@ public function __construct( $this->action = $viberActionObject; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/Viber/ViberVideo.php b/src/Messages/Channel/Viber/ViberVideo.php index ff73dc38..d8e09880 100644 --- a/src/Messages/Channel/Viber/ViberVideo.php +++ b/src/Messages/Channel/Viber/ViberVideo.php @@ -13,6 +13,7 @@ class ViberVideo extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VIDEO; protected string $channel = 'viber_service'; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -28,6 +29,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/WhatsApp/WhatsAppAudio.php b/src/Messages/Channel/WhatsApp/WhatsAppAudio.php index 0b8575ab..6975891a 100644 --- a/src/Messages/Channel/WhatsApp/WhatsAppAudio.php +++ b/src/Messages/Channel/WhatsApp/WhatsAppAudio.php @@ -12,6 +12,7 @@ class WhatsAppAudio extends BaseMessage protected string $channel = 'whatsapp'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_AUDIO; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -22,6 +23,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/WhatsApp/WhatsAppCustom.php b/src/Messages/Channel/WhatsApp/WhatsAppCustom.php index 7a1489d5..e6c8b649 100644 --- a/src/Messages/Channel/WhatsApp/WhatsAppCustom.php +++ b/src/Messages/Channel/WhatsApp/WhatsAppCustom.php @@ -11,6 +11,7 @@ class WhatsAppCustom extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_CUSTOM; protected string $channel = 'whatsapp'; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -21,6 +22,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function setCustom(array $custom): void { $this->custom = $custom; diff --git a/src/Messages/Channel/WhatsApp/WhatsAppFile.php b/src/Messages/Channel/WhatsApp/WhatsAppFile.php index 7f9274c1..1f68ea34 100644 --- a/src/Messages/Channel/WhatsApp/WhatsAppFile.php +++ b/src/Messages/Channel/WhatsApp/WhatsAppFile.php @@ -12,6 +12,7 @@ class WhatsAppFile extends BaseMessage protected string $channel = 'whatsapp'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -22,6 +23,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/WhatsApp/WhatsAppImage.php b/src/Messages/Channel/WhatsApp/WhatsAppImage.php index 8a702daa..a96bbef0 100644 --- a/src/Messages/Channel/WhatsApp/WhatsAppImage.php +++ b/src/Messages/Channel/WhatsApp/WhatsAppImage.php @@ -12,6 +12,7 @@ class WhatsAppImage extends BaseMessage protected string $channel = 'whatsapp'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_IMAGE; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -22,6 +23,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/WhatsApp/WhatsAppSticker.php b/src/Messages/Channel/WhatsApp/WhatsAppSticker.php index d547e7ee..0d5d3d34 100644 --- a/src/Messages/Channel/WhatsApp/WhatsAppSticker.php +++ b/src/Messages/Channel/WhatsApp/WhatsAppSticker.php @@ -12,6 +12,7 @@ class WhatsAppSticker extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_STICKER; protected string $channel = 'whatsapp'; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -22,6 +23,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function getSticker(): StickerObject { return $this->sticker; diff --git a/src/Messages/Channel/WhatsApp/WhatsAppTemplate.php b/src/Messages/Channel/WhatsApp/WhatsAppTemplate.php index 186b8f5f..27ce9470 100644 --- a/src/Messages/Channel/WhatsApp/WhatsAppTemplate.php +++ b/src/Messages/Channel/WhatsApp/WhatsAppTemplate.php @@ -13,6 +13,7 @@ class WhatsAppTemplate extends BaseMessage protected string $channel = 'whatsapp'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_TEMPLATE; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -24,6 +25,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = [ diff --git a/src/Messages/Channel/WhatsApp/WhatsAppText.php b/src/Messages/Channel/WhatsApp/WhatsAppText.php index 7a00c3ee..34e2c324 100644 --- a/src/Messages/Channel/WhatsApp/WhatsAppText.php +++ b/src/Messages/Channel/WhatsApp/WhatsAppText.php @@ -13,6 +13,7 @@ class WhatsAppText extends BaseMessage protected string $subType = BaseMessage::MESSAGES_SUBTYPE_TEXT; protected string $channel = 'whatsapp'; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -24,6 +25,11 @@ public function __construct( $this->text = $text; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Channel/WhatsApp/WhatsAppVideo.php b/src/Messages/Channel/WhatsApp/WhatsAppVideo.php index 6d92d06f..f7604086 100644 --- a/src/Messages/Channel/WhatsApp/WhatsAppVideo.php +++ b/src/Messages/Channel/WhatsApp/WhatsAppVideo.php @@ -12,6 +12,7 @@ class WhatsAppVideo extends BaseMessage protected string $channel = 'whatsapp'; protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VIDEO; + protected bool $validatesE164 = true; public function __construct( string $to, @@ -22,6 +23,11 @@ public function __construct( $this->from = $from; } + public function validatesE164(): bool + { + return $this->validatesE164; + } + public function toArray(): array { $returnArray = $this->getBaseMessageUniversalOutputArray(); diff --git a/src/Messages/Client.php b/src/Messages/Client.php index fe710dc3..1446f4cb 100644 --- a/src/Messages/Client.php +++ b/src/Messages/Client.php @@ -25,12 +25,16 @@ public function send(BaseMessage $message): ?array { $messageArray = $message->toArray(); - if ($this->isValidE164($messageArray['to'])) { - $messageArray['to'] = $this->stripLeadingPlus($messageArray['to']); - return $this->getAPIResource()->create($messageArray); - }; + if ($message->validatesE164()) { + if ($this->isValidE164($messageArray['to'])) { + $messageArray['to'] = $this->stripLeadingPlus($messageArray['to']); + return $this->getAPIResource()->create($messageArray); + } else { + throw new \InvalidArgumentException('Number provided is not a valid E164 number'); + } + } - throw new \InvalidArgumentException('Number provided is not a valid E164 number'); + return $this->getAPIResource()->create($messageArray); } public function updateRcsStatus(string $messageUuid, string $status): bool diff --git a/test/Messages/ClientTest.php b/test/Messages/ClientTest.php index fbc9ff98..ea549ddc 100644 --- a/test/Messages/ClientTest.php +++ b/test/Messages/ClientTest.php @@ -572,7 +572,7 @@ public function testCanSendWhatsAppCustom(): void public function testCanSendMessengerText(): void { $payload = [ - 'to' => '447700900000', + 'to' => '10152368852405295', 'from' => '16105551212', 'text' => 'This is a messenger response', 'category' => 'response'