mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
add response models required for messaging service
This commit is contained in:
parent
be1afc61b0
commit
3e70a19e4f
6 changed files with 383 additions and 0 deletions
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Appwrite\Utopia;
|
||||
|
||||
use Appwrite\Utopia\Response\Model\Message;
|
||||
use Appwrite\Utopia\Response\Model\Subscriber;
|
||||
use Appwrite\Utopia\Response\Model\Topic;
|
||||
use Exception;
|
||||
use Swoole\Http\Request as SwooleRequest;
|
||||
use Utopia\Swoole\Response as SwooleResponse;
|
||||
|
|
@ -78,6 +81,7 @@ use Appwrite\Utopia\Response\Model\LocaleCode;
|
|||
use Appwrite\Utopia\Response\Model\Mock; // Keep last
|
||||
use Appwrite\Utopia\Response\Model\Provider;
|
||||
use Appwrite\Utopia\Response\Model\Runtime;
|
||||
use Appwrite\Utopia\Response\Model\Target;
|
||||
use Appwrite\Utopia\Response\Model\TemplateSMS;
|
||||
use Appwrite\Utopia\Response\Model\UsageBuckets;
|
||||
use Appwrite\Utopia\Response\Model\UsageCollection;
|
||||
|
|
@ -180,6 +184,18 @@ class Response extends SwooleResponse
|
|||
public const MODEL_PHONE = 'phone';
|
||||
public const MODEL_PHONE_LIST = 'phoneList';
|
||||
|
||||
// Messaging
|
||||
public const MODEL_PROVIDER = 'provider';
|
||||
public const MODEL_PROVIDER_LIST = 'providerList';
|
||||
public const MODEL_MESSAGE = 'message';
|
||||
public const MODEL_MESSAGE_LIST = 'messageList';
|
||||
public const MODEL_TOPIC = 'topic';
|
||||
public const MODEL_TOPIC_LIST = 'topicList';
|
||||
public const MODEL_SUBSCRIBER = 'subscriber';
|
||||
public const MODEL_SUBSCRIBER_LIST = 'subscriberList';
|
||||
public const MODEL_TARGET = 'target';
|
||||
public const MODEL_TARGET_LIST = 'targetList';
|
||||
|
||||
// Teams
|
||||
public const MODEL_TEAM = 'team';
|
||||
public const MODEL_TEAM_LIST = 'teamList';
|
||||
|
|
@ -289,6 +305,11 @@ class Response extends SwooleResponse
|
|||
->setModel(new BaseList('Metric List', self::MODEL_METRIC_LIST, 'metrics', self::MODEL_METRIC, true, false))
|
||||
->setModel(new BaseList('Variables List', self::MODEL_VARIABLE_LIST, 'variables', self::MODEL_VARIABLE))
|
||||
->setModel(new BaseList('Locale codes list', self::MODEL_LOCALE_CODE_LIST, 'localeCodes', self::MODEL_LOCALE_CODE))
|
||||
->setModel(new BaseList('Provider list', self::MODEL_PROVIDER_LIST, 'providers', self::MODEL_PROVIDER))
|
||||
->setModel(new BaseList('Message list', self::MODEL_MESSAGE_LIST, 'messages', self::MODEL_MESSAGE))
|
||||
->setModel(new BaseList('Topic list', self::MODEL_TOPIC_LIST, 'topics', self::MODEL_TOPIC))
|
||||
->setModel(new BaseList('Subscriber list', self::MODEL_SUBSCRIBER_LIST, 'subscribers', self::MODEL_SUBSCRIBER))
|
||||
->setModel(new BaseList('Target list', self::MODEL_TARGET_LIST, 'targets', self::MODEL_TARGET))
|
||||
// Entities
|
||||
->setModel(new Database())
|
||||
->setModel(new Collection())
|
||||
|
|
@ -361,6 +382,11 @@ class Response extends SwooleResponse
|
|||
->setModel(new TemplateSMS())
|
||||
->setModel(new TemplateEmail())
|
||||
->setModel(new ConsoleVariables())
|
||||
->setModel(new Provider())
|
||||
->setModel(new Message())
|
||||
->setModel(new Topic())
|
||||
->setModel(new Subscriber())
|
||||
->setModel(new Target())
|
||||
// Verification
|
||||
// Recovery
|
||||
// Tests (keep last)
|
||||
|
|
|
|||
97
src/Appwrite/Utopia/Response/Model/Message.php
Normal file
97
src/Appwrite/Utopia/Response/Model/Message.php
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
use Utopia\Database\DateTime;
|
||||
|
||||
class Message extends Model
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Message ID.',
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('providerId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Provider Id for the message.',
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('data', [
|
||||
'type' => self::TYPE_JSON,
|
||||
'description' => 'Message Data.',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
'example' => '',
|
||||
])
|
||||
->addRule('to', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Recipient of message.',
|
||||
'default' => '',
|
||||
'example' => ['user-1'],
|
||||
])
|
||||
->addRule('deliveryTime', [
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Recipient of message.',
|
||||
'required' => false,
|
||||
'default' => DateTime::now(),
|
||||
'example' => DateTime::now(),
|
||||
])
|
||||
->addRule('deliveryError', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Delivery error if any.',
|
||||
'required' => false,
|
||||
'default' => '',
|
||||
'example' => 'Provider not valid.',
|
||||
])
|
||||
->addRule('deliveredTo', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Number of recipients the message was delivered to.',
|
||||
'default' => '',
|
||||
'example' => 1,
|
||||
])
|
||||
->addRule('delivered', [
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
'description' => 'Status of delivery.',
|
||||
'default' => '',
|
||||
'example' => true,
|
||||
])
|
||||
->addRule('search', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Field that can be used for searching message.',
|
||||
'default' => '',
|
||||
'example' => 'Hello everyone',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Message';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_MESSAGE;
|
||||
}
|
||||
}
|
||||
63
src/Appwrite/Utopia/Response/Model/Provider.php
Normal file
63
src/Appwrite/Utopia/Response/Model/Provider.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Provider extends Model
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Provider ID.',
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The user-given name for the provider instance.',
|
||||
'default' => '',
|
||||
'example' => 'Mailgun',
|
||||
])
|
||||
->addRule('provider', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Provider name setup in Utopia.',
|
||||
'default' => '',
|
||||
'example' => 'mailgun',
|
||||
])
|
||||
->addRule('type', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Type of provider.',
|
||||
'default' => '',
|
||||
'example' => 'sms',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Provider';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_PROVIDER;
|
||||
}
|
||||
}
|
||||
63
src/Appwrite/Utopia/Response/Model/Subsciber.php
Normal file
63
src/Appwrite/Utopia/Response/Model/Subsciber.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Subscriber extends Model
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Subscriber ID.',
|
||||
'default' => '',
|
||||
'example' => '259125845563242502',
|
||||
])
|
||||
->addRule('userId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'User ID.',
|
||||
'default' => '',
|
||||
'example' => '259125845563242502',
|
||||
])
|
||||
->addRule('targetId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Target ID.',
|
||||
'default' => '',
|
||||
'example' => '259125845563242502',
|
||||
])
|
||||
->addRule('topicId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Topic ID.',
|
||||
'default' => '',
|
||||
'example' => '259125845563242502',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Subscriber';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_SUBSCRIBER;
|
||||
}
|
||||
}
|
||||
70
src/Appwrite/Utopia/Response/Model/Target.php
Normal file
70
src/Appwrite/Utopia/Response/Model/Target.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Target extends Model
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Target ID.',
|
||||
'default' => '',
|
||||
'example' => '259125845563242502',
|
||||
])
|
||||
->addRule('userId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'User ID.',
|
||||
'default' => '',
|
||||
'example' => '259125845563242502',
|
||||
])
|
||||
->addRule('providerId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Provider ID.',
|
||||
'required' => false,
|
||||
'default' => '',
|
||||
'example' => '259125845563242502',
|
||||
])
|
||||
->addRule('providerType', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The type of provider supported by this target.',
|
||||
'default' => '',
|
||||
'example' => 'sms',
|
||||
])
|
||||
->addRule('identifier', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The target identifier.',
|
||||
'default' => '',
|
||||
'example' => 'token',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Target';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_TARGET;
|
||||
}
|
||||
}
|
||||
64
src/Appwrite/Utopia/Response/Model/Topic.php
Normal file
64
src/Appwrite/Utopia/Response/Model/Topic.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class Topic extends Model
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $public = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Topic ID.',
|
||||
'default' => '',
|
||||
'example' => '259125845563242502',
|
||||
])
|
||||
->addRule('providerId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Provider ID.',
|
||||
'default' => '',
|
||||
'example' => '259125845563242502',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The name of the topic.',
|
||||
'default' => '',
|
||||
'example' => 'events',
|
||||
])
|
||||
->addRule('description', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Description of the topic.',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
'example' => 'All events related messages will be sent to this topic.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Topic';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_TOPIC;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue