1
0
Fork 0
mirror of synced 2024-07-01 20:50:49 +12:00

adds message description, options to mailgun provider

This commit is contained in:
Prateek Banga 2023-09-26 13:12:44 +05:30
parent df6466a1d3
commit a0858ccc4e
6 changed files with 72 additions and 12 deletions

View file

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

View file

@ -108,12 +108,13 @@ App::post('/v1/messaging/providers/mailgun')
->param('name', '', new Text(128), 'Provider name.') ->param('name', '', new Text(128), 'Provider name.')
->param('default', false, new Boolean(), 'Set as default provider.', true) ->param('default', false, new Boolean(), 'Set as default provider.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', 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('apiKey', '', new Text(0), 'Mailgun API Key.')
->param('domain', '', new Text(0), 'Mailgun Domain.') ->param('domain', '', new Text(0), 'Mailgun Domain.')
->inject('dbForProject') ->inject('dbForProject')
->inject('response') ->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; $providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
$provider = new Document([ $provider = new Document([
@ -129,6 +130,9 @@ App::post('/v1/messaging/providers/mailgun')
'domain' => $domain, 'domain' => $domain,
'isEuRegion' => $isEuRegion, 'isEuRegion' => $isEuRegion,
], ],
'options' => [
'from' => $from,
]
]); ]);
// Check if a default provider exists, if not, set this one as default // Check if a default provider exists, if not, set this one as default
@ -167,12 +171,13 @@ App::patch('/v1/messaging/providers/:id/mailgun')
->param('id', '', new UID(), 'Provider ID.') ->param('id', '', new UID(), 'Provider ID.')
->param('name', '', new Text(128), 'Provider name.', true) ->param('name', '', new Text(128), 'Provider name.', true)
->param('enabled', null, new Boolean(), 'Set as enabled.', 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('apiKey', '', new Text(0), 'Mailgun API Key.', true)
->param('domain', '', new Text(0), 'Mailgun Domain.', true) ->param('domain', '', new Text(0), 'Mailgun Domain.', true)
->inject('dbForProject') ->inject('dbForProject')
->inject('response') ->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); $provider = $dbForProject->getDocument('providers', $id);
if ($provider->isEmpty()) { if ($provider->isEmpty()) {
@ -198,6 +203,12 @@ App::patch('/v1/messaging/providers/:id/mailgun')
]); ]);
} }
if (!empty($from)) {
$provider->setAttribute('options', [
'from' => $from,
]);
}
if ($enabled === true || $enabled === false) { if ($enabled === true || $enabled === false) {
$provider->setAttribute('enabled', $enabled); $provider->setAttribute('enabled', $enabled);
} }
@ -1232,6 +1243,7 @@ App::post('/v1/messaging/messages/email')
->param('providerId', '', new Text(128), 'Email Provider ID.') ->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('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('subject', '', new Text(128), 'Email Subject.')
->param('description', '', new Text(256), 'Description for Message.')
->param('content', '', new Text(65407), 'Email Content.') ->param('content', '', new Text(65407), 'Email Content.')
->param('from', '', new Text(128), 'Email from.', true) ->param('from', '', new Text(128), 'Email from.', true)
->param('html', false, new Boolean(false), 'Is content of type HTML', true) ->param('html', false, new Boolean(false), 'Is content of type HTML', true)
@ -1239,7 +1251,7 @@ App::post('/v1/messaging/messages/email')
->inject('project') ->inject('project')
->inject('messaging') ->inject('messaging')
->inject('response') ->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; $messageId = $messageId == 'unique()' ? ID::unique() : $messageId;
$provider = $dbForProject->getDocument('providers', $providerId); $provider = $dbForProject->getDocument('providers', $providerId);
@ -1257,7 +1269,8 @@ App::post('/v1/messaging/messages/email')
'subject' => $subject, 'subject' => $subject,
'content' => $content, 'content' => $content,
'from' => $from, 'from' => $from,
'html' => $html 'html' => $html,
'description' => $description,
], ],
'status' => 'processing', 'status' => 'processing',
'search' => $subject . ' ' . $from, 'search' => $subject . ' ' . $from,

12
composer.lock generated
View file

@ -1318,16 +1318,16 @@
}, },
{ {
"name": "psr/http-client", "name": "psr/http-client",
"version": "1.0.2", "version": "1.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/http-client.git", "url": "https://github.com/php-fig/http-client.git",
"reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31" "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/0955afe48220520692d2d09f7ab7e0f93ffd6a31", "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90",
"reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31", "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1364,9 +1364,9 @@
"psr-18" "psr-18"
], ],
"support": { "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", "name": "psr/http-factory",

View file

@ -56,6 +56,13 @@ class Message extends Any
'description' => 'Status of delivery.', 'description' => 'Status of delivery.',
'default' => 'processing', 'default' => 'processing',
'example' => 'Message status can be one of the following: processing, sent, failed.', '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.', 'description' => 'Type of provider.',
'default' => '', 'default' => '',
'example' => 'sms', '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

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