adds messaging api controlle for mailgun provider
This commit is contained in:
parent
fe8b8d3dc6
commit
a6d613542b
|
@ -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',
|
||||
]
|
||||
];
|
||||
|
|
42
app/controllers/api/messaging.php
Normal file
42
app/controllers/api/messaging.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\App;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
/**
|
||||
* Email Providers
|
||||
*/
|
||||
App::post('/v1/messaging/providers/mailgun')
|
||||
->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);
|
||||
});
|
Loading…
Reference in a new issue