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.
This commit is contained in:
Chirag Aggarwal 2026-02-03 12:32:21 +05:30
parent 52cb8a9c56
commit e14a026415

View file

@ -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,