From e14a026415c64fe67c2690e8c6ee8f156ec0ddbc Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 3 Feb 2026 12:32:21 +0530 Subject: [PATCH] Add country code extraction for external SMS messages Extract country codes from target identifiers for external SMS messages to match the behavior of internal SMS messages. --- src/Appwrite/Platform/Workers/Messaging.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 76f945a4bb..c1011f2c38 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -191,6 +191,22 @@ class Messaging extends Action Span::add('recipientsTotal', \count($allTargets)); + // Extract country codes for SMS targets + if ($providerType === MESSAGE_TYPE_SMS && !empty($allTargets)) { + $countryCodes = []; + foreach ($allTargets as $target) { + $identifier = $target->getAttribute('identifier', ''); + if (\str_starts_with($identifier, '+')) { + if (\preg_match('/^\+(\d{1,3})/', $identifier, $matches)) { + $countryCodes[$matches[1]] = ($countryCodes[$matches[1]] ?? 0) + 1; + } + } + } + if (!empty($countryCodes)) { + Span::add('countryCodes', \json_encode($countryCodes)); + } + } + if (empty($allTargets)) { $dbForProject->updateDocument('messages', $message->getId(), $message->setAttributes([ 'status' => MessageStatus::FAILED,