1
0
Fork 0
mirror of synced 2024-07-01 04:30:59 +12:00

review changes

This commit is contained in:
Prateek Banga 2023-10-04 16:15:59 +05:30
parent 234f7f003b
commit 48b91e39a8
11 changed files with 851 additions and 854 deletions

View file

@ -1934,6 +1934,13 @@ $commonCollections = [
'attributes' => ['providerInternalId'],
'lengths' => [],
'orders' => [],
],
[
'$id' => ID::custom('_key_identifier'),
'type' => Database::INDEX_KEY,
'attributes' => ['identifier'],
'lengths' => [],
'orders' => [],
]
],
],

View file

@ -1230,7 +1230,6 @@ App::post('/v1/account/sessions/phone')
->label('abuse-key', 'url:{url},phone:{param-phone}')
->param('userId', '', new CustomId(), 'Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
->param('phone', '', new Phone(), 'Phone number. Format this number with a leading \'+\' and a country code, e.g., +16175551212.')
->param('from', '', new Text(128), 'Sender of the message. It can be alphanumeric (Ex: MyCompany20). Restrictions may apply depending of the destination.', true)
->inject('request')
->inject('response')
->inject('user')
@ -1239,9 +1238,9 @@ App::post('/v1/account/sessions/phone')
->inject('events')
->inject('messaging')
->inject('locale')
->action(function (string $userId, string $phone, string $from, Request $request, Response $response, Document $user, Document $project, Database $dbForProject, Event $events, Messaging $messaging, Locale $locale) {
->action(function (string $userId, string $phone, Request $request, Response $response, Document $user, Document $project, Database $dbForProject, Event $events, Messaging $messaging, Locale $locale) {
$provider = Authorization::skip(fn () => $dbForProject->findOne('providers', [
Query::equal('default', [true, false]),
Query::equal('default', [true]),
Query::equal('type', ['sms'])
]));
if ($provider === false || $provider->isEmpty()) {
@ -1330,13 +1329,20 @@ App::post('/v1/account/sessions/phone')
$message = $message->setParam('{{token}}', $secret);
$message = $message->render();
$target = $dbForProject->createDocument('targets', new Document([
'userId' => $user->getId(),
'userInternalId' => $user->getInternalId(),
'providerId' => $provider->getId(),
'providerInternalId' => $provider->getInternalId(),
'identifier' => $phone,
]));
$target = $dbForProject->findOne('targets', [
Query::equal('identifier', [$phone]),
Query::equal('providerInternalId', [$provider->getInternalId()])
]);
if (!$target) {
$target = $dbForProject->createDocument('targets', new Document([
'userId' => $user->getId(),
'userInternalId' => $user->getInternalId(),
'providerId' => $provider->getId(),
'providerInternalId' => $provider->getInternalId(),
'identifier' => $phone,
]));
}
$messageDoc = $dbForProject->createDocument('messages', new Document([
'$id' => $token->getId(),
@ -2899,7 +2905,6 @@ App::post('/v1/account/verification/phone')
->label('sdk.response.model', Response::MODEL_TOKEN)
->label('abuse-limit', 10)
->label('abuse-key', 'userId:{userId}')
->param('from', '', new Text(128), 'Sender of the message. It can be alphanumeric (Ex: MyCompany20). Restrictions may apply depending of the destination.', true)
->inject('request')
->inject('response')
->inject('user')
@ -2908,9 +2913,9 @@ App::post('/v1/account/verification/phone')
->inject('messaging')
->inject('project')
->inject('locale')
->action(function (string $from, Request $request, Response $response, Document $user, Database $dbForProject, Event $events, Messaging $messaging, Document $project, Locale $locale) {
->action(function (Request $request, Response $response, Document $user, Database $dbForProject, Event $events, Messaging $messaging, Document $project, Locale $locale) {
$provider = Authorization::skip(fn () => $dbForProject->findOne('providers', [
Query::equal('default', [true, false]),
Query::equal('default', [true]),
Query::equal('type', ['sms'])
]));
if ($provider === false || $provider->isEmpty()) {
@ -2959,13 +2964,17 @@ App::post('/v1/account/verification/phone')
$message = $message->setParam('{{token}}', $secret);
$message = $message->render();
$target = $dbForProject->createDocument('targets', new Document([
'userId' => $user->getId(),
'userInternalId' => $user->getInternalId(),
'providerId' => $provider->getId(),
'providerInternalId' => $provider->getInternalId(),
'identifier' => $user->getAttribute('phone'),
]));
$target = $dbForProject->findOne('targets', [Query::equal('identifier', [$user->getAttribute('phone')]), Query::equal('providerInternalId', [$provider->getInternalId()])]);
if (!$target) {
$target = $dbForProject->createDocument('targets', new Document([
'userId' => $user->getId(),
'userInternalId' => $user->getInternalId(),
'providerId' => $provider->getId(),
'providerInternalId' => $provider->getInternalId(),
'identifier' => $user->getAttribute('phone'),
]));
}
$messageDoc = $dbForProject->createDocument('messages', new Document([
'$id' => $verification->getId(),

File diff suppressed because it is too large Load diff

View file

@ -1228,7 +1228,6 @@ App::patch('/v1/users/:userId/targets/:targetId/identifier')
throw new Exception(Exception::USER_TARGET_NOT_FOUND);
}
// Update the target identifier here
$target->setAttribute('identifier', $identifier);
$target = $dbForProject->updateDocument('targets', $target->getId(), $target);

View file

@ -22,6 +22,9 @@ use Utopia\Messaging\Adapters\Email\SendGrid;
use Utopia\Messaging\Messages\Email;
use Utopia\Messaging\Messages\Push;
use Utopia\Messaging\Messages\SMS;
use Appwrite\Extend\Exception;
use function Swoole\Coroutine\batch;
require_once __DIR__ . '/../init.php';
@ -39,48 +42,9 @@ class MessagingV1 extends Worker
public function getName(): string
{
return "mails";
return "messaging";
}
public function sms($record): ?SMSAdapter
{
$credentials = $record->getAttribute('credentials');
return match ($record->getAttribute('provider')) {
'mock' => new Mock('username', 'password'),
'twilio' => new Twilio($credentials['accountSid'], $credentials['authToken']),
'text-magic' => new TextMagic($credentials['username'], $credentials['apiKey']),
'telesign' => new Telesign($credentials['username'], $credentials['password']),
'msg91' => new Msg91($credentials['senderId'], $credentials['authKey']),
'vonage' => new Vonage($credentials['apiKey'], $credentials['apiSecret']),
default => null
};
}
public function push($record): ?PushAdapter
{
$credentials = $record->getAttribute('credentials');
return match ($record->getAttribute('provider')) {
'apns' => new APNS(
$credentials['authKey'],
$credentials['authKeyId'],
$credentials['teamId'],
$credentials['bundleId'],
$credentials['endpoint']
),
'fcm' => new FCM($credentials['serverKey']),
default => null
};
}
public function email($record): ?EmailAdapter
{
$credentials = $record->getAttribute('credentials');
return match ($record->getAttribute('provider')) {
'mailgun' => new Mailgun($credentials['apiKey'], $credentials['domain'], $credentials['isEuRegion']),
'sendgrid' => new SendGrid($credentials['apiKey']),
default => null
};
}
public function init(): void
{
@ -91,12 +55,11 @@ class MessagingV1 extends Worker
$project = new Document($this->args['project']);
$this->dbForProject = $this->getProjectDB($project);
$messageRecord = $this->dbForProject->getDocument('messages', $this->args['messageId']);
$message = $this->dbForProject->getDocument('messages', $this->args['messageId']);
$providerId = $messageRecord->getAttribute('providerId');
$providerRecord = $this->dbForProject->getDocument('providers', $providerId);
$provider = $this->dbForProject->getDocument('providers', $message->getAttribute('providerId'));
$this->processMessage($messageRecord, $providerRecord);
$this->processMessage($message, $provider);
}
private function processMessage(Document $messageRecord, Document $providerRecord): void
@ -105,7 +68,7 @@ class MessagingV1 extends Worker
'sms' => $this->sms($providerRecord),
'push' => $this->push($providerRecord),
'email' => $this->email($providerRecord),
default => null
default => throw new Exception(Exception::PROVIDER_INCORRECT_TYPE)
};
$recipientsId = $messageRecord->getAttribute('to');
@ -115,7 +78,6 @@ class MessagingV1 extends Worker
*/
$recipients = [];
$topics = $this->dbForProject->find('topics', [Query::equal('$id', $recipientsId)]);
foreach ($topics as $topic) {
$recipients = \array_merge($recipients, $topic->getAttribute('targets'));
@ -128,6 +90,7 @@ class MessagingV1 extends Worker
$targets = $this->dbForProject->find('targets', [Query::equal('$id', $recipientsId)]);
$recipients = \array_merge($recipients, $targets);
$recipients = \array_filter($recipients, fn (Document $recipient) => $recipient->getAttribute('providerId') === $providerRecord->getId());
$identifiers = \array_map(function (Document $recipient) {
return $recipient->getAttribute('identifier');
@ -135,27 +98,42 @@ class MessagingV1 extends Worker
$maxBatchSize = $provider->getMaxMessagesPerRequest();
$batches = \array_chunk($identifiers, $maxBatchSize);
$deliveredTo = 0;
foreach ($batches as $batch) {
$messageRecord->setAttribute('to', $batch);
$message = match ($providerRecord->getAttribute('type')) {
'sms' => $this->buildSMSMessage($messageRecord, $providerRecord),
'push' => $this->buildPushMessage($messageRecord),
'email' => $this->buildEmailMessage($messageRecord, $providerRecord),
default => null
};
try {
$provider->send($message);
$deliveredTo += \count($batch);
} catch (Exception $e) {
$deliveryErrors = $messageRecord->getAttribute('deliveryErrors');
foreach ($batch as $identifier) {
$deliveryErrors[] = 'Failed to send message to target' . $identifier . ': ' . $e->getMessage();
$results = batch(\array_map(function ($batch) use ($messageRecord, $providerRecord, $provider) {
return function () use ($batch, $messageRecord, $providerRecord, $provider) {
$deliveredTo = 0;
$deliveryErrors = [];
$messageData = clone $messageRecord;
$messageData->setAttribute('to', $batch);
$message = match ($providerRecord->getAttribute('type')) {
'sms' => $this->buildSMSMessage($messageRecord, $providerRecord),
'push' => $this->buildPushMessage($messageRecord),
'email' => $this->buildEmailMessage($messageRecord, $providerRecord),
default => throw new Exception(Exception::PROVIDER_INCORRECT_TYPE)
};
try {
$provider->send($message);
$deliveredTo += \count($batch);
} catch (Exception $e) {
foreach ($batch as $identifier) {
$deliveryErrors[] = 'Failed to send message to target' . $identifier . ': ' . $e->getMessage();
}
} finally {
return [
'deliveredTo' => $deliveredTo,
'deliveryErrors' => $deliveryErrors,
];
}
$messageRecord->setAttribute('deliveryErrors', $deliveryErrors);
}
};
}, $batches));
$deliveredTo = 0;
$deliveryErrors = [];
foreach ($results as $result) {
$deliveredTo += $result['deliveredTo'];
$deliveryErrors = \array_merge($deliveryErrors, $result['deliveryErrors']);
}
$messageRecord->setAttribute('deliveryErrors', $deliveryErrors);
if (\count($messageRecord->getAttribute('deliveryErrors')) > 0) {
$messageRecord->setAttribute('status', 'failed');
@ -173,17 +151,58 @@ class MessagingV1 extends Worker
{
}
private function buildEmailMessage($message, $provider): Email
private function sms(Document $document): ?SMSAdapter
{
$credentials = $document->getAttribute('credentials');
return match ($document->getAttribute('provider')) {
'mock' => new Mock('username', 'password'),
'twilio' => new Twilio($credentials['accountSid'], $credentials['authToken']),
'text-magic' => new TextMagic($credentials['username'], $credentials['apiKey']),
'telesign' => new Telesign($credentials['username'], $credentials['password']),
'msg91' => new Msg91($credentials['senderId'], $credentials['authKey']),
'vonage' => new Vonage($credentials['apiKey'], $credentials['apiSecret']),
default => null
};
}
private function push(Document $document): ?PushAdapter
{
$credentials = $document->getAttribute('credentials');
return match ($document->getAttribute('provider')) {
'apns' => new APNS(
$credentials['authKey'],
$credentials['authKeyId'],
$credentials['teamId'],
$credentials['bundleId'],
$credentials['endpoint']
),
'fcm' => new FCM($credentials['serverKey']),
default => null
};
}
private function email(Document $document): ?EmailAdapter
{
$credentials = $document->getAttribute('credentials');
return match ($document->getAttribute('provider')) {
'mailgun' => new Mailgun($credentials['apiKey'], $credentials['domain'], $credentials['isEuRegion']),
'sendgrid' => new SendGrid($credentials['apiKey']),
default => null
};
}
private function buildEmailMessage(Document $message, Document $provider): Email
{
$from = $provider['options']['from'];
$to = $message['to'];
$subject = $message['data']['subject'];
$content = $message['data']['content'];
$html = $message['data']['html'];
return new Email(to: $to, subject: $subject, content: $content, from: $from, html: $html);
return new Email($to, $subject, $content, $from, null, $html);
}
private function buildSMSMessage($message, $provider): SMS
private function buildSMSMessage(Document $message, Document $provider): SMS
{
$to = $message['to'];
$content = $message['data']['content'];
@ -192,7 +211,7 @@ class MessagingV1 extends Worker
return new SMS($to, $content, $from);
}
private function buildPushMessage($message): Push
private function buildPushMessage(Document $message): Push
{
$to = $message['to'];
$title = $message['data']['title'];
@ -204,6 +223,7 @@ class MessagingV1 extends Worker
$color = $message['data']['color'];
$tag = $message['data']['tag'];
$badge = $message['data']['badge'];
return new Push($to, $title, $body, $data, $action, $sound, $icon, $color, $tag, $badge);
}
}

View file

@ -56,7 +56,7 @@
"utopia-php/image": "0.5.*",
"utopia-php/locale": "0.4.*",
"utopia-php/logger": "0.3.*",
"utopia-php/messaging": "dev-feat-push as 0.1.1",
"utopia-php/messaging": "0.2.*",
"utopia-php/migration": "0.3.*",
"utopia-php/orchestration": "0.9.*",
"utopia-php/platform": "0.4.*",

95
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6431be75373bf2e1bdbe2c638188d15f",
"content-hash": "237609b7e9fb20d807aa6e773bf72de6",
"packages": [
{
"name": "adhocore/jwt",
@ -1050,16 +1050,16 @@
},
{
"name": "matomo/device-detector",
"version": "6.1.5",
"version": "6.1.6",
"source": {
"type": "git",
"url": "https://github.com/matomo-org/device-detector.git",
"reference": "40ca2990dba2c1719e5c62168e822e0b86c167d4"
"reference": "5cbea85106e561c7138d03603eb6e05128480409"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/matomo-org/device-detector/zipball/40ca2990dba2c1719e5c62168e822e0b86c167d4",
"reference": "40ca2990dba2c1719e5c62168e822e0b86c167d4",
"url": "https://api.github.com/repos/matomo-org/device-detector/zipball/5cbea85106e561c7138d03603eb6e05128480409",
"reference": "5cbea85106e561c7138d03603eb6e05128480409",
"shasum": ""
},
"require": {
@ -1115,7 +1115,7 @@
"source": "https://github.com/matomo-org/matomo",
"wiki": "https://dev.matomo.org/"
},
"time": "2023-08-17T16:17:41+00:00"
"time": "2023-10-02T10:01:54+00:00"
},
{
"name": "mongodb/mongodb",
@ -2152,16 +2152,16 @@
},
{
"name": "utopia-php/database",
"version": "0.43.2",
"version": "0.43.4",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database.git",
"reference": "f2626acd42665a9987c94af1c93bf20c28d55c9d"
"reference": "cabdd02e8dc1732eb0b22007c511e7bb3caa5c8c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/f2626acd42665a9987c94af1c93bf20c28d55c9d",
"reference": "f2626acd42665a9987c94af1c93bf20c28d55c9d",
"url": "https://api.github.com/repos/utopia-php/database/zipball/cabdd02e8dc1732eb0b22007c511e7bb3caa5c8c",
"reference": "cabdd02e8dc1732eb0b22007c511e7bb3caa5c8c",
"shasum": ""
},
"require": {
@ -2202,9 +2202,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/0.43.2"
"source": "https://github.com/utopia-php/database/tree/0.43.4"
},
"time": "2023-09-07T19:04:33+00:00"
"time": "2023-09-28T09:00:05+00:00"
},
{
"name": "utopia-php/domains",
@ -2516,16 +2516,16 @@
},
{
"name": "utopia-php/messaging",
"version": "dev-feat-push",
"version": "0.2.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/messaging.git",
"reference": "2bb09220d0993a9f8f0afc63ff51382b13d93e18"
"reference": "2d0f474a106bb1da285f85e105c29b46085d3a43"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/messaging/zipball/2bb09220d0993a9f8f0afc63ff51382b13d93e18",
"reference": "2bb09220d0993a9f8f0afc63ff51382b13d93e18",
"url": "https://api.github.com/repos/utopia-php/messaging/zipball/2d0f474a106bb1da285f85e105c29b46085d3a43",
"reference": "2d0f474a106bb1da285f85e105c29b46085d3a43",
"shasum": ""
},
"require": {
@ -2558,22 +2558,22 @@
],
"support": {
"issues": "https://github.com/utopia-php/messaging/issues",
"source": "https://github.com/utopia-php/messaging/tree/feat-push"
"source": "https://github.com/utopia-php/messaging/tree/0.2.0"
},
"time": "2023-09-14T20:29:49+00:00"
"time": "2023-09-14T20:48:42+00:00"
},
{
"name": "utopia-php/migration",
"version": "0.3.4",
"version": "0.3.5",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/migration.git",
"reference": "ade836d61b3e1547bc9f0dc300ee75b24ab49f7a"
"reference": "b2fd3a8310296f4e44ff0e85b0eb0230ad9a2f83"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/ade836d61b3e1547bc9f0dc300ee75b24ab49f7a",
"reference": "ade836d61b3e1547bc9f0dc300ee75b24ab49f7a",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/b2fd3a8310296f4e44ff0e85b0eb0230ad9a2f83",
"reference": "b2fd3a8310296f4e44ff0e85b0eb0230ad9a2f83",
"shasum": ""
},
"require": {
@ -2596,16 +2596,6 @@
"license": [
"MIT"
],
"authors": [
{
"name": "Eldad Fux",
"email": "eldad@appwrite.io"
},
{
"name": "Bradley Schofield",
"email": "bradley@appwrite.io"
}
],
"description": "A simple library to migrate resources between services.",
"keywords": [
"framework",
@ -2616,9 +2606,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/migration/issues",
"source": "https://github.com/utopia-php/migration/tree/0.3.4"
"source": "https://github.com/utopia-php/migration/tree/0.3.5"
},
"time": "2023-09-14T17:17:55+00:00"
"time": "2023-09-25T16:51:47+00:00"
},
{
"name": "utopia-php/mongo",
@ -3442,16 +3432,16 @@
},
{
"name": "doctrine/deprecations",
"version": "v1.1.1",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/doctrine/deprecations.git",
"reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3"
"reference": "4f2d4f2836e7ec4e7a8625e75c6aa916004db931"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3",
"reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/4f2d4f2836e7ec4e7a8625e75c6aa916004db931",
"reference": "4f2d4f2836e7ec4e7a8625e75c6aa916004db931",
"shasum": ""
},
"require": {
@ -3483,9 +3473,9 @@
"homepage": "https://www.doctrine-project.org/",
"support": {
"issues": "https://github.com/doctrine/deprecations/issues",
"source": "https://github.com/doctrine/deprecations/tree/v1.1.1"
"source": "https://github.com/doctrine/deprecations/tree/1.1.2"
},
"time": "2023-06-03T09:27:29+00:00"
"time": "2023-09-27T20:04:15+00:00"
},
{
"name": "doctrine/instantiator",
@ -4145,16 +4135,16 @@
},
{
"name": "phpstan/phpdoc-parser",
"version": "1.24.1",
"version": "1.24.2",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01"
"reference": "bcad8d995980440892759db0c32acae7c8e79442"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01",
"reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442",
"reference": "bcad8d995980440892759db0c32acae7c8e79442",
"shasum": ""
},
"require": {
@ -4186,9 +4176,9 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.1"
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.2"
},
"time": "2023-09-18T12:18:02+00:00"
"time": "2023-09-26T12:28:12+00:00"
},
{
"name": "phpunit/php-code-coverage",
@ -6001,18 +5991,9 @@
"time": "2023-08-28T11:09:02+00:00"
}
],
"aliases": [
{
"package": "utopia-php/messaging",
"version": "dev-feat-push",
"alias": "0.1.1",
"alias_normalized": "0.1.1.0"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"utopia-php/messaging": 20
},
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {

View file

@ -15,7 +15,6 @@ class Messaging extends Event
}
/**
* Sets message ID for the messaging event.
*

View file

@ -748,7 +748,7 @@ class AccountCustomClientTest extends Scope
$authKey = App::getEnv('_APP_MESSAGE_SMS_PROVIDER_MSG91_AUTH_KEY');
$senderId = App::getEnv('_APP_MESSAGE_SMS_PROVIDER_MSG91_SENDER_ID');
if ($to === '' || $from === '' || $authKey === '' || $senderId === '') {
if (empty($to) || empty($from) || empty($authKey) || empty($senderId)) {
$this->markTestSkipped('SMS provider not configured');
}
@ -758,10 +758,8 @@ class AccountCustomClientTest extends Scope
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]), [
'providerId' => 'unique()',
'providerId' => ID::unique(),
'name' => 'Sms provider',
'provider' => 'msg91',
'type' => 'sms',
'senderId' => $senderId,
'authKey' => $authKey,
'default' => true,
@ -1032,7 +1030,7 @@ class AccountCustomClientTest extends Scope
$this->assertEmpty($response['body']['secret']);
$this->assertEquals(true, (new DatetimeValidator())->isValid($response['body']['expire']));
\sleep(2);
\sleep(3);
$message = $this->client->call(Client::METHOD_GET, '/messaging/messages/' . $response['body']['$id'], [
'origin' => 'http://localhost',

View file

@ -128,7 +128,7 @@ class AccountTest extends Scope
$authKey = App::getEnv('_APP_MESSAGE_SMS_PROVIDER_MSG91_AUTH_KEY');
$senderId = App::getEnv('_APP_MESSAGE_SMS_PROVIDER_MSG91_SENDER_ID');
if ($to === '' || $from === '' || $authKey === '' || $senderId === '') {
if (empty($to) || empty($from) || empty($authKey) || empty($senderId)) {
$this->markTestSkipped('SMS provider not configured');
}
@ -137,10 +137,8 @@ class AccountTest extends Scope
$graphQLPayload = [
'query' => $query,
'variables' => [
'providerId' => 'unique()',
'providerId' => ID::unique(),
'name' => 'Sms Provider',
'provider' => 'msg91',
'type' => 'sms',
'from' => $from,
'senderId' => $senderId,
'authKey' => $authKey,

View file

@ -137,7 +137,7 @@ trait MessagingBase
],
];
foreach (\array_keys($providersParams) as $index => $key) {
$response = $this->client->call(Client::METHOD_PATCH, '/messaging/providers/' . $providers[$index]['$id'] . '/' . $key, [
$response = $this->client->call(Client::METHOD_PATCH, '/messaging/providers/' . $key . '/' . $providers[$index]['$id'], [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
@ -147,7 +147,7 @@ trait MessagingBase
$this->assertEquals($providersParams[$key]['name'], $response['body']['name']);
}
$response = $this->client->call(Client::METHOD_PATCH, '/messaging/providers/' . $providers[1]['$id'] . '/mailgun', [
$response = $this->client->call(Client::METHOD_PATCH, '/messaging/providers/mailgun/' . $providers[1]['$id'], [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],