2023-08-21 22:44:50 +12:00
< ? php
2023-09-06 22:10:56 +12:00
use Appwrite\Event\Messaging ;
2023-08-22 04:45:15 +12:00
use Appwrite\Extend\Exception ;
2023-09-06 22:10:56 +12:00
use Appwrite\Permission ;
use Appwrite\Role ;
2023-08-25 08:15:17 +12:00
use Appwrite\Utopia\Database\Validator\CustomId ;
2023-08-23 04:45:31 +12:00
use Appwrite\Utopia\Database\Validator\Queries\Providers ;
2023-08-25 08:15:17 +12:00
use Appwrite\Utopia\Database\Validator\Queries\Topics ;
2023-08-21 22:44:50 +12:00
use Appwrite\Utopia\Response ;
use Utopia\App ;
use Utopia\Database\Database ;
use Utopia\Database\Document ;
2023-08-29 03:11:05 +12:00
use Utopia\Database\Exception\Duplicate as DuplicateException ;
2023-08-25 09:02:51 +12:00
use Utopia\Database\Helpers\ID ;
2023-08-23 04:45:31 +12:00
use Utopia\Database\Query ;
use Utopia\Database\Validator\Authorization ;
2023-09-06 22:10:56 +12:00
use Utopia\Database\Validator\Datetime as DatetimeValidator ;
2023-08-23 04:45:31 +12:00
use Utopia\Database\Validator\UID ;
2023-08-22 04:45:15 +12:00
use Utopia\Validator\ArrayList ;
2023-08-30 04:59:48 +12:00
use Utopia\Validator\Boolean ;
2023-09-06 05:10:48 +12:00
use Utopia\Validator\JSON ;
2023-08-21 22:44:50 +12:00
use Utopia\Validator\Text ;
2023-09-06 05:10:48 +12:00
use Utopia\Validator\WhiteList ;
2023-08-21 22:44:50 +12:00
App :: post ( '/v1/messaging/providers/mailgun' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Create Mailgun Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.create' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'createMailgunProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-mailgun-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_CREATED )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
2023-08-25 11:13:40 +12:00
-> 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.' )
2023-08-24 21:01:22 +12:00
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' )
2023-08-30 04:59:48 +12:00
-> param ( 'default' , false , new Boolean (), 'Set as default provider.' , true )
2023-09-14 00:17:38 +12:00
-> param ( 'enabled' , true , new Boolean (), 'Set as enabled.' , true )
2023-09-26 20:42:44 +13:00
-> param ( 'isEuRegion' , false , new Boolean (), 'Set as EU region.' , true )
-> param ( 'from' , '' , new Text ( 256 ), 'Sender Email Address.' )
2023-08-24 21:01:22 +12:00
-> param ( 'apiKey' , '' , new Text ( 0 ), 'Mailgun API Key.' )
-> param ( 'domain' , '' , new Text ( 0 ), 'Mailgun Domain.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-09-26 20:42:44 +13:00
-> action ( function ( string $providerId , string $name , bool $default , bool $enabled , bool $isEuRegion , string $from , string $apiKey , string $domain , Database $dbForProject , Response $response ) {
2023-08-25 11:16:15 +12:00
$providerId = $providerId == 'unique()' ? ID :: unique () : $providerId ;
2023-08-30 04:59:48 +12:00
$provider = new Document ([
2023-08-25 11:16:15 +12:00
'$id' => $providerId ,
'name' => $name ,
2023-08-24 21:01:22 +12:00
'provider' => 'mailgun' ,
'type' => 'email' ,
2023-08-30 04:59:48 +12:00
'default' => $default ,
2023-09-14 00:17:38 +12:00
'enabled' => $enabled ,
2023-09-19 22:06:40 +12:00
'search' => $providerId . ' ' . $name . ' ' . 'mailgun' . ' ' . 'email' ,
2023-08-24 21:01:22 +12:00
'credentials' => [
'apiKey' => $apiKey ,
'domain' => $domain ,
2023-09-19 22:06:40 +12:00
'isEuRegion' => $isEuRegion ,
2023-08-24 21:01:22 +12:00
],
2023-09-26 20:42:44 +13:00
'options' => [
'from' => $from ,
]
2023-08-30 04:59:48 +12:00
]);
// Check if a default provider exists, if not, set this one as default
if (
empty ( $dbForProject -> findOne ( 'providers' , [
Query :: equal ( 'default' , [ true ]),
2023-10-04 23:45:59 +13:00
Query :: equal ( 'type' , [ 'email' ])
2023-08-30 04:59:48 +12:00
]))
) {
$provider -> setAttribute ( 'default' , true );
}
try {
$provider = $dbForProject -> createDocument ( 'providers' , $provider );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: PROVIDER_ALREADY_EXISTS , 'Provider already exists.' );
}
2023-08-24 21:01:22 +12:00
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
App :: post ( '/v1/messaging/providers/sendgrid' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Create Sendgrid Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.create' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'createSendgridProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-sengrid-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_CREATED )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
2023-08-25 11:13:40 +12:00
-> 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.' )
2023-08-24 21:01:22 +12:00
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' )
2023-08-30 04:59:48 +12:00
-> param ( 'default' , false , new Boolean (), 'Set as default provider.' , true )
2023-09-14 00:17:38 +12:00
-> param ( 'enabled' , true , new Boolean (), 'Set as enabled.' , true )
2023-08-24 21:01:22 +12:00
-> param ( 'apiKey' , '' , new Text ( 0 ), 'Sendgrid API key.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-09-14 00:17:38 +12:00
-> action ( function ( string $providerId , string $name , bool $default , bool $enabled , string $apiKey , Database $dbForProject , Response $response ) {
2023-08-25 11:16:15 +12:00
$providerId = $providerId == 'unique()' ? ID :: unique () : $providerId ;
2023-08-30 04:59:48 +12:00
$provider = new Document ([
2023-08-25 11:16:15 +12:00
'$id' => $providerId ,
'name' => $name ,
2023-08-24 21:01:22 +12:00
'provider' => 'sendgrid' ,
'type' => 'email' ,
2023-08-30 04:59:48 +12:00
'default' => $default ,
2023-09-14 00:17:38 +12:00
'enabled' => $enabled ,
2023-09-28 02:28:00 +13:00
'options' => [],
2023-09-19 22:06:40 +12:00
'search' => $providerId . ' ' . $name . ' ' . 'sendgrid' . ' ' . 'email' ,
2023-08-24 21:01:22 +12:00
'credentials' => [
'apiKey' => $apiKey ,
],
2023-08-30 04:59:48 +12:00
]);
// Check if a default provider exists, if not, set this one as default
if (
empty ( $dbForProject -> findOne ( 'providers' , [
Query :: equal ( 'default' , [ true ]),
2023-10-04 23:45:59 +13:00
Query :: equal ( 'type' , [ 'sms' ])
2023-08-30 04:59:48 +12:00
]))
) {
$provider -> setAttribute ( 'default' , true );
}
try {
$provider = $dbForProject -> createDocument ( 'providers' , $provider );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: PROVIDER_ALREADY_EXISTS , 'Provider already exists.' );
}
2023-08-24 21:01:22 +12:00
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
App :: post ( '/v1/messaging/providers/msg91' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Create Msg91 Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.create' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'createMsg91Provider' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-msg91-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_CREATED )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
2023-08-25 11:16:15 +12:00
-> 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.' )
2023-08-24 21:01:22 +12:00
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' )
2023-08-30 04:59:48 +12:00
-> param ( 'default' , false , new Boolean (), 'Set as default provider.' , true )
2023-09-14 00:17:38 +12:00
-> param ( 'enabled' , true , new Boolean (), 'Set as enabled.' , true )
2023-09-28 02:28:00 +13:00
-> param ( 'from' , '' , new Text ( 256 ), 'Sender Number.' )
2023-08-24 21:01:22 +12:00
-> param ( 'senderId' , '' , new Text ( 0 ), 'Msg91 Sender ID.' )
-> param ( 'authKey' , '' , new Text ( 0 ), 'Msg91 Auth Key.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-09-28 02:28:00 +13:00
-> action ( function ( string $providerId , string $name , bool $default , bool $enabled , string $from , string $senderId , string $authKey , Database $dbForProject , Response $response ) {
2023-08-25 11:16:15 +12:00
$providerId = $providerId == 'unique()' ? ID :: unique () : $providerId ;
2023-08-30 04:59:48 +12:00
$provider = new Document ([
2023-08-25 11:16:15 +12:00
'$id' => $providerId ,
'name' => $name ,
2023-08-24 21:01:22 +12:00
'provider' => 'msg91' ,
'type' => 'sms' ,
2023-09-19 22:06:40 +12:00
'search' => $providerId . ' ' . $name . ' ' . 'msg91' . ' ' . 'sms' ,
2023-08-30 04:59:48 +12:00
'default' => $default ,
2023-09-14 00:17:38 +12:00
'enabled' => $enabled ,
2023-08-24 21:01:22 +12:00
'credentials' => [
'senderId' => $senderId ,
'authKey' => $authKey ,
],
2023-09-28 02:28:00 +13:00
'options' => [
'from' => $from ,
]
2023-08-30 04:59:48 +12:00
]);
// Check if a default provider exists, if not, set this one as default
if (
empty ( $dbForProject -> findOne ( 'providers' , [
2023-10-04 23:45:59 +13:00
Query :: equal ( 'default' , [ true ]),
Query :: equal ( 'type' , [ 'sms' ])
2023-08-30 04:59:48 +12:00
]))
) {
$provider -> setAttribute ( 'default' , true );
}
try {
$provider = $dbForProject -> createDocument ( 'providers' , $provider );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: PROVIDER_ALREADY_EXISTS , 'Provider already exists.' );
}
2023-08-24 21:01:22 +12:00
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
App :: post ( '/v1/messaging/providers/telesign' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Create Telesign Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.create' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'createTelesignProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-telesign-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_CREATED )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
2023-08-25 11:13:40 +12:00
-> 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.' )
2023-08-24 21:01:22 +12:00
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' )
2023-08-30 04:59:48 +12:00
-> param ( 'default' , false , new Boolean (), 'Set as default provider.' , true )
2023-09-14 00:17:38 +12:00
-> param ( 'enabled' , true , new Boolean (), 'Set as enabled.' , true )
2023-08-24 21:01:22 +12:00
-> param ( 'username' , '' , new Text ( 0 ), 'Telesign username.' )
-> param ( 'password' , '' , new Text ( 0 ), 'Telesign password.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-09-14 00:17:38 +12:00
-> action ( function ( string $providerId , string $name , bool $default , bool $enabled , string $username , string $password , Database $dbForProject , Response $response ) {
2023-08-25 11:16:15 +12:00
$providerId = $providerId == 'unique()' ? ID :: unique () : $providerId ;
2023-08-30 04:59:48 +12:00
$provider = new Document ([
2023-08-25 11:16:15 +12:00
'$id' => $providerId ,
'name' => $name ,
2023-08-24 21:01:22 +12:00
'provider' => 'telesign' ,
'type' => 'sms' ,
2023-09-19 22:06:40 +12:00
'search' => $providerId . ' ' . $name . ' ' . 'telesign' . ' ' . 'sms' ,
2023-08-30 04:59:48 +12:00
'default' => $default ,
2023-09-14 00:17:38 +12:00
'enabled' => $enabled ,
2023-08-24 21:01:22 +12:00
'credentials' => [
'username' => $username ,
'password' => $password ,
],
2023-08-30 04:59:48 +12:00
]);
// Check if a default provider exists, if not, set this one as default
if (
empty ( $dbForProject -> findOne ( 'providers' , [
Query :: equal ( 'default' , [ true ]),
2023-10-04 23:45:59 +13:00
Query :: equal ( 'type' , [ 'sms' ])
2023-08-30 04:59:48 +12:00
]))
) {
$provider -> setAttribute ( 'default' , true );
}
try {
$provider = $dbForProject -> createDocument ( 'providers' , $provider );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: PROVIDER_ALREADY_EXISTS , 'Provider already exists.' );
}
2023-08-24 21:01:22 +12:00
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
2023-10-04 23:45:59 +13:00
App :: post ( '/v1/messaging/providers/textmagic' )
-> desc ( 'Create Textmagic Provider' )
2023-08-24 21:01:22 +12:00
-> groups ([ 'api' , 'messaging' ])
2023-10-04 23:45:59 +13:00
-> label ( 'audits.event' , 'providers.create' )
2023-08-24 21:01:22 +12:00
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'createTextmagicProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-textmagic-provider.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_CREATED )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
2023-10-04 23:45:59 +13:00
-> 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 ( 'username' , '' , new Text ( 0 ), 'Textmagic username.' )
-> param ( 'apiKey' , '' , new Text ( 0 ), 'Textmagic apiKey.' )
2023-08-24 21:01:22 +12:00
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-10-04 23:45:59 +13:00
-> action ( function ( string $providerId , string $name , bool $default , bool $enabled , string $username , string $apiKey , Database $dbForProject , Response $response ) {
$providerId = $providerId == 'unique()' ? ID :: unique () : $providerId ;
$provider = new Document ([
'$id' => $providerId ,
'name' => $name ,
'provider' => 'text-magic' ,
'type' => 'sms' ,
'search' => $providerId . ' ' . $name . ' ' . 'text-magic' . ' ' . 'sms' ,
'default' => $default ,
'enabled' => $enabled ,
'credentials' => [
'username' => $username ,
'apiKey' => $apiKey ,
],
]);
2023-08-24 21:01:22 +12:00
2023-10-04 23:45:59 +13:00
// Check if a default provider exists, if not, set this one as default
if (
empty ( $dbForProject -> findOne ( 'providers' , [
Query :: equal ( 'default' , [ true ]),
Query :: equal ( 'type' , [ 'sms' ])
]))
) {
$provider -> setAttribute ( 'default' , true );
2023-08-24 21:01:22 +12:00
}
2023-10-04 23:45:59 +13:00
try {
$provider = $dbForProject -> createDocument ( 'providers' , $provider );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: PROVIDER_ALREADY_EXISTS , 'Provider already exists.' );
2023-09-14 00:17:38 +12:00
}
2023-10-04 23:45:59 +13:00
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
App :: post ( '/v1/messaging/providers/twilio' )
-> desc ( 'Create Twilio Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.create' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'createTwilioProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-twilio-provider.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 ( '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 ( 'accountSid' , '' , new Text ( 0 ), 'Twilio account secret ID.' )
-> param ( 'authToken' , '' , new Text ( 0 ), 'Twilio authentication token.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $providerId , string $name , bool $default , bool $enabled , string $accountSid , string $authToken , Database $dbForProject , Response $response ) {
$providerId = $providerId == 'unique()' ? ID :: unique () : $providerId ;
$provider = new Document ([
'$id' => $providerId ,
'name' => $name ,
'provider' => 'twilio' ,
'type' => 'sms' ,
'search' => $providerId . ' ' . $name . ' ' . 'twilio' . ' ' . 'sms' ,
'default' => $default ,
'enabled' => $enabled ,
'credentials' => [
'accountSid' => $accountSid ,
'authToken' => $authToken ,
],
]);
// Check if a default provider exists, if not, set this one as default
if (
empty ( $dbForProject -> findOne ( 'providers' , [
Query :: equal ( 'default' , [ true ]),
Query :: equal ( 'type' , [ 'sms' ])
]))
) {
$provider -> setAttribute ( 'default' , true );
2023-08-24 21:01:22 +12:00
}
2023-08-24 08:23:52 +12:00
2023-10-04 23:45:59 +13:00
try {
$provider = $dbForProject -> createDocument ( 'providers' , $provider );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: PROVIDER_ALREADY_EXISTS , 'Provider already exists.' );
}
2023-08-24 21:01:22 +12:00
$response
2023-10-04 23:45:59 +13:00
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
2023-08-24 21:01:22 +12:00
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
2023-10-04 23:45:59 +13:00
App :: post ( '/v1/messaging/providers/vonage' )
-> desc ( 'Create Vonage Provider' )
2023-08-24 21:01:22 +12:00
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.create' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'createVonageProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-vonage-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_CREATED )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
2023-08-25 11:13:40 +12:00
-> 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.' )
2023-08-24 21:01:22 +12:00
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' )
2023-08-30 04:59:48 +12:00
-> param ( 'default' , false , new Boolean (), 'Set as default provider.' , true )
2023-09-14 00:17:38 +12:00
-> param ( 'enabled' , true , new Boolean (), 'Set as enabled.' , true )
2023-10-04 23:45:59 +13:00
-> param ( 'apiKey' , '' , new Text ( 0 ), 'Vonage API key.' )
-> param ( 'apiSecret' , '' , new Text ( 0 ), 'Vonage API secret.' )
2023-08-24 21:01:22 +12:00
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-10-04 23:45:59 +13:00
-> action ( function ( string $providerId , string $name , bool $default , bool $enabled , string $apiKey , string $apiSecret , Database $dbForProject , Response $response ) {
2023-08-25 11:16:15 +12:00
$providerId = $providerId == 'unique()' ? ID :: unique () : $providerId ;
2023-08-30 04:59:48 +12:00
$provider = new Document ([
2023-08-25 11:16:15 +12:00
'$id' => $providerId ,
'name' => $name ,
2023-10-04 23:45:59 +13:00
'provider' => 'vonage' ,
2023-08-24 21:01:22 +12:00
'type' => 'sms' ,
2023-10-04 23:45:59 +13:00
'search' => $providerId . ' ' . $name . ' ' . 'vonage' . ' ' . 'sms' ,
2023-08-30 04:59:48 +12:00
'default' => $default ,
2023-09-14 00:17:38 +12:00
'enabled' => $enabled ,
2023-08-24 21:01:22 +12:00
'credentials' => [
'apiKey' => $apiKey ,
2023-10-04 23:45:59 +13:00
'apiSecret' => $apiSecret ,
2023-08-24 21:01:22 +12:00
],
2023-08-30 04:59:48 +12:00
]);
// Check if a default provider exists, if not, set this one as default
if (
empty ( $dbForProject -> findOne ( 'providers' , [
Query :: equal ( 'default' , [ true ]),
2023-10-04 23:45:59 +13:00
Query :: equal ( 'type' , [ 'sms' ])
2023-08-30 04:59:48 +12:00
]))
) {
$provider -> setAttribute ( 'default' , true );
}
try {
$provider = $dbForProject -> createDocument ( 'providers' , $provider );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: PROVIDER_ALREADY_EXISTS , 'Provider already exists.' );
}
2023-08-24 21:01:22 +12:00
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-22 04:45:15 +12:00
2023-10-04 23:45:59 +13:00
App :: post ( '/v1/messaging/providers/fcm' )
-> desc ( 'Create FCM Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.create' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'createFCMProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-fcm-provider.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 ( '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 ( 'serverKey' , '' , new Text ( 0 ), 'FCM Server Key.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $providerId , string $name , bool $default , bool $enabled , string $serverKey , Database $dbForProject , Response $response ) {
$providerId = $providerId == 'unique()' ? ID :: unique () : $providerId ;
$provider = new Document ([
'$id' => $providerId ,
'name' => $name ,
'provider' => 'fcm' ,
'type' => 'push' ,
'search' => $providerId . ' ' . $name . ' ' . 'fcm' . ' ' . 'push' ,
'default' => $default ,
'enabled' => $enabled ,
'credentials' => [
'serverKey' => $serverKey ,
2023-08-24 21:01:22 +12:00
],
2023-08-30 04:59:48 +12:00
]);
// Check if a default provider exists, if not, set this one as default
if (
empty ( $dbForProject -> findOne ( 'providers' , [
Query :: equal ( 'default' , [ true ]),
2023-10-04 23:49:05 +13:00
Query :: equal ( 'type' , [ 'push' ])
2023-08-30 04:59:48 +12:00
]))
) {
$provider -> setAttribute ( 'default' , true );
}
2023-10-04 23:45:59 +13:00
try {
$provider = $dbForProject -> createDocument ( 'providers' , $provider );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: PROVIDER_ALREADY_EXISTS , 'Provider already exists.' );
}
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
App :: post ( '/v1/messaging/providers/apns' )
-> desc ( 'Create APNS Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.create' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'createAPNSProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-apns-provider.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 ( '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 ( 'authKey' , '' , new Text ( 0 ), 'APNS authentication key.' )
-> param ( 'authKeyId' , '' , new Text ( 0 ), 'APNS authentication key ID.' )
-> param ( 'teamId' , '' , new Text ( 0 ), 'APNS team ID.' )
-> param ( 'bundleId' , '' , new Text ( 0 ), 'APNS bundle ID.' )
-> param ( 'endpoint' , '' , new Text ( 0 ), 'APNS endpoint.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $providerId , string $name , bool $default , bool $enabled , string $authKey , string $authKeyId , string $teamId , string $bundleId , string $endpoint , Database $dbForProject , Response $response ) {
$providerId = $providerId == 'unique()' ? ID :: unique () : $providerId ;
$provider = new Document ([
'$id' => $providerId ,
'name' => $name ,
'provider' => 'apns' ,
'type' => 'push' ,
'search' => $providerId . ' ' . $name . ' ' . 'apns' . ' ' . 'push' ,
'default' => $default ,
'enabled' => $enabled ,
'credentials' => [
'authKey' => $authKey ,
'authKeyId' => $authKeyId ,
'teamId' => $teamId ,
'bundleId' => $bundleId ,
'endpoint' => $endpoint ,
],
]);
// Check if a default provider exists, if not, set this one as default
if (
empty ( $dbForProject -> findOne ( 'providers' , [
Query :: equal ( 'default' , [ true ]),
Query :: equal ( 'type' , [ 'push' ])
]))
) {
$provider -> setAttribute ( 'default' , true );
}
try {
$provider = $dbForProject -> createDocument ( 'providers' , $provider );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: PROVIDER_ALREADY_EXISTS , 'Provider already exists.' );
}
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
App :: get ( '/v1/messaging/providers' )
-> desc ( 'List Providers' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'scope' , 'providers.read' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'listProviders' )
-> label ( 'sdk.description' , '/docs/references/messaging/list-providers.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER_LIST )
-> param ( 'queries' , [], new Providers (), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode ( ', ' , Providers :: ALLOWED_ATTRIBUTES ), true )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( array $queries , Database $dbForProject , Response $response ) {
$queries = Query :: parseQueries ( $queries );
// Get cursor document if there was a cursor query
$cursor = Query :: getByType ( $queries , [ Query :: TYPE_CURSORAFTER , Query :: TYPE_CURSORBEFORE ]);
$cursor = reset ( $cursor );
if ( $cursor ) {
$providerId = $cursor -> getValue ();
$cursorDocument = Authorization :: skip ( fn () => $dbForProject -> findOne ( 'providers' , [
Query :: equal ( '$id' , [ $providerId ]),
]));
if ( empty ( $cursorDocument ) || $cursorDocument [ 0 ] -> isEmpty ()) {
throw new Exception ( Exception :: GENERAL_CURSOR_NOT_FOUND , " Provider ' { $providerId } ' for the 'cursor' value not found. " );
}
$cursor -> setValue ( $cursorDocument [ 0 ]);
}
$filterQueries = Query :: groupByType ( $queries )[ 'filters' ];
$response -> dynamic ( new Document ([
'total' => $dbForProject -> count ( 'providers' , $filterQueries , APP_LIMIT_COUNT ),
'providers' => $dbForProject -> find ( 'providers' , $queries ),
]), Response :: MODEL_PROVIDER_LIST );
});
App :: get ( '/v1/messaging/providers/:id' )
-> desc ( 'Get Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'scope' , 'providers.read' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'getProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/get-provider.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $id , Database $dbForProject , Response $response ) {
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
}
$response -> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
App :: patch ( '/v1/messaging/providers/mailgun/:id' )
-> desc ( 'Update Mailgun Provider' )
2023-08-24 21:01:22 +12:00
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.update' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'updateMailgunProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-mailgun-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' , true )
2023-09-20 22:25:22 +12:00
-> param ( 'enabled' , null , new Boolean (), 'Set as enabled.' , true )
2023-10-04 23:45:59 +13:00
-> 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 )
2023-08-24 21:01:22 +12:00
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-10-04 23:45:59 +13:00
-> action ( function ( string $id , string $name , ? bool $enabled , ? bool $isEuRegion , string $from , string $apiKey , string $domain , Database $dbForProject , Response $response ) {
2023-08-24 21:01:22 +12:00
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
2023-08-24 08:23:52 +12:00
}
2023-08-24 21:01:22 +12:00
$providerAttr = $provider -> getAttribute ( 'provider' );
2023-08-24 08:23:52 +12:00
2023-10-04 23:45:59 +13:00
if ( $providerAttr !== 'mailgun' ) {
2023-08-25 11:16:15 +12:00
throw new Exception ( Exception :: PROVIDER_INCORRECT_TYPE . $providerAttr );
2023-08-24 21:01:22 +12:00
}
2023-08-24 08:23:52 +12:00
2023-09-20 22:25:22 +12:00
if ( ! empty ( $name )) {
2023-08-24 21:01:22 +12:00
$provider -> setAttribute ( 'name' , $name );
2023-10-04 23:45:59 +13:00
$provider -> setAttribute ( 'search' , $provider -> getId () . ' ' . $name . ' ' . 'mailgun' . ' ' . 'email' );
}
if ( ! empty ( $from )) {
$provider -> setAttribute ( 'options' , [
'from' => $from ,
]);
2023-08-24 21:01:22 +12:00
}
2023-09-19 22:06:40 +12:00
if ( $enabled === true || $enabled === false ) {
2023-09-14 00:17:38 +12:00
$provider -> setAttribute ( 'enabled' , $enabled );
}
2023-10-04 23:45:59 +13:00
$credentials = $provider -> getAttribute ( 'credentials' );
if ( $isEuRegion === true || $isEuRegion === false ) {
$credentials [ 'isEuRegion' ] = $isEuRegion ;
}
if ( ! empty ( $apiKey )) {
$credentials [ 'apiKey' ] = $apiKey ;
}
if ( ! empty ( $domain )) {
$credentials [ 'domain' ] = $domain ;
2023-08-24 21:01:22 +12:00
}
2023-10-04 23:45:59 +13:00
$provider -> setAttribute ( 'credentials' , $credentials );
2023-08-24 21:01:22 +12:00
$provider = $dbForProject -> updateDocument ( 'providers' , $provider -> getId (), $provider );
$response
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
2023-10-04 23:45:59 +13:00
App :: patch ( '/v1/messaging/providers/sendgrid/:id' )
-> desc ( 'Update Sendgrid Provider' )
2023-08-24 21:01:22 +12:00
-> groups ([ 'api' , 'messaging' ])
2023-10-04 23:45:59 +13:00
-> label ( 'audits.event' , 'providers.update' )
2023-08-24 21:01:22 +12:00
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'updateSendgridProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-sendgrid-provider.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
2023-10-04 23:45:59 +13:00
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> 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 )
2023-08-24 21:01:22 +12:00
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-10-04 23:45:59 +13:00
-> action ( function ( string $id , string $name , ? bool $enabled , string $apiKey , Database $dbForProject , Response $response ) {
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
}
$providerAttr = $provider -> getAttribute ( 'provider' );
if ( $providerAttr !== 'sendgrid' ) {
throw new Exception ( Exception :: PROVIDER_INCORRECT_TYPE . $providerAttr );
}
if ( ! empty ( $name )) {
$provider -> setAttribute ( 'name' , $name );
$provider -> setAttribute ( 'search' , $provider -> getId () . ' ' . $name . ' ' . 'sendgrid' . ' ' . 'email' );
}
if ( $enabled === true || $enabled === false ) {
$provider -> setAttribute ( 'enabled' , $enabled );
}
if ( ! empty ( $apiKey )) {
$provider -> setAttribute ( 'credentials' , [
'apiKey' => $apiKey ,
]);
}
$provider = $dbForProject -> updateDocument ( 'providers' , $provider -> getId (), $provider );
$response
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
App :: patch ( '/v1/messaging/providers/msg91/:id' )
-> desc ( 'Update Msg91 Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.update' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'updateMsg91Provider' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-msg91-provider.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' , true )
-> 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 )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $id , string $name , ? bool $enabled , string $senderId , string $authKey , Database $dbForProject , Response $response ) {
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
}
$providerAttr = $provider -> getAttribute ( 'provider' );
if ( $providerAttr !== 'msg91' ) {
throw new Exception ( Exception :: PROVIDER_INCORRECT_TYPE . $providerAttr );
}
if ( ! empty ( $name )) {
$provider -> setAttribute ( 'name' , $name );
$provider -> setAttribute ( 'search' , $provider -> getId () . ' ' . $name . ' ' . 'msg91' . ' ' . 'sms' );
}
if ( $enabled === true || $enabled === false ) {
$provider -> setAttribute ( 'enabled' , $enabled );
}
$credentials = $provider -> getAttribute ( 'credentials' );
if ( ! empty ( $senderId )) {
$credentials [ 'senderId' ] = $senderId ;
}
if ( ! empty ( $authKey )) {
$credentials [ 'authKey' ] = $authKey ;
}
$provider -> setAttribute ( 'credentials' , $credentials );
$provider = $dbForProject -> updateDocument ( 'providers' , $provider -> getId (), $provider );
$response
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
App :: patch ( '/v1/messaging/providers/telesign/:id' )
-> desc ( 'Update Telesign Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.update' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'updateTelesignProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-telesign-provider.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' , true )
-> 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 )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $id , string $name , ? bool $enabled , string $username , string $password , Database $dbForProject , Response $response ) {
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
}
$providerAttr = $provider -> getAttribute ( 'provider' );
if ( $providerAttr !== 'telesign' ) {
throw new Exception ( Exception :: PROVIDER_INCORRECT_TYPE . $providerAttr );
}
if ( ! empty ( $name )) {
$provider -> setAttribute ( 'name' , $name );
$provider -> setAttribute ( 'search' , $provider -> getId () . ' ' . $name . ' ' . 'telesign' . ' ' . 'sms' );
}
if ( $enabled === true || $enabled === false ) {
$provider -> setAttribute ( 'enabled' , $enabled );
}
$credentials = $provider -> getAttribute ( 'credentials' );
if ( ! empty ( $username )) {
$credentials [ 'username' ] = $username ;
}
if ( ! empty ( $password )) {
$credentials [ 'password' ] = $password ;
2023-08-30 04:59:48 +12:00
}
2023-10-04 23:45:59 +13:00
$provider -> setAttribute ( 'credentials' , $credentials );
$provider = $dbForProject -> updateDocument ( 'providers' , $provider -> getId (), $provider );
2023-08-24 21:01:22 +12:00
$response
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-22 04:45:15 +12:00
2023-10-04 23:45:59 +13:00
App :: patch ( '/v1/messaging/providers/textmagic/:id' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Update Textmagic Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.update' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'updateTextmagicProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-textmagic-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' , true )
2023-09-20 22:25:22 +12:00
-> param ( 'enabled' , null , new Boolean (), 'Set as enabled.' , true )
2023-08-24 21:01:22 +12:00
-> param ( 'username' , '' , new Text ( 0 ), 'Textmagic username.' , true )
-> param ( 'apiKey' , '' , new Text ( 0 ), 'Textmagic apiKey.' , true )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-09-20 22:25:22 +12:00
-> action ( function ( string $id , string $name , ? bool $enabled , string $username , string $apiKey , Database $dbForProject , Response $response ) {
2023-08-24 21:01:22 +12:00
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
2023-08-24 08:23:52 +12:00
}
2023-08-24 21:01:22 +12:00
$providerAttr = $provider -> getAttribute ( 'provider' );
2023-08-24 08:23:52 +12:00
2023-08-24 21:01:22 +12:00
if ( $providerAttr !== 'text-magic' ) {
2023-08-25 08:15:17 +12:00
throw new Exception ( Exception :: PROVIDER_INCORRECT_TYPE . $providerAttr );
2023-08-24 21:01:22 +12:00
}
2023-08-24 08:23:52 +12:00
2023-09-20 22:25:22 +12:00
if ( ! empty ( $name )) {
2023-08-24 21:01:22 +12:00
$provider -> setAttribute ( 'name' , $name );
2023-09-19 22:06:40 +12:00
$provider -> setAttribute ( 'search' , $provider -> getId () . ' ' . $name . ' ' . 'textmagic' . ' ' . 'sms' );
2023-08-24 21:01:22 +12:00
}
2023-09-19 22:06:40 +12:00
if ( $enabled === true || $enabled === false ) {
2023-09-14 00:17:38 +12:00
$provider -> setAttribute ( 'enabled' , $enabled );
}
2023-10-04 23:45:59 +13:00
$credentials = $provider -> getAttribute ( 'credentials' );
2023-08-30 04:59:48 +12:00
2023-10-04 23:45:59 +13:00
if ( ! empty ( $username )) {
$credentials [ 'username' ] = $username ;
2023-08-30 04:59:48 +12:00
}
2023-10-04 23:45:59 +13:00
if ( ! empty ( $apiKey )) {
$credentials [ 'apiKey' ] = $apiKey ;
2023-08-30 04:59:48 +12:00
}
2023-10-04 23:45:59 +13:00
$provider -> setAttribute ( 'credentials' , $credentials );
$provider = $dbForProject -> updateDocument ( 'providers' , $provider -> getId (), $provider );
2023-08-24 21:01:22 +12:00
$response
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
2023-10-04 23:45:59 +13:00
App :: patch ( '/v1/messaging/providers/twilio/:id' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Update Twilio Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.update' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'updateTwilioProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-twilio-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' , true )
2023-09-20 22:25:22 +12:00
-> param ( 'enabled' , null , new Boolean (), 'Set as enabled.' , true )
2023-08-24 21:01:22 +12:00
-> param ( 'accountSid' , null , new Text ( 0 ), 'Twilio account secret ID.' , true )
-> param ( 'authToken' , null , new Text ( 0 ), 'Twilio authentication token.' , true )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-09-20 22:25:22 +12:00
-> action ( function ( string $id , string $name , ? bool $enabled , string $accountSid , string $authToken , Database $dbForProject , Response $response ) {
2023-08-24 21:01:22 +12:00
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
2023-08-24 08:23:52 +12:00
}
2023-08-24 21:01:22 +12:00
$providerAttr = $provider -> getAttribute ( 'provider' );
2023-08-24 08:23:52 +12:00
2023-08-24 21:01:22 +12:00
if ( $providerAttr !== 'twilio' ) {
2023-08-25 08:15:17 +12:00
throw new Exception ( Exception :: PROVIDER_INCORRECT_TYPE . $providerAttr );
2023-08-24 21:01:22 +12:00
}
2023-09-20 22:25:22 +12:00
if ( ! empty ( $name )) {
2023-08-24 21:01:22 +12:00
$provider -> setAttribute ( 'name' , $name );
2023-09-19 22:06:40 +12:00
$provider -> setAttribute ( 'search' , $provider -> getId () . ' ' . $name . ' ' . 'twilio' . ' ' . 'sms' );
2023-08-24 21:01:22 +12:00
}
2023-09-19 22:06:40 +12:00
if ( $enabled === true || $enabled === false ) {
2023-09-14 00:17:38 +12:00
$provider -> setAttribute ( 'enabled' , $enabled );
}
2023-10-04 23:45:59 +13:00
$credentials = $provider -> getAttribute ( 'credentials' );
2023-08-30 04:59:48 +12:00
2023-10-04 23:45:59 +13:00
if ( ! empty ( $accountSid )) {
$credentials [ 'accountSid' ] = $accountSid ;
2023-08-30 04:59:48 +12:00
}
2023-10-04 23:45:59 +13:00
if ( ! empty ( $authToken )) {
$credentials [ 'authToken' ] = $authToken ;
2023-08-30 04:59:48 +12:00
}
2023-10-04 23:45:59 +13:00
$provider -> setAttribute ( 'credentials' , $credentials );
$provider = $dbForProject -> updateDocument ( 'providers' , $provider -> getId (), $provider );
2023-08-24 21:01:22 +12:00
$response
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
2023-10-04 23:45:59 +13:00
App :: patch ( '/v1/messaging/providers/vonage/:id' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Update Vonage Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.update' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'updateVonageProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-vonage-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' , true )
2023-09-20 22:25:22 +12:00
-> param ( 'enabled' , null , new Boolean (), 'Set as enabled.' , true )
2023-08-24 21:01:22 +12:00
-> param ( 'apiKey' , '' , new Text ( 0 ), 'Vonage API key.' , true )
-> param ( 'apiSecret' , '' , new Text ( 0 ), 'Vonage API secret.' , true )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-09-20 22:25:22 +12:00
-> action ( function ( string $id , string $name , ? bool $enabled , string $apiKey , string $apiSecret , Database $dbForProject , Response $response ) {
2023-08-24 21:01:22 +12:00
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
}
$providerAttr = $provider -> getAttribute ( 'provider' );
if ( $providerAttr !== 'vonage' ) {
2023-08-25 08:15:17 +12:00
throw new Exception ( Exception :: PROVIDER_INCORRECT_TYPE . $providerAttr );
2023-08-24 08:23:52 +12:00
}
2023-09-20 22:25:22 +12:00
if ( ! empty ( $name )) {
2023-08-24 21:01:22 +12:00
$provider -> setAttribute ( 'name' , $name );
2023-09-19 22:06:40 +12:00
$provider -> setAttribute ( 'search' , $provider -> getId () . ' ' . $name . ' ' . 'vonage' . ' ' . 'sms' );
2023-08-24 21:01:22 +12:00
}
2023-09-19 22:06:40 +12:00
if ( $enabled === true || $enabled === false ) {
2023-09-14 00:17:38 +12:00
$provider -> setAttribute ( 'enabled' , $enabled );
}
2023-10-04 23:45:59 +13:00
$credentials = $provider -> getAttribute ( 'credentials' );
2023-08-30 04:59:48 +12:00
2023-10-04 23:45:59 +13:00
if ( ! empty ( $apiKey )) {
$credentials [ 'apiKey' ] = $apiKey ;
2023-08-30 04:59:48 +12:00
}
2023-10-04 23:45:59 +13:00
if ( ! empty ( $apiSecret )) {
$credentials [ 'apiSecret' ] = $apiSecret ;
2023-08-30 04:59:48 +12:00
}
2023-10-04 23:45:59 +13:00
$provider -> setAttribute ( 'credentials' , $credentials );
$provider = $dbForProject -> updateDocument ( 'providers' , $provider -> getId (), $provider );
2023-08-24 21:01:22 +12:00
$response
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
2023-10-04 23:45:59 +13:00
App :: patch ( '/v1/messaging/providers/fcm/:id' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Update FCM Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.update' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'updateFCMProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-fcm-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' , true )
2023-09-20 22:25:22 +12:00
-> param ( 'enabled' , null , new Boolean (), 'Set as enabled.' , true )
2023-08-24 21:01:22 +12:00
-> param ( 'serverKey' , '' , new Text ( 0 ), 'FCM Server Key.' , true )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-09-20 22:25:22 +12:00
-> action ( function ( string $id , string $name , ? bool $enabled , string $serverKey , Database $dbForProject , Response $response ) {
2023-08-24 21:01:22 +12:00
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
}
$providerAttr = $provider -> getAttribute ( 'provider' );
if ( $providerAttr !== 'fcm' ) {
2023-08-25 08:15:17 +12:00
throw new Exception ( Exception :: PROVIDER_INCORRECT_TYPE . $providerAttr );
2023-08-24 21:01:22 +12:00
}
2023-09-20 22:25:22 +12:00
if ( ! empty ( $name )) {
2023-08-24 21:01:22 +12:00
$provider -> setAttribute ( 'name' , $name );
2023-09-19 22:06:40 +12:00
$provider -> setAttribute ( 'search' , $provider -> getId () . ' ' . $name . ' ' . 'fcm' . ' ' . 'push' );
2023-08-24 21:01:22 +12:00
}
2023-09-19 22:06:40 +12:00
if ( $enabled === true || $enabled === false ) {
2023-09-14 00:17:38 +12:00
$provider -> setAttribute ( 'enabled' , $enabled );
}
2023-10-04 23:45:59 +13:00
if ( ! empty ( $serverKey )) {
2023-08-24 21:01:22 +12:00
$provider -> setAttribute ( 'credentials' , [ 'serverKey' => $serverKey ]);
}
$provider = $dbForProject -> updateDocument ( 'providers' , $provider -> getId (), $provider );
$response
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
2023-10-04 23:45:59 +13:00
App :: patch ( '/v1/messaging/providers/apns/:id' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Update APNS Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.update' )
-> label ( 'audits.resource' , 'providers/{response.$id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
2023-10-04 23:45:59 +13:00
-> label ( 'sdk.method' , 'updateAPNSProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-apns-provider.md' )
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_PROVIDER )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> param ( 'name' , '' , new Text ( 128 ), 'Provider name.' , true )
2023-09-20 22:25:22 +12:00
-> param ( 'enabled' , null , new Boolean (), 'Set as enabled.' , true )
2023-08-24 21:01:22 +12:00
-> param ( 'authKey' , '' , new Text ( 0 ), 'APNS authentication key.' , true )
-> param ( 'authKeyId' , '' , new Text ( 0 ), 'APNS authentication key ID.' , true )
-> param ( 'teamId' , '' , new Text ( 0 ), 'APNS team ID.' , true )
-> param ( 'bundleId' , '' , new Text ( 0 ), 'APNS bundle ID.' , true )
-> param ( 'endpoint' , '' , new Text ( 0 ), 'APNS endpoint.' , true )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-09-20 22:25:22 +12:00
-> action ( function ( string $id , string $name , ? bool $enabled , string $authKey , string $authKeyId , string $teamId , string $bundleId , string $endpoint , Database $dbForProject , Response $response ) {
2023-08-24 21:01:22 +12:00
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
2023-08-24 08:23:52 +12:00
}
2023-08-24 21:01:22 +12:00
$providerAttr = $provider -> getAttribute ( 'provider' );
2023-08-24 08:23:52 +12:00
2023-08-24 21:01:22 +12:00
if ( $providerAttr !== 'apns' ) {
2023-08-25 08:15:17 +12:00
throw new Exception ( Exception :: PROVIDER_INCORRECT_TYPE . $providerAttr );
2023-08-24 21:01:22 +12:00
}
2023-08-24 08:23:52 +12:00
2023-09-20 22:25:22 +12:00
if ( ! empty ( $name )) {
2023-08-24 21:01:22 +12:00
$provider -> setAttribute ( 'name' , $name );
2023-09-19 22:06:40 +12:00
$provider -> setAttribute ( 'search' , $provider -> getId () . ' ' . $name . ' ' . 'apns' . ' ' . 'push' );
2023-08-24 21:01:22 +12:00
}
2023-09-19 22:06:40 +12:00
if ( $enabled === true || $enabled === false ) {
2023-09-14 00:17:38 +12:00
$provider -> setAttribute ( 'enabled' , $enabled );
}
2023-10-04 23:45:59 +13:00
$credentials = $provider -> getAttribute ( 'credentials' );
if ( ! empty ( $authKey )) {
$credentials [ 'authKey' ] = $authKey ;
}
if ( ! empty ( $authKeyId )) {
$credentials [ 'authKeyId' ] = $authKeyId ;
}
if ( ! empty ( $teamId )) {
$credentials [ 'teamId' ] = $teamId ;
}
if ( ! empty ( $bundleId )) {
$credentials [ 'bundle' ] = $bundleId ;
}
if ( ! empty ( $endpoint )) {
$credentials [ 'endpoint' ] = $endpoint ;
2023-08-24 21:01:22 +12:00
}
2023-10-04 23:45:59 +13:00
$provider -> setAttribute ( 'credentials' , $credentials );
2023-08-24 21:01:22 +12:00
$provider = $dbForProject -> updateDocument ( 'providers' , $provider -> getId (), $provider );
$response
-> dynamic ( $provider , Response :: MODEL_PROVIDER );
});
2023-08-23 04:45:31 +12:00
App :: delete ( '/v1/messaging/providers/:id' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Delete Provider' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'providers.delete' )
-> label ( 'audits.resource' , 'providers/{request.id}' )
-> label ( 'scope' , 'providers.write' )
2023-09-21 22:48:20 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-24 21:01:22 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'deleteProvider' )
-> label ( 'sdk.description' , '/docs/references/messaging/delete-provider.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_NOCONTENT )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_NONE )
-> param ( 'id' , '' , new UID (), 'Provider ID.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $id , Database $dbForProject , Response $response ) {
$provider = $dbForProject -> getDocument ( 'providers' , $id );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
}
$dbForProject -> deleteDocument ( 'providers' , $provider -> getId ());
$response -> noContent ();
});
2023-08-23 04:45:31 +12:00
2023-10-05 00:57:56 +13:00
App :: post ( '/v1/messaging/topics' )
-> desc ( 'Create a topic.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'topics.create' )
-> label ( 'audits.resource' , 'topics/{response.$id}' )
-> label ( 'scope' , 'topics.write' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'createTopic' )
-> label ( 'sdk.description' , '/docs/references/messaging/create-topic.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_CREATED )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_TOPIC )
-> param ( 'topicId' , '' , new CustomId (), 'Topic ID. Choose a custom Topic ID or a new Topic ID.' )
-> param ( 'providerId' , '' , new UID (), 'Provider ID.' )
-> param ( 'name' , '' , new Text ( 128 ), 'Topic Name.' )
-> param ( 'description' , '' , new Text ( 2048 ), 'Topic Description.' , true )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $topicId , string $providerId , string $name , string $description , Database $dbForProject , Response $response ) {
$topicId = $topicId == 'unique()' ? ID :: unique () : $topicId ;
$provider = $dbForProject -> getDocument ( 'providers' , $providerId );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
}
$topic = new Document ([
'$id' => $topicId ,
'providerId' => $providerId ,
'providerInternalId' => $provider -> getInternalId (),
'name' => $name ,
]);
if ( $description ) {
$topic -> setAttribute ( 'description' , $description );
}
try {
$topic = $dbForProject -> createDocument ( 'topics' , $topic );
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $topic , Response :: MODEL_TOPIC );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: TOPIC_ALREADY_EXISTS );
}
});
2023-08-25 08:15:17 +12:00
App :: get ( '/v1/messaging/topics' )
-> desc ( 'List topics.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'scope' , 'topics.read' )
2023-08-25 11:06:41 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-25 08:15:17 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'listTopics' )
-> label ( 'sdk.description' , '/docs/references/messaging/list-topics.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_TOPIC_LIST )
-> param ( 'queries' , [], new Topics (), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode ( ', ' , Topics :: ALLOWED_ATTRIBUTES ), true )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( array $queries , Database $dbForProject , Response $response ) {
$queries = Query :: parseQueries ( $queries );
// Get cursor document if there was a cursor query
$cursor = Query :: getByType ( $queries , [ Query :: TYPE_CURSORAFTER , Query :: TYPE_CURSORBEFORE ]);
$cursor = reset ( $cursor );
if ( $cursor ) {
$topicId = $cursor -> getValue ();
$cursorDocument = Authorization :: skip ( fn () => $dbForProject -> find ( 'topics' , [
Query :: equal ( '$id' , [ $topicId ]),
Query :: limit ( 1 ),
]));
if ( empty ( $cursorDocument ) || $cursorDocument [ 0 ] -> isEmpty ()) {
throw new Exception ( Exception :: GENERAL_CURSOR_NOT_FOUND , " Topic ' { $topicId } ' for the 'cursor' value not found. " );
}
$cursor -> setValue ( $cursorDocument [ 0 ]);
}
$filterQueries = Query :: groupByType ( $queries )[ 'filters' ];
$response -> dynamic ( new Document ([
'total' => $dbForProject -> count ( 'topics' , $filterQueries , APP_LIMIT_COUNT ),
2023-08-25 11:06:41 +12:00
'topics' => $dbForProject -> find ( 'topics' , $queries ),
2023-08-25 08:15:17 +12:00
]), Response :: MODEL_TOPIC_LIST );
});
2023-08-29 03:11:05 +12:00
App :: get ( '/v1/messaging/topics/:topicId' )
2023-08-25 08:15:17 +12:00
-> desc ( 'Get a topic.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'scope' , 'topics.read' )
2023-08-25 11:06:41 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-25 08:15:17 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'getTopic' )
-> label ( 'sdk.description' , '/docs/references/messaging/get-topic.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_TOPIC )
2023-08-29 03:11:05 +12:00
-> param ( 'topicId' , '' , new UID (), 'Topic ID.' )
2023-08-25 08:15:17 +12:00
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-08-29 03:11:05 +12:00
-> action ( function ( string $topicId , Database $dbForProject , Response $response ) {
$topic = $dbForProject -> getDocument ( 'topics' , $topicId );
2023-08-25 08:15:17 +12:00
if ( $topic -> isEmpty ()) {
throw new Exception ( Exception :: TOPIC_NOT_FOUND );
}
2023-08-29 03:11:05 +12:00
$topic = $dbForProject -> getDocument ( 'topics' , $topicId );
2023-08-25 08:15:17 +12:00
$response
-> dynamic ( $topic , Response :: MODEL_TOPIC );
});
2023-08-25 11:06:41 +12:00
App :: patch ( '/v1/messaging/topics/:topicId' )
2023-08-25 08:15:17 +12:00
-> desc ( 'Update a topic.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'topics.update' )
-> label ( 'audits.resource' , 'topics/{response.$id}' )
-> label ( 'scope' , 'topics.write' )
2023-08-25 11:06:41 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-25 08:15:17 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'updateTopic' )
-> label ( 'sdk.description' , '/docs/references/messaging/update-topic.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_TOPIC )
2023-08-25 11:06:41 +12:00
-> param ( 'topicId' , '' , new UID (), 'Topic ID.' )
2023-08-25 08:15:17 +12:00
-> param ( 'name' , '' , new Text ( 128 ), 'Topic Name.' , true )
-> param ( 'description' , null , new Text ( 128 ), 'Topic Description.' , true )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-08-25 11:06:41 +12:00
-> action ( function ( string $topicId , string $name , string $description , Database $dbForProject , Response $response ) {
$topic = $dbForProject -> getDocument ( 'topics' , $topicId );
2023-08-25 08:15:17 +12:00
if ( $topic -> isEmpty ()) {
throw new Exception ( Exception :: TOPIC_NOT_FOUND );
}
if ( $name ) {
$topic -> setAttribute ( 'name' , $name );
}
if ( $description ) {
$topic -> setAttribute ( 'description' , $description );
}
2023-08-25 11:06:41 +12:00
$topic = $dbForProject -> updateDocument ( 'topics' , $topicId , $topic );
2023-08-25 08:15:17 +12:00
$response
-> dynamic ( $topic , Response :: MODEL_TOPIC );
});
2023-08-25 11:06:41 +12:00
App :: delete ( '/v1/messaging/topics/:topicId' )
2023-08-25 08:15:17 +12:00
-> desc ( 'Delete a topic.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'topics.delete' )
2023-08-25 11:06:41 +12:00
-> label ( 'audits.resource' , 'topics/{request.topicId}' )
2023-08-25 08:15:17 +12:00
-> label ( 'scope' , 'topics.write' )
2023-08-25 11:06:41 +12:00
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
2023-08-25 08:15:17 +12:00
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'deleteTopic' )
-> label ( 'sdk.description' , '/docs/references/messaging/delete-topic.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_NOCONTENT )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_NONE )
2023-08-25 11:06:41 +12:00
-> param ( 'topicId' , '' , new UID (), 'Topic ID.' )
2023-08-25 08:15:17 +12:00
-> inject ( 'dbForProject' )
-> inject ( 'response' )
2023-08-25 11:06:41 +12:00
-> action ( function ( string $topicId , Database $dbForProject , Response $response ) {
$topic = $dbForProject -> getDocument ( 'topics' , $topicId );
2023-08-25 08:15:17 +12:00
if ( $topic -> isEmpty ()) {
throw new Exception ( Exception :: TOPIC_NOT_FOUND );
}
2023-08-25 11:06:41 +12:00
$topic = $dbForProject -> deleteDocument ( 'topics' , $topicId );
2023-08-25 08:15:17 +12:00
$response -> noContent ();
});
2023-10-05 00:57:56 +13:00
App :: post ( '/v1/messaging/topics/:topicId/subscribers' )
-> desc ( 'Adds a Subscriber to a Topic.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'subscribers.create' )
-> label ( 'audits.resource' , 'subscribers/{response.$id}' )
-> label ( 'scope' , 'subscribers.write' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_JWT , APP_AUTH_TYPE_SESSION , APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'addSubscriber' )
-> label ( 'sdk.description' , '/docs/references/messaging/add-subscriber.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_CREATED )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_SUBSCRIBER )
-> param ( 'subscriberId' , '' , new CustomId (), 'Subscriber ID. Choose a custom Topic ID or a new Topic ID.' )
-> param ( 'topicId' , '' , new UID (), 'Topic ID.' )
-> param ( 'targetId' , '' , new UID (), 'Target ID.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $subscriberId , string $topicId , string $targetId , Database $dbForProject , Response $response ) {
$subscriberId = $subscriberId == 'unique()' ? ID :: unique () : $subscriberId ;
$topic = Authorization :: skip ( fn () => $dbForProject -> getDocument ( 'topics' , $topicId ));
if ( $topic -> isEmpty ()) {
throw new Exception ( Exception :: TOPIC_NOT_FOUND );
}
$target = Authorization :: skip ( fn () => $dbForProject -> getDocument ( 'targets' , $targetId ));
if ( $target -> isEmpty ()) {
throw new Exception ( Exception :: USER_TARGET_NOT_FOUND );
}
$subscriber = new Document ([
'$id' => $subscriberId ,
'$permissions' => [
Permission :: read ( Role :: user ( $target -> getAttribute ( 'userId' ))),
Permission :: delete ( Role :: user ( $target -> getAttribute ( 'userId' ))),
],
'topicId' => $topicId ,
'topicInternalId' => $topic -> getInternalId (),
'targetId' => $targetId ,
'targetInternalId' => $target -> getInternalId (),
]);
try {
$subscriber = $dbForProject -> createDocument ( 'subscribers' , $subscriber );
$dbForProject -> deleteCachedDocument ( 'topics' , $topicId );
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
-> dynamic ( $subscriber , Response :: MODEL_SUBSCRIBER );
} catch ( DuplicateException ) {
throw new Exception ( Exception :: SUBSCRIBER_ALREADY_EXISTS );
}
});
2023-08-29 03:11:05 +12:00
App :: get ( '/v1/messaging/topics/:topicId/subscribers' )
-> desc ( 'List topic\'s subscribers.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'scope' , 'subscribers.read' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_JWT , APP_AUTH_TYPE_SESSION , APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'listSubscribers' )
-> label ( 'sdk.description' , '/docs/references/messaging/list-subscribers.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_SUBSCRIBER_LIST )
-> param ( 'topicId' , '' , new UID (), 'Topic ID.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $topicId , Database $dbForProject , Response $response ) {
$topic = Authorization :: skip ( fn () => $dbForProject -> getDocument ( 'topics' , $topicId ));
if ( $topic -> isEmpty ()) {
throw new Exception ( Exception :: TOPIC_NOT_FOUND );
}
$subscribers = $dbForProject -> find ( 'subscribers' , [
Query :: equal ( 'topicInternalId' , [ $topic -> getInternalId ()])
]);
2023-08-29 03:13:18 +12:00
2023-08-29 03:11:05 +12:00
$response
-> dynamic ( new Document ([
'subscribers' => $subscribers ,
'total' => \count ( $subscribers ),
]), Response :: MODEL_SUBSCRIBER_LIST );
2023-08-29 03:13:18 +12:00
});
2023-08-29 03:11:05 +12:00
App :: get ( '/v1/messaging/topics/:topicId/subscriber/:subscriberId' )
-> desc ( 'Get a topic\'s subscriber.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'scope' , 'subscribers.read' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_JWT , APP_AUTH_TYPE_SESSION , APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'getSubscriber' )
-> label ( 'sdk.description' , '/docs/references/messaging/get-subscriber.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_SUBSCRIBER )
-> param ( 'topicId' , '' , new UID (), 'Topic ID.' )
-> param ( 'subscriberId' , '' , new UID (), 'Subscriber ID.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $topicId , string $subscriberId , Database $dbForProject , Response $response ) {
$topic = Authorization :: skip ( fn () => $dbForProject -> getDocument ( 'topics' , $topicId ));
if ( $topic -> isEmpty ()) {
throw new Exception ( Exception :: TOPIC_NOT_FOUND );
}
2023-08-29 03:13:18 +12:00
2023-08-29 03:11:05 +12:00
$subscriber = $dbForProject -> getDocument ( 'subscribers' , $subscriberId );
2023-08-29 03:13:18 +12:00
if ( $subscriber -> isEmpty () || $subscriber -> getAttribute ( 'topicId' ) !== $topicId ) {
2023-08-29 03:11:05 +12:00
throw new Exception ( Exception :: SUBSCRIBER_NOT_FOUND );
}
$response
-> dynamic ( $subscriber , Response :: MODEL_SUBSCRIBER );
});
App :: delete ( '/v1/messaging/topics/:topicId/subscriber/:subscriberId' )
-> desc ( 'Delete a Subscriber from a Topic.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'subscribers.delete' )
-> label ( 'audits.resource' , 'subscribers/{request.subscriberId}' )
-> label ( 'scope' , 'subscribers.write' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_JWT , APP_AUTH_TYPE_SESSION , APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'deleteSubscriber' )
-> label ( 'sdk.description' , '/docs/references/messaging/delete-subscriber.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_NOCONTENT )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_NONE )
-> param ( 'topicId' , '' , new UID (), 'Topic ID.' )
-> param ( 'subscriberId' , '' , new UID (), 'Subscriber ID.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $topicId , string $subscriberId , Database $dbForProject , Response $response ) {
$topic = Authorization :: skip ( fn () => $dbForProject -> getDocument ( 'topics' , $topicId ));
if ( $topic -> isEmpty ()) {
throw new Exception ( Exception :: TOPIC_NOT_FOUND );
}
$subscriber = $dbForProject -> getDocument ( 'subscribers' , $subscriberId );
if ( $subscriber -> isEmpty () || $subscriber -> getAttribute ( 'topicId' ) !== $topicId ) {
throw new Exception ( Exception :: SUBSCRIBER_NOT_FOUND );
}
$subscriber = $dbForProject -> deleteDocument ( 'subscribers' , $subscriberId );
$dbForProject -> deleteCachedDocument ( 'topics' , $topicId );
$response
-> setStatusCode ( Response :: STATUS_CODE_NOCONTENT )
-> noContent ();
});
2023-08-22 04:45:15 +12:00
App :: post ( '/v1/messaging/messages/email' )
2023-08-24 21:01:22 +12:00
-> desc ( 'Send an email.' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'audits.event' , 'messages.create' )
-> label ( 'audits.resource' , 'messages/{response.$id}' )
-> label ( 'scope' , 'messages.write' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'sendEmail' )
-> label ( 'sdk.description' , '/docs/references/messaging/send-email.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_CREATED )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_MESSAGE )
2023-09-22 03:47:15 +12:00
-> param ( 'messageId' , '' , new CustomId (), 'Message 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.' )
2023-10-04 23:45:59 +13:00
-> param ( 'providerId' , '' , new UID (), 'Email Provider ID.' )
2023-10-04 23:54:29 +13:00
-> param ( 'to' , [], new ArrayList ( new Text ( Database :: LENGTH_KEY )), 'List of Topic IDs or List of User IDs or List of Target IDs.' )
2023-10-04 23:45:59 +13:00
-> param ( 'subject' , '' , new Text ( 998 ), 'Email Subject.' )
2023-09-28 02:28:00 +13:00
-> param ( 'description' , '' , new Text ( 256 ), 'Description for Message.' , true )
2023-09-21 22:42:56 +12:00
-> param ( 'content' , '' , new Text ( 65407 ), 'Email Content.' )
2023-10-04 23:45:59 +13:00
-> param ( 'html' , false , new Boolean (), 'Is content of type HTML' , true )
2023-08-24 21:01:22 +12:00
-> inject ( 'dbForProject' )
2023-09-06 22:10:56 +12:00
-> inject ( 'project' )
-> inject ( 'messaging' )
2023-08-24 21:01:22 +12:00
-> inject ( 'response' )
2023-09-28 02:28:00 +13:00
-> action ( function ( string $messageId , string $providerId , array $to , string $subject , string $description , string $content , string $html , Database $dbForProject , Document $project , Messaging $messaging , Response $response ) {
2023-09-22 03:47:15 +12:00
$messageId = $messageId == 'unique()' ? ID :: unique () : $messageId ;
2023-08-24 21:01:22 +12:00
$provider = $dbForProject -> getDocument ( 'providers' , $providerId );
if ( $provider -> isEmpty ()) {
throw new Exception ( Exception :: PROVIDER_NOT_FOUND );
}
$message = $dbForProject -> createDocument ( 'messages' , new Document ([
2023-09-22 03:47:15 +12:00
'$id' => $messageId ,
2023-08-24 21:01:22 +12:00
'providerId' => $provider -> getId (),
'providerInternalId' => $provider -> getInternalId (),
'to' => $to ,
'data' => [
'subject' => $subject ,
'content' => $content ,
2023-09-26 20:42:44 +13:00
'html' => $html ,
'description' => $description ,
2023-08-24 21:01:22 +12:00
],
2023-09-21 00:08:29 +12:00
'status' => 'processing' ,
2023-09-28 02:28:00 +13:00
'search' => $messageId . ' ' . $description . ' ' . $subject ,
2023-08-24 21:01:22 +12:00
]));
2023-09-06 22:10:56 +12:00
$messaging
2023-10-04 23:45:59 +13:00
-> setMessageId ( $message -> getId ())
-> setProject ( $project )
-> trigger ();
2023-08-24 21:01:22 +12:00
$response
-> setStatusCode ( Response :: STATUS_CODE_CREATED )
2023-09-06 23:00:46 +12:00
-> dynamic ( $message , Response :: MODEL_MESSAGE );
2023-08-24 21:01:22 +12:00
});
2023-10-04 23:45:59 +13:00
App :: get ( '/v1/messaging/messages/:id' )
-> desc ( 'Get Message' )
-> groups ([ 'api' , 'messaging' ])
-> label ( 'scope' , 'messages.read' )
-> label ( 'sdk.auth' , [ APP_AUTH_TYPE_ADMIN , APP_AUTH_TYPE_KEY ])
-> label ( 'sdk.namespace' , 'messaging' )
-> label ( 'sdk.method' , 'getMessage' )
-> label ( 'sdk.description' , '/docs/references/messaging/get-message.md' )
-> label ( 'sdk.response.code' , Response :: STATUS_CODE_OK )
-> label ( 'sdk.response.type' , Response :: CONTENT_TYPE_JSON )
-> label ( 'sdk.response.model' , Response :: MODEL_MESSAGE )
-> param ( 'id' , '' , new UID (), 'Message ID.' )
-> inject ( 'dbForProject' )
-> inject ( 'response' )
-> action ( function ( string $id , Database $dbForProject , Response $response ) {
$message = $dbForProject -> getDocument ( 'messages' , $id );
if ( $message -> isEmpty ()) {
throw new Exception ( Exception :: MESSAGE_NOT_FOUND );
}
$response -> dynamic ( $message , Response :: MODEL_MESSAGE );
});