Skip to content

Commit 584ff71

Browse files
committed
feature symfony#61777 [Notifier][Twilio] WhatsApp number validation (OvidiuGi)
This PR was merged into the 7.4 branch. Discussion ---------- [Notifier][Twilio] WhatsApp number validation | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix symfony#61776 | License | MIT This commit modifies the validation regex to handle 'whatsapp:' prefixes. The regex now correctly validates WhatsApp numbers without breaking existing functionality for standard phone numbers. See - [https://github.com/symfony/symfony/issues/61776](url) Commits ------- b64f285 fix: WhatsApp number validation
2 parents 2d6913c + b64f285 commit 584ff71

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/Symfony/Component/Notifier/Bridge/Twilio/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.4
5+
---
6+
7+
* Add support for the WhatsApp integration if phone numbers are prefixed with `whatsapp:`
8+
49
6.2
510
---
611

src/Symfony/Component/Notifier/Bridge/Twilio/Tests/TwilioTransportTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,21 @@ public static function validFromProvider(): iterable
141141
yield ['+1123456789123'];
142142
yield ['+11234567891234'];
143143
yield ['+112345678912345'];
144+
145+
// whatsapp
146+
yield ['whatsapp:+11'];
147+
yield ['whatsapp:+112'];
148+
yield ['whatsapp:+1123'];
149+
yield ['whatsapp:+11234'];
150+
yield ['whatsapp:+112345'];
151+
yield ['whatsapp:+1123456'];
152+
yield ['whatsapp:+11234567'];
153+
yield ['whatsapp:+112345678'];
154+
yield ['whatsapp:+1123456789'];
155+
yield ['whatsapp:+11234567891'];
156+
yield ['whatsapp:+112345678912'];
157+
yield ['whatsapp:+1123456789123'];
158+
yield ['whatsapp:+11234567891234'];
159+
yield ['whatsapp:+112345678912345'];
144160
}
145161
}

src/Symfony/Component/Notifier/Bridge/Twilio/TwilioTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function doSend(MessageInterface $message): SentMessage
5757

5858
$from = $message->getFrom() ?: $this->from;
5959

60-
if (!preg_match('/^[a-zA-Z0-9\s]{2,11}$/', $from) && !preg_match('/^\+[1-9]\d{1,14}$/', $from)) {
60+
if (!preg_match('/^[a-zA-Z0-9\s]{2,11}$/', $from) && !preg_match('/^(?:whatsapp:)?\+[1-9]\d{1,14}$/', $from)) {
6161
throw new InvalidArgumentException(\sprintf('The "From" number "%s" is not a valid phone number, shortcode, or alphanumeric sender ID.', $from));
6262
}
6363

0 commit comments

Comments
 (0)