refactor(messaging): detect Messaging Service SIDs by prefix and length

A Messaging Service SID is always MG followed by 32 characters, and an alphanumeric sender ID is at most 11, so the MG prefix plus a length of 34 tells them apart without a regular expression.
This commit is contained in:
harsh mahajan committed 2026-09-13 01:15:34 +05:30
1 parent 3cb9680e7e
commit 33fadf8f93
1 file changed
+3 -3
+3 -3
View File
@@ -1278,9 +1278,9 @@ class Messaging extends Action
'twilio' => [
'accountSid' => $user,
'authToken' => $password,
// Alphanumeric sender IDs can also start with MG, so require the full Messaging Service SID format
// Messaging Service SIDs are always 34 characters; alphanumeric sender IDs, at most 11, can also start with MG
// https://www.twilio.com/docs/messaging/api/service-resource
'messagingServiceSid' => \preg_match('/^MG[0-9a-fA-F]{32}$/', $from) ? $from : null
'messagingServiceSid' => \str_starts_with($from, 'MG') && \strlen($from) === 34 ? $from : null
],
'textmagic' => [
'username' => $user,
@@ -1313,7 +1313,7 @@ class Messaging extends Action
},
'options' => match ($host) {
'twilio' => [
'from' => \preg_match('/^MG[0-9a-fA-F]{32}$/', $from) ? null : $from
'from' => \str_starts_with($from, 'MG') && \strlen($from) === 34 ? null : $from
],
default => [
'from' => $from