Skip to content

Commit b64f285

Browse files
committed
fix: WhatsApp number validation
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.
1 parent e33fcd6 commit b64f285

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
@@ -146,5 +146,21 @@ public static function validFromProvider(): iterable
146146
yield ['+1123456789123'];
147147
yield ['+11234567891234'];
148148
yield ['+112345678912345'];
149+
150+
// whatsapp
151+
yield ['whatsapp:+11'];
152+
yield ['whatsapp:+112'];
153+
yield ['whatsapp:+1123'];
154+
yield ['whatsapp:+11234'];
155+
yield ['whatsapp:+112345'];
156+
yield ['whatsapp:+1123456'];
157+
yield ['whatsapp:+11234567'];
158+
yield ['whatsapp:+112345678'];
159+
yield ['whatsapp:+1123456789'];
160+
yield ['whatsapp:+11234567891'];
161+
yield ['whatsapp:+112345678912'];
162+
yield ['whatsapp:+1123456789123'];
163+
yield ['whatsapp:+11234567891234'];
164+
yield ['whatsapp:+112345678912345'];
149165
}
150166
}

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

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

6161
$from = $message->getFrom() ?: $this->from;
6262

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

0 commit comments

Comments
 (0)