mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch 'feat-mailgun-provider' of https://github.com/appwrite/appwrite into feat-topics-controller
This commit is contained in:
@@ -22,6 +22,7 @@ use Utopia\Validator\Boolean;
|
||||
use Utopia\Validator\JSON;
|
||||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\WhiteList;
|
||||
use Utopia\Database\DateTime;
|
||||
|
||||
App::post('/v1/messaging/providers/mailgun')
|
||||
->desc('Create Mailgun Provider')
|
||||
@@ -70,8 +71,8 @@ App::post('/v1/messaging/providers/mailgun')
|
||||
// Check if a default provider exists, if not, set this one as default
|
||||
if (
|
||||
empty($dbForProject->findOne('providers', [
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['email'])
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['email'])
|
||||
]))
|
||||
) {
|
||||
$provider->setAttribute('default', true);
|
||||
@@ -80,7 +81,7 @@ App::post('/v1/messaging/providers/mailgun')
|
||||
try {
|
||||
$provider = $dbForProject->createDocument('providers', $provider);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS, 'Provider already exists.');
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
$response
|
||||
@@ -127,8 +128,8 @@ App::post('/v1/messaging/providers/sendgrid')
|
||||
// Check if a default provider exists, if not, set this one as default
|
||||
if (
|
||||
empty($dbForProject->findOne('providers', [
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['sms'])
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['sms'])
|
||||
]))
|
||||
) {
|
||||
$provider->setAttribute('default', true);
|
||||
@@ -137,7 +138,7 @@ App::post('/v1/messaging/providers/sendgrid')
|
||||
try {
|
||||
$provider = $dbForProject->createDocument('providers', $provider);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS, 'Provider already exists.');
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
$response
|
||||
@@ -199,13 +200,14 @@ App::post('/v1/messaging/providers/msg91')
|
||||
try {
|
||||
$provider = $dbForProject->createDocument('providers', $provider);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS, 'Provider already exists.');
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::post('/v1/messaging/providers/telesign')
|
||||
->desc('Create Telesign Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
@@ -246,8 +248,8 @@ App::post('/v1/messaging/providers/telesign')
|
||||
// Check if a default provider exists, if not, set this one as default
|
||||
if (
|
||||
empty($dbForProject->findOne('providers', [
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['sms'])
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['sms'])
|
||||
]))
|
||||
) {
|
||||
$provider->setAttribute('default', true);
|
||||
@@ -256,7 +258,7 @@ App::post('/v1/messaging/providers/telesign')
|
||||
try {
|
||||
$provider = $dbForProject->createDocument('providers', $provider);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS, 'Provider already exists.');
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
$response
|
||||
@@ -304,8 +306,8 @@ App::post('/v1/messaging/providers/textmagic')
|
||||
// Check if a default provider exists, if not, set this one as default
|
||||
if (
|
||||
empty($dbForProject->findOne('providers', [
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['sms'])
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['sms'])
|
||||
]))
|
||||
) {
|
||||
$provider->setAttribute('default', true);
|
||||
@@ -314,7 +316,7 @@ App::post('/v1/messaging/providers/textmagic')
|
||||
try {
|
||||
$provider = $dbForProject->createDocument('providers', $provider);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS, 'Provider already exists.');
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
$response
|
||||
@@ -362,8 +364,8 @@ App::post('/v1/messaging/providers/twilio')
|
||||
// Check if a default provider exists, if not, set this one as default
|
||||
if (
|
||||
empty($dbForProject->findOne('providers', [
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['sms'])
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['sms'])
|
||||
]))
|
||||
) {
|
||||
$provider->setAttribute('default', true);
|
||||
@@ -372,7 +374,7 @@ App::post('/v1/messaging/providers/twilio')
|
||||
try {
|
||||
$provider = $dbForProject->createDocument('providers', $provider);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS, 'Provider already exists.');
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
$response
|
||||
@@ -420,7 +422,7 @@ App::post('/v1/messaging/providers/vonage')
|
||||
// Check if a default provider exists, if not, set this one as default
|
||||
if (
|
||||
empty($dbForProject->findOne('providers', [
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['sms'])
|
||||
]))
|
||||
) {
|
||||
@@ -430,7 +432,7 @@ App::post('/v1/messaging/providers/vonage')
|
||||
try {
|
||||
$provider = $dbForProject->createDocument('providers', $provider);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS, 'Provider already exists.');
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
$response
|
||||
@@ -446,7 +448,7 @@ App::post('/v1/messaging/providers/fcm')
|
||||
->label('scope', 'providers.write')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'messaging')
|
||||
->label('sdk.method', 'createFCMProvider')
|
||||
->label('sdk.method', 'createFcmProvider')
|
||||
->label('sdk.description', '/docs/references/messaging/create-fcm-provider.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_CREATED)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
@@ -476,8 +478,8 @@ App::post('/v1/messaging/providers/fcm')
|
||||
// Check if a default provider exists, if not, set this one as default
|
||||
if (
|
||||
empty($dbForProject->findOne('providers', [
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['push'])
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['push'])
|
||||
]))
|
||||
) {
|
||||
$provider->setAttribute('default', true);
|
||||
@@ -486,7 +488,7 @@ App::post('/v1/messaging/providers/fcm')
|
||||
try {
|
||||
$provider = $dbForProject->createDocument('providers', $provider);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS, 'Provider already exists.');
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
$response
|
||||
@@ -502,7 +504,7 @@ App::post('/v1/messaging/providers/apns')
|
||||
->label('scope', 'providers.write')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'messaging')
|
||||
->label('sdk.method', 'createAPNSProvider')
|
||||
->label('sdk.method', 'createApnsProvider')
|
||||
->label('sdk.description', '/docs/references/messaging/create-apns-provider.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_CREATED)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
@@ -540,8 +542,8 @@ App::post('/v1/messaging/providers/apns')
|
||||
// Check if a default provider exists, if not, set this one as default
|
||||
if (
|
||||
empty($dbForProject->findOne('providers', [
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['push'])
|
||||
Query::equal('default', [true]),
|
||||
Query::equal('type', ['push'])
|
||||
]))
|
||||
) {
|
||||
$provider->setAttribute('default', true);
|
||||
@@ -550,7 +552,7 @@ App::post('/v1/messaging/providers/apns')
|
||||
try {
|
||||
$provider = $dbForProject->createDocument('providers', $provider);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS, 'Provider already exists.');
|
||||
throw new Exception(Exception::PROVIDER_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
$response
|
||||
@@ -585,11 +587,11 @@ App::get('/v1/messaging/providers')
|
||||
Query::equal('$id', [$providerId]),
|
||||
]));
|
||||
|
||||
if (empty($cursorDocument) || $cursorDocument[0]->isEmpty()) {
|
||||
if ($cursorDocument === false || $cursorDocument->isEmpty()) {
|
||||
throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Provider '{$providerId}' for the 'cursor' value not found.");
|
||||
}
|
||||
|
||||
$cursor->setValue($cursorDocument[0]);
|
||||
$cursor->setValue($cursorDocument);
|
||||
}
|
||||
|
||||
$filterQueries = Query::groupByType($queries)['filters'];
|
||||
@@ -599,7 +601,7 @@ App::get('/v1/messaging/providers')
|
||||
]), Response::MODEL_PROVIDER_LIST);
|
||||
});
|
||||
|
||||
App::get('/v1/messaging/providers/:id')
|
||||
App::get('/v1/messaging/providers/:providerId')
|
||||
->desc('Get Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('scope', 'providers.read')
|
||||
@@ -610,11 +612,11 @@ App::get('/v1/messaging/providers/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -623,7 +625,7 @@ App::get('/v1/messaging/providers/:id')
|
||||
$response->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::patch('/v1/messaging/providers/mailgun/:id')
|
||||
App::patch('/v1/messaging/providers/mailgun/:providerId')
|
||||
->desc('Update Mailgun Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.update')
|
||||
@@ -636,7 +638,7 @@ App::patch('/v1/messaging/providers/mailgun/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->param('name', '', new Text(128), 'Provider name.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->param('isEuRegion', null, new Boolean(), 'Set as eu region.', true)
|
||||
@@ -645,8 +647,8 @@ App::patch('/v1/messaging/providers/mailgun/:id')
|
||||
->param('domain', '', new Text(0), 'Mailgun Domain.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, string $name, ?bool $enabled, ?bool $isEuRegion, string $from, string $apiKey, string $domain, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, ?bool $isEuRegion, string $from, string $apiKey, string $domain, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -654,7 +656,7 @@ App::patch('/v1/messaging/providers/mailgun/:id')
|
||||
$providerAttr = $provider->getAttribute('provider');
|
||||
|
||||
if ($providerAttr !== 'mailgun') {
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
@@ -694,7 +696,7 @@ App::patch('/v1/messaging/providers/mailgun/:id')
|
||||
->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::patch('/v1/messaging/providers/sendgrid/:id')
|
||||
App::patch('/v1/messaging/providers/sendgrid/:providerId')
|
||||
->desc('Update Sendgrid Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.update')
|
||||
@@ -707,14 +709,14 @@ App::patch('/v1/messaging/providers/sendgrid/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->param('name', '', new Text(128), 'Provider name.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->param('apiKey', '', new Text(0), 'Sendgrid API key.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, string $name, ?bool $enabled, string $apiKey, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $apiKey, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -722,7 +724,7 @@ App::patch('/v1/messaging/providers/sendgrid/:id')
|
||||
$providerAttr = $provider->getAttribute('provider');
|
||||
|
||||
if ($providerAttr !== 'sendgrid') {
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
@@ -746,7 +748,7 @@ App::patch('/v1/messaging/providers/sendgrid/:id')
|
||||
->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::patch('/v1/messaging/providers/msg91/:id')
|
||||
App::patch('/v1/messaging/providers/msg91/:providerId')
|
||||
->desc('Update Msg91 Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.update')
|
||||
@@ -759,15 +761,15 @@ App::patch('/v1/messaging/providers/msg91/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->param('name', '', new Text(128), 'Provider name.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->param('senderId', '', new Text(0), 'Msg91 Sender ID.', true)
|
||||
->param('authKey', '', new Text(0), 'Msg91 Auth Key.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, string $name, ?bool $enabled, string $senderId, string $authKey, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $senderId, string $authKey, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -775,7 +777,7 @@ App::patch('/v1/messaging/providers/msg91/:id')
|
||||
$providerAttr = $provider->getAttribute('provider');
|
||||
|
||||
if ($providerAttr !== 'msg91') {
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
@@ -805,7 +807,7 @@ App::patch('/v1/messaging/providers/msg91/:id')
|
||||
->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::patch('/v1/messaging/providers/telesign/:id')
|
||||
App::patch('/v1/messaging/providers/telesign/:providerId')
|
||||
->desc('Update Telesign Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.update')
|
||||
@@ -818,15 +820,15 @@ App::patch('/v1/messaging/providers/telesign/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->param('name', '', new Text(128), 'Provider name.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->param('username', '', new Text(0), 'Telesign username.', true)
|
||||
->param('password', '', new Text(0), 'Telesign password.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, string $name, ?bool $enabled, string $username, string $password, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $username, string $password, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -834,7 +836,7 @@ App::patch('/v1/messaging/providers/telesign/:id')
|
||||
$providerAttr = $provider->getAttribute('provider');
|
||||
|
||||
if ($providerAttr !== 'telesign') {
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
@@ -864,7 +866,7 @@ App::patch('/v1/messaging/providers/telesign/:id')
|
||||
->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::patch('/v1/messaging/providers/textmagic/:id')
|
||||
App::patch('/v1/messaging/providers/textmagic/:providerId')
|
||||
->desc('Update Textmagic Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.update')
|
||||
@@ -877,15 +879,15 @@ App::patch('/v1/messaging/providers/textmagic/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->param('name', '', new Text(128), 'Provider name.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->param('username', '', new Text(0), 'Textmagic username.', true)
|
||||
->param('apiKey', '', new Text(0), 'Textmagic apiKey.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, string $name, ?bool $enabled, string $username, string $apiKey, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $username, string $apiKey, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -893,7 +895,7 @@ App::patch('/v1/messaging/providers/textmagic/:id')
|
||||
$providerAttr = $provider->getAttribute('provider');
|
||||
|
||||
if ($providerAttr !== 'text-magic') {
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
@@ -923,7 +925,7 @@ App::patch('/v1/messaging/providers/textmagic/:id')
|
||||
->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::patch('/v1/messaging/providers/twilio/:id')
|
||||
App::patch('/v1/messaging/providers/twilio/:providerId')
|
||||
->desc('Update Twilio Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.update')
|
||||
@@ -936,15 +938,15 @@ App::patch('/v1/messaging/providers/twilio/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->param('name', '', new Text(128), 'Provider name.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->param('accountSid', null, new Text(0), 'Twilio account secret ID.', true)
|
||||
->param('authToken', null, new Text(0), 'Twilio authentication token.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, string $name, ?bool $enabled, string $accountSid, string $authToken, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $accountSid, string $authToken, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -952,7 +954,7 @@ App::patch('/v1/messaging/providers/twilio/:id')
|
||||
$providerAttr = $provider->getAttribute('provider');
|
||||
|
||||
if ($providerAttr !== 'twilio') {
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
@@ -982,7 +984,7 @@ App::patch('/v1/messaging/providers/twilio/:id')
|
||||
->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::patch('/v1/messaging/providers/vonage/:id')
|
||||
App::patch('/v1/messaging/providers/vonage/:providerId')
|
||||
->desc('Update Vonage Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.update')
|
||||
@@ -995,15 +997,15 @@ App::patch('/v1/messaging/providers/vonage/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->param('name', '', new Text(128), 'Provider name.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->param('apiKey', '', new Text(0), 'Vonage API key.', true)
|
||||
->param('apiSecret', '', new Text(0), 'Vonage API secret.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, string $name, ?bool $enabled, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -1011,7 +1013,7 @@ App::patch('/v1/messaging/providers/vonage/:id')
|
||||
$providerAttr = $provider->getAttribute('provider');
|
||||
|
||||
if ($providerAttr !== 'vonage') {
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
@@ -1041,7 +1043,7 @@ App::patch('/v1/messaging/providers/vonage/:id')
|
||||
->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::patch('/v1/messaging/providers/fcm/:id')
|
||||
App::patch('/v1/messaging/providers/fcm/:providerId')
|
||||
->desc('Update FCM Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.update')
|
||||
@@ -1049,19 +1051,19 @@ App::patch('/v1/messaging/providers/fcm/:id')
|
||||
->label('scope', 'providers.write')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'messaging')
|
||||
->label('sdk.method', 'updateFCMProvider')
|
||||
->label('sdk.method', 'updateFcmProvider')
|
||||
->label('sdk.description', '/docs/references/messaging/update-fcm-provider.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->param('name', '', new Text(128), 'Provider name.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->param('serverKey', '', new Text(0), 'FCM Server Key.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, string $name, ?bool $enabled, string $serverKey, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $serverKey, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -1069,7 +1071,7 @@ App::patch('/v1/messaging/providers/fcm/:id')
|
||||
$providerAttr = $provider->getAttribute('provider');
|
||||
|
||||
if ($providerAttr !== 'fcm') {
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
@@ -1092,7 +1094,7 @@ App::patch('/v1/messaging/providers/fcm/:id')
|
||||
});
|
||||
|
||||
|
||||
App::patch('/v1/messaging/providers/apns/:id')
|
||||
App::patch('/v1/messaging/providers/apns/:providerId')
|
||||
->desc('Update APNS Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.update')
|
||||
@@ -1100,12 +1102,12 @@ App::patch('/v1/messaging/providers/apns/:id')
|
||||
->label('scope', 'providers.write')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'messaging')
|
||||
->label('sdk.method', 'updateAPNSProvider')
|
||||
->label('sdk.method', 'updateApnsProvider')
|
||||
->label('sdk.description', '/docs/references/messaging/update-apns-provider.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->param('name', '', new Text(128), 'Provider name.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->param('authKey', '', new Text(0), 'APNS authentication key.', true)
|
||||
@@ -1115,8 +1117,8 @@ App::patch('/v1/messaging/providers/apns/:id')
|
||||
->param('endpoint', '', new Text(0), 'APNS endpoint.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, string $name, ?bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -1124,7 +1126,7 @@ App::patch('/v1/messaging/providers/apns/:id')
|
||||
$providerAttr = $provider->getAttribute('provider');
|
||||
|
||||
if ($providerAttr !== 'apns') {
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE . $providerAttr);
|
||||
throw new Exception(Exception::PROVIDER_INCORRECT_TYPE);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
@@ -1166,7 +1168,7 @@ App::patch('/v1/messaging/providers/apns/:id')
|
||||
->dynamic($provider, Response::MODEL_PROVIDER);
|
||||
});
|
||||
|
||||
App::delete('/v1/messaging/providers/:id')
|
||||
App::delete('/v1/messaging/providers/:providerId')
|
||||
->desc('Delete Provider')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'providers.delete')
|
||||
@@ -1179,11 +1181,11 @@ App::delete('/v1/messaging/providers/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_NONE)
|
||||
->param('id', '', new UID(), 'Provider ID.')
|
||||
->param('providerId', '', new UID(), 'Provider ID.')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $id);
|
||||
->action(function (string $providerId, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
throw new Exception(Exception::PROVIDER_NOT_FOUND);
|
||||
@@ -1552,13 +1554,14 @@ App::post('/v1/messaging/messages/email')
|
||||
->param('to', [], new ArrayList(new Text(Database::LENGTH_KEY)), 'List of Topic IDs or List of User IDs or List of Target IDs.')
|
||||
->param('subject', '', new Text(998), 'Email Subject.')
|
||||
->param('description', '', new Text(256), 'Description for Message.', true)
|
||||
->param('content', '', new Text(65407), 'Email Content.')
|
||||
->param('content', '', new Text(64230), 'Email Content.')
|
||||
->param('status', 'processing', new WhiteList(['draft', 'processing']), 'Message Status.', true)
|
||||
->param('html', false, new Boolean(), 'Is content of type HTML', true)
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('messaging')
|
||||
->inject('response')
|
||||
->action(function (string $messageId, string $providerId, array $to, string $subject, string $description, string $content, string $html, Database $dbForProject, Document $project, Messaging $messaging, Response $response) {
|
||||
->action(function (string $messageId, string $providerId, array $to, string $subject, string $description, string $content, string $status, bool $html, Database $dbForProject, Document $project, Messaging $messaging, Response $response) {
|
||||
$messageId = $messageId == 'unique()' ? ID::unique() : $messageId;
|
||||
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
@@ -1578,21 +1581,64 @@ App::post('/v1/messaging/messages/email')
|
||||
'html' => $html,
|
||||
'description' => $description,
|
||||
],
|
||||
'status' => 'processing',
|
||||
'status' => $status,
|
||||
'search' => $messageId . ' ' . $description . ' ' . $subject,
|
||||
]));
|
||||
|
||||
$messaging
|
||||
->setMessageId($message->getId())
|
||||
->setProject($project)
|
||||
->trigger();
|
||||
if ($status === 'processing') {
|
||||
$messaging
|
||||
->setMessageId($message->getId())
|
||||
->setProject($project)
|
||||
->trigger();
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($message, Response::MODEL_MESSAGE);
|
||||
});
|
||||
|
||||
App::get('/v1/messaging/messages/:id')
|
||||
App::get('/v1/messaging/messages')
|
||||
->desc('List Messages')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('scope', 'messages.read')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'messaging')
|
||||
->label('sdk.method', 'listMessages')
|
||||
->label('sdk.description', '/docs/references/messaging/list-messages.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_MESSAGE_LIST)
|
||||
->param('queries', [], new Providers(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Providers::ALLOWED_ATTRIBUTES), true)
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (array $queries, Database $dbForProject, Response $response) {
|
||||
$queries = Query::parseQueries($queries);
|
||||
|
||||
// Get cursor document if there was a cursor query
|
||||
$cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]);
|
||||
$cursor = reset($cursor);
|
||||
|
||||
if ($cursor) {
|
||||
$messageId = $cursor->getValue();
|
||||
$cursorDocument = Authorization::skip(fn () => $dbForProject->findOne('messages', [
|
||||
Query::equal('$id', [$messageId]),
|
||||
]));
|
||||
|
||||
if ($cursorDocument === false || $cursorDocument->isEmpty()) {
|
||||
throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Message '{$messageId}' for the 'cursor' value not found.");
|
||||
}
|
||||
|
||||
$cursor->setValue($cursorDocument);
|
||||
}
|
||||
|
||||
$filterQueries = Query::groupByType($queries)['filters'];
|
||||
$response->dynamic(new Document([
|
||||
'total' => $dbForProject->count('messages', $filterQueries, APP_LIMIT_COUNT),
|
||||
'messages' => $dbForProject->find('messages', $queries),
|
||||
]), Response::MODEL_MESSAGE_LIST);
|
||||
});
|
||||
|
||||
App::get('/v1/messaging/messages/:messageId')
|
||||
->desc('Get Message')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('scope', 'messages.read')
|
||||
@@ -1603,11 +1649,11 @@ App::get('/v1/messaging/messages/:id')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_MESSAGE)
|
||||
->param('id', '', new UID(), 'Message ID.')
|
||||
->param('messageId', '', new UID(), 'Message ID.')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $id, Database $dbForProject, Response $response) {
|
||||
$message = $dbForProject->getDocument('messages', $id);
|
||||
->action(function (string $messageId, Database $dbForProject, Response $response) {
|
||||
$message = $dbForProject->getDocument('messages', $messageId);
|
||||
|
||||
if ($message->isEmpty()) {
|
||||
throw new Exception(Exception::MESSAGE_NOT_FOUND);
|
||||
@@ -1615,3 +1661,79 @@ App::get('/v1/messaging/messages/:id')
|
||||
|
||||
$response->dynamic($message, Response::MODEL_MESSAGE);
|
||||
});
|
||||
|
||||
App::post('/v1/messaging/messages/email/:messageId')
|
||||
->desc('Update an email.')
|
||||
->groups(['api', 'messaging'])
|
||||
->label('audits.event', 'messages.update')
|
||||
->label('audits.resource', 'messages/{response.$id}')
|
||||
->label('scope', 'messages.write')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN, APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.namespace', 'messaging')
|
||||
->label('sdk.method', 'updateEmail')
|
||||
->label('sdk.description', '/docs/references/messaging/update-email.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_CREATED)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_MESSAGE)
|
||||
->param('messageId', '', new UID(), 'Message ID.')
|
||||
->param('to', [], new ArrayList(new Text(Database::LENGTH_KEY)), 'List of Topic IDs or List of User IDs or List of Target IDs.', true)
|
||||
->param('subject', '', new Text(998), 'Email Subject.', true)
|
||||
->param('description', '', new Text(256), 'Description for Message.', true)
|
||||
->param('content', '', new Text(64230), 'Email Content.', true)
|
||||
->param('status', '', new WhiteList(['draft', 'processing']), 'Message Status.', true)
|
||||
->param('html', false, new Boolean(), 'Is content of type HTML', true)
|
||||
->param('deliveryTime', DateTime::now(), new DatetimeValidator(), 'Delivery time for message.', true)
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->inject('messaging')
|
||||
->inject('response')
|
||||
->action(function (string $messageId, array $to, string $subject, string $description, string $content, string $status, bool $html, string $deliveryTime, Database $dbForProject, Document $project, Messaging $messaging, Response $response) {
|
||||
$message = $dbForProject->getDocument('messages', $messageId);
|
||||
|
||||
if ($message->isEmpty()) {
|
||||
throw new Exception(Exception::MESSAGE_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (\count($to) > 0) {
|
||||
$message->setAttribute('to', $to);
|
||||
}
|
||||
|
||||
$data = $message->getAttribute('data');
|
||||
|
||||
if (!empty($subject)) {
|
||||
$data['subject'] = $subject;
|
||||
}
|
||||
|
||||
if (!empty($content)) {
|
||||
$data['content'] = $content;
|
||||
}
|
||||
|
||||
if (!empty($description)) {
|
||||
$data['description'] = $description;
|
||||
}
|
||||
|
||||
if (!empty($html)) {
|
||||
$data['html'] = $html;
|
||||
}
|
||||
|
||||
$message->setAttribute('data', $data);
|
||||
$message->setAttribute('search', $message->getId() . ' ' . $data['description'] . ' ' . $data['subject']);
|
||||
|
||||
if (!empty($status)) {
|
||||
$message->setAttribute('status', $status);
|
||||
}
|
||||
|
||||
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
|
||||
|
||||
if ($status === 'processing') {
|
||||
$messaging
|
||||
->setMessageId($message->getId())
|
||||
->setDeliveryTime($deliveryTime)
|
||||
->setProject($project)
|
||||
->trigger();
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($message, Response::MODEL_MESSAGE);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user