diff --git a/app/init.php b/app/init.php index 88e8de0ea2..8260707ef7 100644 --- a/app/init.php +++ b/app/init.php @@ -215,6 +215,7 @@ const MESSAGE_TYPE_PUSH = 'push'; const METRIC_TEAMS = 'teams'; const METRIC_USERS = 'users'; const METRIC_MESSAGES = 'messages'; +const METRIC_MESSAGES_COUNTRY_CODE = '{countryCode}.messages'; const METRIC_SESSIONS = 'sessions'; const METRIC_DATABASES = 'databases'; const METRIC_COLLECTIONS = 'collections'; diff --git a/src/Appwrite/Event/Usage.php b/src/Appwrite/Event/Usage.php index cf92e6ffef..4426f4ab1b 100644 --- a/src/Appwrite/Event/Usage.php +++ b/src/Appwrite/Event/Usage.php @@ -58,7 +58,6 @@ class Usage extends Event public function trigger(): string|bool { $client = new Client($this->queue, $this->connection); - return $client->enqueue([ 'project' => $this->getProject(), 'reduce' => $this->reduce, diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index 0399302e77..c8df169e28 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -441,17 +441,24 @@ class Messaging extends Action try { $adapter->send($data); + $countryCode = $adapter->getCountryCode($message['to'][0] ?? ''); + if (!empty($countryCode)) { + $queueForUsage + ->addMetric(str_replace('{countryCode}', $countryCode, METRIC_MESSAGES_COUNTRY_CODE), 1); + } $queueForUsage ->addMetric(METRIC_MESSAGES, 1) ->setProject($project) ->trigger(); - } catch (\Throwable $e) { - throw new \Exception('Failed sending to targets with error: ' . $e->getMessage()); + } catch (\Throwable $th) { + throw new \Exception('Failed sending to targets with error: ' . $th->getMessage()); } }; }, $batches)); } + + private function getSmsAdapter(Document $provider): ?SMSAdapter { $credentials = $provider->getAttribute('credentials');