diff --git a/app/config/services.php b/app/config/services.php index e14a1d5781..f80431f784 100644 --- a/app/config/services.php +++ b/app/config/services.php @@ -225,4 +225,17 @@ return [ 'optional' => true, 'icon' => '/images/services/migrations.png', ], + 'messaging' => [ + 'key' => 'messaging', + 'name' => 'Messaging', + 'subtitle' => 'The Messaging service allows you to send messages to any provider type (SMTP, push notification, SMS, etc.).', + 'description' => '/docs/services/messaging.md', + 'controller' => 'api/messaging.php', + 'sdk' => true, + 'docs' => true, + 'docsUrl' => 'https://appwrite.io/docs/server/messaging', + 'tests' => false, + 'optional' => true, + 'icon' => '/images/services/messaging.png', + ] ]; diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php new file mode 100644 index 0000000000..2f0c50348a --- /dev/null +++ b/app/controllers/api/messaging.php @@ -0,0 +1,42 @@ +desc('Create Mailgun Provider') + ->groups(['api', 'messaging']) + ->label('event', 'messages.providers.create') + ->label('scope', 'providers.write') + ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN]) + ->label('sdk.namespace', 'messaging') + ->label('sdk.description', '/docs/references/messaging/create-provider-mailgun.md') + ->label('sdk.response.code', Response::STATUS_CODE_CREATED) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_PROVIDER) + ->param('name', '', new Text(128), 'Provider name.') + ->param('apiKey', null, new Text(0), 'Mailgun API Key.', true) + ->param('domain', null, new Text(0), 'Mailgun Domain.', true) + ->inject('dbForProject') + ->inject('response') + ->action(function (string $name, string $apiKey, string $domain, Database $dbForProject, Response $response) { + $provider = $dbForProject->getDocument('providers', '64e33e70dd07f0d03efb'); + $provider = $dbForProject->createDocument('providers', new Document([ + 'name' => $name, + 'provider' => 'Mailgun', + 'type' => 'email', + 'credentials' => [ + 'apiKey' => $apiKey, + 'domain' => $domain + ], + ])); + $response + ->setStatusCode(Response::STATUS_CODE_CREATED) + ->dynamic($provider, Response::MODEL_PROVIDER); + });