1
0
Fork 0
mirror of synced 2024-10-02 10:16:27 +13:00

adds from field in remaining providers

This commit is contained in:
prateek banga 2023-10-24 01:05:46 +05:30
parent af40c63357
commit b60cbcada5
3 changed files with 92 additions and 21 deletions

View file

@ -106,12 +106,13 @@ App::post('/v1/messaging/providers/sendgrid')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
->param('name', '', new Text(128), 'Provider name.')
->param('from', '', new Text(256), 'Sender Email Address.')
->param('apiKey', '', new Text(0), 'Sendgrid API key.')
->param('default', false, new Boolean(), 'Set as default provider.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->param('apiKey', '', new Text(0), 'Sendgrid API key.')
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, bool $default, bool $enabled, string $apiKey, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, string $from, string $apiKey, bool $default, bool $enabled, Database $dbForProject, Response $response) {
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
$provider = new Document([
'$id' => $providerId,
@ -120,11 +121,13 @@ App::post('/v1/messaging/providers/sendgrid')
'type' => 'email',
'default' => $default,
'enabled' => $enabled,
'options' => [],
'search' => $providerId . ' ' . $name . ' ' . 'sendgrid' . ' ' . 'email',
'credentials' => [
'apiKey' => $apiKey,
],
'options' => [
'from' => $from,
]
]);
// Check if a default provider exists, if not, set this one as default
@ -225,13 +228,14 @@ App::post('/v1/messaging/providers/telesign')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
->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('from', '', new Text(256), 'Sender Number.')
->param('username', '', new Text(0), 'Telesign username.')
->param('password', '', new Text(0), 'Telesign password.')
->param('default', false, new Boolean(), 'Set as default provider.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, bool $default, bool $enabled, string $username, string $password, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, string $from, string $username, string $password, bool $default, bool $enabled, Database $dbForProject, Response $response) {
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
$provider = new Document([
'$id' => $providerId,
@ -245,6 +249,9 @@ App::post('/v1/messaging/providers/telesign')
'username' => $username,
'password' => $password,
],
'options' => [
'from' => $from,
]
]);
// Check if a default provider exists, if not, set this one as default
@ -283,13 +290,14 @@ App::post('/v1/messaging/providers/textmagic')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
->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('from', '', new Text(256), 'Sender Number.')
->param('username', '', new Text(0), 'Textmagic username.')
->param('apiKey', '', new Text(0), 'Textmagic apiKey.')
->param('default', false, new Boolean(), 'Set as default provider.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, bool $default, bool $enabled, string $username, string $apiKey, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, string $from, string $username, string $apiKey, bool $default, bool $enabled, Database $dbForProject, Response $response) {
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
$provider = new Document([
'$id' => $providerId,
@ -303,6 +311,9 @@ App::post('/v1/messaging/providers/textmagic')
'username' => $username,
'apiKey' => $apiKey,
],
'options' => [
'from' => $from,
]
]);
// Check if a default provider exists, if not, set this one as default
@ -341,13 +352,14 @@ App::post('/v1/messaging/providers/twilio')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
->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('from', '', new Text(256), 'Sender number.')
->param('accountSid', '', new Text(0), 'Twilio account secret ID.')
->param('authToken', '', new Text(0), 'Twilio authentication token.')
->param('default', false, new Boolean(), 'Set as default provider.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, bool $default, bool $enabled, string $accountSid, string $authToken, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, string $from, string $accountSid, string $authToken, bool $default, bool $enabled, Database $dbForProject, Response $response) {
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
$provider = new Document([
'$id' => $providerId,
@ -361,6 +373,9 @@ App::post('/v1/messaging/providers/twilio')
'accountSid' => $accountSid,
'authToken' => $authToken,
],
'options' => [
'from' => $from,
]
]);
// Check if a default provider exists, if not, set this one as default
@ -399,13 +414,14 @@ App::post('/v1/messaging/providers/vonage')
->label('sdk.response.model', Response::MODEL_PROVIDER)
->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
->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('from', '', new Text(256), 'Sender number.')
->param('apiKey', '', new Text(0), 'Vonage API key.')
->param('apiSecret', '', new Text(0), 'Vonage API secret.')
->param('default', false, new Boolean(), 'Set as default provider.', true)
->param('enabled', true, new Boolean(), 'Set as enabled.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, bool $default, bool $enabled, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, string $from, string $apiKey, string $apiSecret, bool $default, bool $enabled, Database $dbForProject, Response $response) {
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
$provider = new Document([
'$id' => $providerId,
@ -419,6 +435,9 @@ App::post('/v1/messaging/providers/vonage')
'apiKey' => $apiKey,
'apiSecret' => $apiSecret,
],
'options' => [
'from' => $from,
]
]);
// Check if a default provider exists, if not, set this one as default
@ -713,9 +732,10 @@ App::patch('/v1/messaging/providers/sendgrid/:providerId')
->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)
->param('from', '', new Text(256), 'Sender Email Address.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, ?bool $enabled, string $apiKey, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, ?bool $enabled, string $apiKey, string $from, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
@ -732,6 +752,12 @@ App::patch('/v1/messaging/providers/sendgrid/:providerId')
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'sendgrid' . ' ' . 'email');
}
if (!empty($from)) {
$provider->setAttribute('options', [
'from' => $from,
]);
}
if ($enabled === true || $enabled === false) {
$provider->setAttribute('enabled', $enabled);
}
@ -766,9 +792,10 @@ App::patch('/v1/messaging/providers/msg91/:providerId')
->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)
->param('from', '', new Text(256), 'Sender Number.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, ?bool $enabled, string $senderId, string $authKey, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, ?bool $enabled, string $senderId, string $authKey, string $from, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
@ -785,6 +812,12 @@ App::patch('/v1/messaging/providers/msg91/:providerId')
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'msg91' . ' ' . 'sms');
}
if (!empty($from)) {
$provider->setAttribute('options', [
'from' => $from,
]);
}
if ($enabled === true || $enabled === false) {
$provider->setAttribute('enabled', $enabled);
}
@ -825,9 +858,10 @@ App::patch('/v1/messaging/providers/telesign/:providerId')
->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)
->param('from', '', new Text(256), 'Sender Number.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, ?bool $enabled, string $username, string $password, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, ?bool $enabled, string $username, string $password, string $from, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
@ -844,6 +878,12 @@ App::patch('/v1/messaging/providers/telesign/:providerId')
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'telesign' . ' ' . 'sms');
}
if (!empty($from)) {
$provider->setAttribute('options', [
'from' => $from,
]);
}
if ($enabled === true || $enabled === false) {
$provider->setAttribute('enabled', $enabled);
}
@ -884,9 +924,10 @@ App::patch('/v1/messaging/providers/textmagic/:providerId')
->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)
->param('from', '', new Text(256), 'Sender Number.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, ?bool $enabled, string $username, string $apiKey, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, ?bool $enabled, string $username, string $apiKey, string $from, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
@ -903,6 +944,12 @@ App::patch('/v1/messaging/providers/textmagic/:providerId')
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'textmagic' . ' ' . 'sms');
}
if (!empty($from)) {
$provider->setAttribute('options', [
'from' => $from,
]);
}
if ($enabled === true || $enabled === false) {
$provider->setAttribute('enabled', $enabled);
}
@ -943,9 +990,10 @@ App::patch('/v1/messaging/providers/twilio/:providerId')
->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)
->param('from', '', new Text(256), 'Sender Number.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, ?bool $enabled, string $accountSid, string $authToken, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, ?bool $enabled, string $accountSid, string $authToken, string $from, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
@ -962,6 +1010,12 @@ App::patch('/v1/messaging/providers/twilio/:providerId')
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'twilio' . ' ' . 'sms');
}
if (!empty($from)) {
$provider->setAttribute('options', [
'from' => $from,
]);
}
if ($enabled === true || $enabled === false) {
$provider->setAttribute('enabled', $enabled);
}
@ -1002,9 +1056,10 @@ App::patch('/v1/messaging/providers/vonage/:providerId')
->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)
->param('from', '', new Text(256), 'Sender Number.', true)
->inject('dbForProject')
->inject('response')
->action(function (string $providerId, string $name, ?bool $enabled, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) {
->action(function (string $providerId, string $name, ?bool $enabled, string $apiKey, string $apiSecret, string $from, Database $dbForProject, Response $response) {
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
@ -1021,6 +1076,12 @@ App::patch('/v1/messaging/providers/vonage/:providerId')
$provider->setAttribute('search', $provider->getId() . ' ' . $name . ' ' . 'vonage' . ' ' . 'sms');
}
if (!empty($from)) {
$provider->setAttribute('options', [
'from' => $from,
]);
}
if ($enabled === true || $enabled === false) {
$provider->setAttribute('enabled', $enabled);
}

View file

@ -22,6 +22,7 @@ class MessagingTest extends Scope
'providerId' => ID::unique(),
'name' => 'Sengrid1',
'apiKey' => 'my-apikey',
'from' => 'sender-email@my-domain',
],
'Mailgun' => [
'providerId' => ID::unique(),
@ -35,18 +36,21 @@ class MessagingTest extends Scope
'name' => 'Twilio1',
'accountSid' => 'my-accountSid',
'authToken' => 'my-authToken',
'from' => '+123456789',
],
'Telesign' => [
'providerId' => ID::unique(),
'name' => 'Telesign1',
'username' => 'my-username',
'password' => 'my-password',
'from' => '+123456789',
],
'Textmagic' => [
'providerId' => ID::unique(),
'name' => 'Textmagic1',
'username' => 'my-username',
'apiKey' => 'my-apikey',
'from' => '+123456789',
],
'Msg91' => [
'providerId' => ID::unique(),
@ -60,6 +64,7 @@ class MessagingTest extends Scope
'name' => 'Vonage1',
'apiKey' => 'my-apikey',
'apiSecret' => 'my-apisecret',
'from' => '+123456789',
],
'Fcm' => [
'providerId' => ID::unique(),

View file

@ -15,6 +15,7 @@ trait MessagingBase
'providerId' => ID::unique(),
'name' => 'Sengrid1',
'apiKey' => 'my-apikey',
'from' => 'sender-email@my-domain',
],
'mailgun' => [
'providerId' => ID::unique(),
@ -28,18 +29,21 @@ trait MessagingBase
'name' => 'Twilio1',
'accountSid' => 'my-accountSid',
'authToken' => 'my-authToken',
'from' => '+123456789',
],
'telesign' => [
'providerId' => ID::unique(),
'name' => 'Telesign1',
'username' => 'my-username',
'password' => 'my-password',
'from' => '+123456789',
],
'textmagic' => [
'providerId' => ID::unique(),
'name' => 'Textmagic1',
'username' => 'my-username',
'apiKey' => 'my-apikey',
'from' => '+123456789',
],
'msg91' => [
'providerId' => ID::unique(),
@ -53,6 +57,7 @@ trait MessagingBase
'name' => 'Vonage1',
'apiKey' => 'my-apikey',
'apiSecret' => 'my-apisecret',
'from' => '+123456789',
],
'fcm' => [
'providerId' => ID::unique(),