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

Add providerType to Message

This commit is contained in:
Jake Barnby 2023-11-29 17:09:44 +13:00
parent 82c86c0ae2
commit 4b58d08fd8
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
5 changed files with 57 additions and 58 deletions

View file

@ -1505,6 +1505,17 @@ $commonCollections = [
'$id' => ID::custom('messages'), '$id' => ID::custom('messages'),
'name' => 'Messages', 'name' => 'Messages',
'attributes' => [ 'attributes' => [
[
'$id' => ID::custom('providerType'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => true,
'default' => null,
'array' => false,
'filters' => [],
],
[ [
'$id' => ID::custom('description'), '$id' => ID::custom('description'),
'type' => Database::VAR_STRING, 'type' => Database::VAR_STRING,

View file

@ -2240,6 +2240,7 @@ App::post('/v1/messaging/messages/email')
$message = $dbForProject->createDocument('messages', new Document([ $message = $dbForProject->createDocument('messages', new Document([
'$id' => $messageId, '$id' => $messageId,
'providerType' => MESSAGE_TYPE_EMAIL,
'topics' => $topics, 'topics' => $topics,
'users' => $users, 'users' => $users,
'targets' => $targets, 'targets' => $targets,
@ -2303,6 +2304,7 @@ App::post('/v1/messaging/messages/sms')
$message = $dbForProject->createDocument('messages', new Document([ $message = $dbForProject->createDocument('messages', new Document([
'$id' => $messageId, '$id' => $messageId,
'providerType' => MESSAGE_TYPE_SMS,
'topics' => $topics, 'topics' => $topics,
'users' => $users, 'users' => $users,
'targets' => $targets, 'targets' => $targets,
@ -2370,41 +2372,19 @@ App::post('/v1/messaging/messages/push')
throw new Exception(Exception::MESSAGE_MISSING_TARGET); throw new Exception(Exception::MESSAGE_MISSING_TARGET);
} }
$pushData = [ $pushData = [];
'title' => $title,
'body' => $body,
];
if (!is_null($data)) { $keys = ['title', 'body', 'data', 'action', 'icon', 'sound', 'color', 'tag', 'badge'];
$pushData['data'] = $data;
}
if ($action) { foreach ($keys as $key) {
$pushData['action'] = $action; if (!empty($$key)) {
} $pushData[$key] = $$key;
}
if ($icon) {
$pushData['icon'] = $icon;
}
if ($sound) {
$pushData['sound'] = $sound;
}
if ($color) {
$pushData['color'] = $color;
}
if ($tag) {
$pushData['tag'] = $tag;
}
if ($badge) {
$pushData['badge'] = $badge;
} }
$message = $dbForProject->createDocument('messages', new Document([ $message = $dbForProject->createDocument('messages', new Document([
'$id' => $messageId, '$id' => $messageId,
'providerType' => MESSAGE_TYPE_PUSH,
'topics' => $topics, 'topics' => $topics,
'users' => $users, 'users' => $users,
'targets' => $targets, 'targets' => $targets,

View file

@ -11,7 +11,7 @@ class Messaging extends Event
protected ?string $messageId = null; protected ?string $messageId = null;
protected ?Document $message = null; protected ?Document $message = null;
protected ?array $recipients = null; protected ?array $recipients = null;
protected ?string $deliveryTime = null; protected ?string $scheduledAt = null;
protected ?string $providerType = null; protected ?string $providerType = null;
@ -117,14 +117,14 @@ class Messaging extends Event
} }
/** /**
* Sets Delivery time for the messaging event. * Sets Scheduled delivery time for the messaging event.
* *
* @param string $deliveryTime * @param string $scheduledAt
* @return self * @return self
*/ */
public function setDeliveryTime(string $deliveryTime): self public function setScheduledAt(string $scheduledAt): self
{ {
$this->deliveryTime = $deliveryTime; $this->scheduledAt = $scheduledAt;
return $this; return $this;
} }
@ -134,9 +134,9 @@ class Messaging extends Event
* *
* @return string * @return string
*/ */
public function getDeliveryTime(): string public function getScheduledAt(): string
{ {
return $this->deliveryTime; return $this->scheduledAt;
} }
/** /**

View file

@ -29,6 +29,12 @@ class Message extends Any
'default' => '', 'default' => '',
'example' => self::TYPE_DATETIME_EXAMPLE, 'example' => self::TYPE_DATETIME_EXAMPLE,
]) ])
->addRule('providerType', [
'type' => self::TYPE_STRING,
'description' => 'Message provider type.',
'default' => '',
'example' => MESSAGE_TYPE_EMAIL,
])
->addRule('topics', [ ->addRule('topics', [
'type' => self::TYPE_STRING, 'type' => self::TYPE_STRING,
'description' => 'Topic IDs set as recipients.', 'description' => 'Topic IDs set as recipients.',
@ -50,7 +56,7 @@ class Message extends Any
'array' => true, 'array' => true,
'example' => ['5e5ea5c16897e'], 'example' => ['5e5ea5c16897e'],
]) ])
->addRule('deliveryTime', [ ->addRule('scheduledAt', [
'type' => self::TYPE_DATETIME, 'type' => self::TYPE_DATETIME,
'description' => 'The scheduled time for message.', 'description' => 'The scheduled time for message.',
'required' => false, 'required' => false,

View file

@ -2098,13 +2098,13 @@ trait Base
} }
}'; }';
case self::$CREATE_EMAIL: case self::$CREATE_EMAIL:
return 'mutation createEmail($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $subject: String!, $content: String!, $status: String, $description: String, $html: Boolean, $deliveryTime: String) { return 'mutation createEmail($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $subject: String!, $content: String!, $status: String, $description: String, $html: Boolean, $scheduledAt: String) {
messagingCreateEmail(messageId: $messageId, topics: $topics, users: $users, targets: $targets, subject: $subject, content: $content, status: $status, description: $description, html: $html, deliveryTime: $deliveryTime) { messagingCreateEmail(messageId: $messageId, topics: $topics, users: $users, targets: $targets, subject: $subject, content: $content, status: $status, description: $description, html: $html, scheduledAt: $scheduledAt) {
_id _id
topics topics
users users
targets targets
deliveryTime scheduledAt
deliveredAt deliveredAt
deliveryErrors deliveryErrors
deliveredTotal deliveredTotal
@ -2113,13 +2113,13 @@ trait Base
} }
}'; }';
case self::$CREATE_SMS: case self::$CREATE_SMS:
return 'mutation createSMS($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $content: String!, $status: String, $description: String, $deliveryTime: String) { return 'mutation createSMS($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $content: String!, $status: String, $description: String, $scheduledAt: String) {
messagingCreateSMS(messageId: $messageId, topics: $topics, users: $users, targets: $targets, content: $content, status: $status, description: $description, deliveryTime: $deliveryTime) { messagingCreateSMS(messageId: $messageId, topics: $topics, users: $users, targets: $targets, content: $content, status: $status, description: $description, scheduledAt: $scheduledAt) {
_id _id
topics topics
users users
targets targets
deliveryTime scheduledAt
deliveredAt deliveredAt
deliveryErrors deliveryErrors
deliveredTotal deliveredTotal
@ -2128,13 +2128,13 @@ trait Base
} }
}'; }';
case self::$CREATE_PUSH_NOTIFICATION: case self::$CREATE_PUSH_NOTIFICATION:
return 'mutation createPushNotification($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $title: String!, $body: String!, $data: Json, $action: String, $icon: String, $sound: String, $color: String, $tag: String, $badge: String, $status: String, $description: String, $deliveryTime: String) { return 'mutation createPushNotification($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $title: String!, $body: String!, $data: Json, $action: String, $icon: String, $sound: String, $color: String, $tag: String, $badge: String, $status: String, $description: String, $scheduledAt: String) {
messagingCreatePushNotification(messageId: $messageId, topics: $topics, users: $users, targets: $targets, title: $title, body: $body, data: $data, action: $action, icon: $icon, sound: $sound, color: $color, tag: $tag, badge: $badge, status: $status, description: $description, deliveryTime: $deliveryTime) { messagingCreatePushNotification(messageId: $messageId, topics: $topics, users: $users, targets: $targets, title: $title, body: $body, data: $data, action: $action, icon: $icon, sound: $sound, color: $color, tag: $tag, badge: $badge, status: $status, description: $description, scheduledAt: $scheduledAt) {
_id _id
topics topics
users users
targets targets
deliveryTime scheduledAt
deliveredAt deliveredAt
deliveryErrors deliveryErrors
deliveredTotal deliveredTotal
@ -2148,10 +2148,11 @@ trait Base
total total
messages { messages {
_id _id
providerType
topics topics
users users
targets targets
deliveryTime scheduledAt
deliveredAt deliveredAt
deliveryErrors deliveryErrors
deliveredTotal deliveredTotal
@ -2164,10 +2165,11 @@ trait Base
return 'query getMessage($messageId: String!) { return 'query getMessage($messageId: String!) {
messagingGetMessage(messageId: $messageId) { messagingGetMessage(messageId: $messageId) {
_id _id
providerType
topics topics
users users
targets targets
deliveryTime scheduledAt
deliveredAt deliveredAt
deliveryErrors deliveryErrors
deliveredTotal deliveredTotal
@ -2176,13 +2178,13 @@ trait Base
} }
}'; }';
case self::$UPDATE_EMAIL: case self::$UPDATE_EMAIL:
return 'mutation updateEmail($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $subject: String, $content: String, $status: String, $description: String, $html: Boolean, $deliveryTime: String) { return 'mutation updateEmail($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $subject: String, $content: String, $status: String, $description: String, $html: Boolean, $scheduledAt: String) {
messagingUpdateEmail(messageId: $messageId, topics: $topics, users: $users, targets: $targets, subject: $subject, content: $content, status: $status, description: $description, html: $html, deliveryTime: $deliveryTime) { messagingUpdateEmail(messageId: $messageId, topics: $topics, users: $users, targets: $targets, subject: $subject, content: $content, status: $status, description: $description, html: $html, scheduledAt: $scheduledAt) {
_id _id
topics topics
users users
targets targets
deliveryTime scheduledAt
deliveredAt deliveredAt
deliveryErrors deliveryErrors
deliveredTotal deliveredTotal
@ -2191,13 +2193,13 @@ trait Base
} }
}'; }';
case self::$UPDATE_SMS: case self::$UPDATE_SMS:
return 'mutation updateSMS($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $content: String, $status: String, $description: String, $deliveryTime: String) { return 'mutation updateSMS($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $content: String, $status: String, $description: String, $scheduledAt: String) {
messagingUpdateSMS(messageId: $messageId, topics: $topics, users: $users, targets: $targets, content: $content, status: $status, description: $description, deliveryTime: $deliveryTime) { messagingUpdateSMS(messageId: $messageId, topics: $topics, users: $users, targets: $targets, content: $content, status: $status, description: $description, scheduledAt: $scheduledAt) {
_id _id
topics topics
users users
targets targets
deliveryTime scheduledAt
deliveredAt deliveredAt
deliveryErrors deliveryErrors
deliveredTotal deliveredTotal
@ -2206,13 +2208,13 @@ trait Base
} }
}'; }';
case self::$UPDATE_PUSH_NOTIFICATION: case self::$UPDATE_PUSH_NOTIFICATION:
return 'mutation updatePushNotification($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $title: String, $body: String, $data: Json, $action: String, $icon: String, $sound: String, $color: String, $tag: String, $badge: String, $status: String, $description: String, $deliveryTime: String) { return 'mutation updatePushNotification($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $title: String, $body: String, $data: Json, $action: String, $icon: String, $sound: String, $color: String, $tag: String, $badge: String, $status: String, $description: String, $scheduledAt: String) {
messagingUpdatePushNotification(messageId: $messageId, topics: $topics, users: $users, targets: $targets, title: $title, body: $body, data: $data, action: $action, icon: $icon, sound: $sound, color: $color, tag: $tag, badge: $badge, status: $status, description: $description, deliveryTime: $deliveryTime) { messagingUpdatePushNotification(messageId: $messageId, topics: $topics, users: $users, targets: $targets, title: $title, body: $body, data: $data, action: $action, icon: $icon, sound: $sound, color: $color, tag: $tag, badge: $badge, status: $status, description: $description, scheduledAt: $scheduledAt) {
_id _id
topics topics
users users
targets targets
deliveryTime scheduledAt
deliveredAt deliveredAt
deliveryErrors deliveryErrors
deliveredTotal deliveredTotal
@ -2472,7 +2474,7 @@ trait Base
protected string $stdout = ''; protected string $stdout = '';
protected string $stderr = ''; protected string $stderr = '';
protected function packageCode($folder) protected function packageCode($folder): void
{ {
Console::execute('cd ' . realpath(__DIR__ . "/../../../resources/functions") . "/$folder && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->stdout, $this->stderr); Console::execute('cd ' . realpath(__DIR__ . "/../../../resources/functions") . "/$folder && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->stdout, $this->stderr);
} }