mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 16:38:32 +00:00
Merge pull request #7592 from appwrite/feat-sms-locale
usage sms per country code count
This commit is contained in:
commit
c3dba79009
3 changed files with 10 additions and 3 deletions
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue