mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
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:
parent
52cb8a9c56
commit
e14a026415
1 changed files with 16 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue