1
0
Fork 0
mirror of synced 2024-10-02 02:07:04 +13:00

Merge pull request #7592 from appwrite/feat-sms-locale

usage sms per country code count
This commit is contained in:
Christy Jacob 2024-05-22 17:30:14 +04:00 committed by GitHub
commit c3dba79009
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

View file

@ -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';

View file

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

View file

@ -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');