Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage sms per country code count #7592

Merged
merged 23 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
62ee104
usage sms per country code count
shimonewman Feb 15, 2024
44ead21
Update src/Appwrite/Platform/Workers/Messaging.php
shimonewman Feb 15, 2024
ad44c7a
Addressed comments
shimonewman Feb 15, 2024
5b00737
Update app/init.php
shimonewman Mar 6, 2024
fcba25d
dummy commit
shimonewman Apr 7, 2024
d99fef5
Merge remote-tracking branch 'origin/feat-sms-locale' into feat-sms-l…
shimonewman Apr 7, 2024
7df94fc
Merge branch 'refactor-usage-sn' of github.com:appwrite/appwrite into…
shimonewman Apr 7, 2024
574035d
sms country code
shimonewman Apr 7, 2024
17b9f13
Merge branch 'refactor-usage-sn' of github.com:appwrite/appwrite into…
shimonewman May 8, 2024
88e67c8
getCountryCode
shimonewman May 8, 2024
9609ae3
getCountryCode
shimonewman May 8, 2024
989b0d9
Merge branch 'refactor-usage-sn' of github.com:appwrite/appwrite into…
shimonewman May 12, 2024
15b8aa5
composer format
shimonewman May 12, 2024
62a3521
composer format
shimonewman May 12, 2024
122b8e2
composer format
shimonewman May 12, 2024
d185002
composer format
shimonewman May 12, 2024
510f864
adding null safety
shimonewman May 12, 2024
02eacf6
composer update
shimonewman May 12, 2024
c26f09d
composer update
shimonewman May 12, 2024
3a46ac2
composer update
shimonewman May 12, 2024
aabd81e
composer update
shimonewman May 12, 2024
e53a074
composer update
shimonewman May 12, 2024
074eab3
Merge branch 'refactor-usage-sn' of github.com:appwrite/appwrite into…
shimonewman May 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
const METRIC_TEAMS = 'teams';
const METRIC_USERS = 'users';
const METRIC_MESSAGES = 'messages';
const METRIC_MESSAGES_COUNTRY_CODE = '{countryCode}.messages';
shimonewman marked this conversation as resolved.
Show resolved Hide resolved
const METRIC_SESSIONS = 'sessions';
const METRIC_DATABASES = 'databases';
const METRIC_COLLECTIONS = 'collections';
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"chillerlan/php-qrcode": "4.3.4",
"adhocore/jwt": "1.1.2",
"webonyx/graphql-php": "14.11.*",
"league/csv": "9.7.1"
"league/csv": "9.7.1",
"giggsey/libphonenumber-for-php-lite": "8.13.30"
},
"repositories": [
{
Expand Down
258 changes: 170 additions & 88 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Appwrite/Event/Usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function addMetric(string $key, int $value): self
public function trigger(): string|bool
{
$client = new Client($this->queue, $this->connection);

return $client->enqueue([
'project' => $this->getProject(),
'reduce' => $this->reduce,
Expand Down
13 changes: 13 additions & 0 deletions src/Appwrite/Platform/Workers/Messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Utopia\Platform\Action;
use Utopia\Queue\Message;
use Appwrite\Event\Usage;
use libphonenumber\PhoneNumberUtil;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use the lib directly in Appwrite and instead abstract it in utopia/messaging.


class Messaging extends Action
{
Expand Down Expand Up @@ -119,6 +120,18 @@ public function action(Message $message, Usage $queueForUsage): void
try {
$sms->send($message);

$phoneUtil = PhoneNumberUtil::getInstance();

try {
$countryCode = $phoneUtil
->parse($payload['recipient'])
->getCountryCode();

$queueForUsage->addMetric(str_replace('{countryCode}', $countryCode, METRIC_MESSAGES_COUNTRY_CODE), 1);
} catch (\libphonenumber\NumberParseException $e) {
shimonewman marked this conversation as resolved.
Show resolved Hide resolved
console::error("Error parsing number: " . $e->getMessage());
shimonewman marked this conversation as resolved.
Show resolved Hide resolved
}

$queueForUsage
->setProject($project)
->addMetric(METRIC_MESSAGES, 1)
Expand Down
Loading