1
0
Fork 0
mirror of synced 2024-07-03 21:50:34 +12:00

Merge branch 'feat-mailgun-provider' of https://github.com/appwrite/appwrite into feat-topics-controller

This commit is contained in:
Prateek Banga 2023-09-27 16:57:07 +05:30
commit 63bd4d6daf
6 changed files with 72 additions and 12 deletions

View file

@ -1449,6 +1449,17 @@ $commonCollections = [
'array' => false,
'filters' => ['json', 'encrypt'],
],
[
'$id' => ID::custom('options'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => 16384,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => ['json'],
],
[
'$id' => ID::custom('search'),
'type' => Database::VAR_STRING,
@ -1534,6 +1545,17 @@ $commonCollections = [
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('description'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => 256,
'signed' => true,
'required' => false,
'default' => '',
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('status'),
'type' => Database::VAR_STRING,

View file

@ -109,12 +109,13 @@ App::post('/v1/messaging/providers/mailgun')
->param('name', '', new Text(128), 'Provider name.')
->param('default', false, new Boolean(), 'Set as default provider.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('isEuRegion', false, new Boolean(), 'Set as eu region.', true)
->param('isEuRegion', false, new Boolean(), 'Set as EU region.', true)
->param('from', '', new Text(256), 'Sender Email Address.')
->param('apiKey', '', new Text(0), 'Mailgun API Key.')
->param('domain', '', new Text(0), 'Mailgun Domain.')
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, bool $default, bool $enabled, bool $isEuRegion, string $apiKey, string $domain, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, bool $default, bool $enabled, bool $isEuRegion, string $from, string $apiKey, string $domain, Database $dbForProject, Response $response) {
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
$provider = new Document([
@ -130,6 +131,9 @@ App::post('/v1/messaging/providers/mailgun')
'domain' => $domain,
'isEuRegion' => $isEuRegion,
],
'options' => [
'from' => $from,
]
]);
// Check if a default provider exists, if not, set this one as default
@ -168,12 +172,13 @@ App::patch('/v1/messaging/providers/:id/mailgun')
->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
->param('isEuRegion', false, new Boolean(), 'Set as eu region.', true)
->param('isEuRegion', null, new Boolean(), 'Set as eu region.', true)
->param('from', '', new Text(256), 'Sender Email Address.', true)
->param('apiKey', '', new Text(0), 'Mailgun API Key.', true)
->param('domain', '', new Text(0), 'Mailgun Domain.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $id, string $name, ?bool $enabled, bool $isEuRegion, string $apiKey, string $domain, Database $dbForProject, Response $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);
if ($provider->isEmpty()) {
@ -199,6 +204,12 @@ App::patch('/v1/messaging/providers/:id/mailgun')
]);
}
if (!empty($from)) {
$provider->setAttribute('options', [
'from' => $from,
]);
}
if ($enabled === true || $enabled === false) {
$provider->setAttribute('enabled', $enabled);
}
@ -1573,6 +1584,7 @@ App::post('/v1/messaging/messages/email')
->param('providerId', '', new Text(128), 'Email Provider ID.')
->param('to', [], new ArrayList(new Text(65535)), 'List of Topic IDs or List of User IDs or List of Target IDs.')
->param('subject', '', new Text(128), 'Email Subject.')
->param('description', '', new Text(256), 'Description for Message.')
->param('content', '', new Text(65407), 'Email Content.')
->param('from', '', new Text(128), 'Email from.', true)
->param('html', false, new Boolean(false), 'Is content of type HTML', true)
@ -1580,7 +1592,7 @@ App::post('/v1/messaging/messages/email')
->inject('project')
->inject('messaging')
->inject('response')
->action(function (string $messageId, string $providerId, array $to, string $subject, string $content, string $from, 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 $from, string $html, Database $dbForProject, Document $project, Messaging $messaging, Response $response) {
$messageId = $messageId == 'unique()' ? ID::unique() : $messageId;
$provider = $dbForProject->getDocument('providers', $providerId);
@ -1598,7 +1610,8 @@ App::post('/v1/messaging/messages/email')
'subject' => $subject,
'content' => $content,
'from' => $from,
'html' => $html
'html' => $html,
'description' => $description,
],
'status' => 'processing',
'search' => $subject . ' ' . $from,

12
composer.lock generated
View file

@ -1318,16 +1318,16 @@
},
{
"name": "psr/http-client",
"version": "1.0.2",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-client.git",
"reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31"
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/0955afe48220520692d2d09f7ab7e0f93ffd6a31",
"reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90",
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90",
"shasum": ""
},
"require": {
@ -1364,9 +1364,9 @@
"psr-18"
],
"support": {
"source": "https://github.com/php-fig/http-client/tree/1.0.2"
"source": "https://github.com/php-fig/http-client"
},
"time": "2023-04-10T20:12:12+00:00"
"time": "2023-09-23T14:17:50+00:00"
},
{
"name": "psr/http-factory",

View file

@ -56,6 +56,13 @@ class Message extends Any
'description' => 'Status of delivery.',
'default' => 'processing',
'example' => 'Message status can be one of the following: processing, sent, failed.',
])
->addRule('description', [
'type' => self::TYPE_STRING,
'description' => 'Message description.',
'required' => false,
'default' => '',
'example' => 'Welcome Email.',
]);
}

View file

@ -45,6 +45,23 @@ class Provider extends Model
'description' => 'Type of provider.',
'default' => '',
'example' => 'sms',
])
->addRule('credentials', [
'type' => self::TYPE_JSON,
'description' => 'Provider credentials.',
'default' => [],
'example' => [
'key' => '123456789'
],
])
->addRule('options', [
'type' => self::TYPE_JSON,
'description' => 'Provider options.',
'default' => [],
'required' => false,
'example' => [
'from' => 'sender-email@mydomain'
],
]);
}

View file

@ -20,6 +20,7 @@ trait MessagingBase
'name' => 'Mailgun1',
'apiKey' => 'my-apikey',
'domain' => 'my-domain',
'from' => 'sender-email@my-domain',
],
'twilio' => [
'providerId' => 'unique()',