2023-08-07 15:26:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Utopia\Response\Model;
|
|
|
|
|
|
|
|
|
|
use Appwrite\Utopia\Response;
|
|
|
|
|
use Appwrite\Utopia\Response\Model;
|
|
|
|
|
use Utopia\Database\DateTime;
|
|
|
|
|
|
2023-09-11 15:00:21 +00:00
|
|
|
class Message extends Any
|
2023-08-07 15:26:03 +00:00
|
|
|
{
|
2023-08-07 15:31:25 +00:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this
|
2023-08-18 18:00:42 +00:00
|
|
|
->addRule('$id', [
|
|
|
|
|
'type' => self::TYPE_STRING,
|
|
|
|
|
'description' => 'Message ID.',
|
|
|
|
|
'default' => '',
|
|
|
|
|
'example' => '5e5ea5c16897e',
|
|
|
|
|
])
|
|
|
|
|
->addRule('to', [
|
|
|
|
|
'type' => self::TYPE_STRING,
|
2023-09-14 11:04:53 +00:00
|
|
|
'description' => 'Message recipients.',
|
2023-08-18 18:00:42 +00:00
|
|
|
'default' => '',
|
2023-09-11 15:06:43 +00:00
|
|
|
'array' => true,
|
2023-08-18 18:00:42 +00:00
|
|
|
'example' => ['user-1'],
|
|
|
|
|
])
|
|
|
|
|
->addRule('deliveryTime', [
|
|
|
|
|
'type' => self::TYPE_DATETIME,
|
2023-10-06 13:53:46 +00:00
|
|
|
'description' => 'The scheduled time for message.',
|
2023-08-18 18:00:42 +00:00
|
|
|
'required' => false,
|
|
|
|
|
'default' => DateTime::now(),
|
2023-09-13 11:27:59 +00:00
|
|
|
'example' => self::TYPE_DATETIME_EXAMPLE,
|
2023-08-18 18:00:42 +00:00
|
|
|
])
|
2023-10-06 13:53:46 +00:00
|
|
|
->addRule('deliveredAt', [
|
|
|
|
|
'type' => self::TYPE_DATETIME,
|
|
|
|
|
'description' => 'The time when the message was delivered.',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => '',
|
|
|
|
|
'example' => self::TYPE_DATETIME_EXAMPLE,
|
|
|
|
|
])
|
2023-09-13 11:27:59 +00:00
|
|
|
->addRule('deliveryErrors', [
|
2023-08-18 18:00:42 +00:00
|
|
|
'type' => self::TYPE_STRING,
|
2023-09-13 11:27:59 +00:00
|
|
|
'description' => 'Delivery errors if any.',
|
2023-08-18 18:00:42 +00:00
|
|
|
'required' => false,
|
|
|
|
|
'default' => '',
|
2023-09-11 15:06:43 +00:00
|
|
|
'array' => true,
|
2023-09-14 11:13:38 +00:00
|
|
|
'example' => ['Failed to send message to target 5e5ea5c16897e: Credentials not valid.'],
|
2023-08-18 18:00:42 +00:00
|
|
|
])
|
|
|
|
|
->addRule('deliveredTo', [
|
|
|
|
|
'type' => self::TYPE_INTEGER,
|
|
|
|
|
'description' => 'Number of recipients the message was delivered to.',
|
2023-09-13 11:27:59 +00:00
|
|
|
'default' => 0,
|
2023-08-18 18:00:42 +00:00
|
|
|
'example' => 1,
|
|
|
|
|
])
|
2023-10-17 18:15:46 +00:00
|
|
|
->addRule('data', [
|
|
|
|
|
'type' => self::TYPE_JSON,
|
|
|
|
|
'description' => 'Data of the message.',
|
|
|
|
|
'default' => [],
|
|
|
|
|
'example' => [
|
|
|
|
|
'subject' => 'Welcome to Appwrite',
|
|
|
|
|
'content' => 'Hi there, welcome to Appwrite family.',
|
|
|
|
|
],
|
|
|
|
|
])
|
2023-09-20 12:08:29 +00:00
|
|
|
->addRule('status', [
|
|
|
|
|
'type' => self::TYPE_STRING,
|
2023-08-18 18:00:42 +00:00
|
|
|
'description' => 'Status of delivery.',
|
2023-09-20 12:08:29 +00:00
|
|
|
'default' => 'processing',
|
|
|
|
|
'example' => 'Message status can be one of the following: processing, sent, failed.',
|
2023-09-26 07:42:44 +00:00
|
|
|
])
|
|
|
|
|
->addRule('description', [
|
|
|
|
|
'type' => self::TYPE_STRING,
|
|
|
|
|
'description' => 'Message description.',
|
|
|
|
|
'required' => false,
|
|
|
|
|
'default' => '',
|
|
|
|
|
'example' => 'Welcome Email.',
|
2023-08-18 18:00:42 +00:00
|
|
|
]);
|
2023-08-07 15:31:25 +00:00
|
|
|
}
|
2023-08-07 15:26:03 +00:00
|
|
|
|
2023-08-18 18:00:42 +00:00
|
|
|
/**
|
|
|
|
|
* Get Name
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2023-08-07 15:31:25 +00:00
|
|
|
public function getName(): string
|
|
|
|
|
{
|
|
|
|
|
return 'Message';
|
|
|
|
|
}
|
2023-08-07 15:26:03 +00:00
|
|
|
|
2023-08-18 18:00:42 +00:00
|
|
|
/**
|
|
|
|
|
* Get Type
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2023-08-07 15:31:25 +00:00
|
|
|
public function getType(): string
|
|
|
|
|
{
|
|
|
|
|
return Response::MODEL_MESSAGE;
|
|
|
|
|
}
|
2023-08-07 15:26:03 +00:00
|
|
|
}
|