1 | <?php |
||
9 | class Message implements \JsonSerializable |
||
10 | { |
||
11 | |||
12 | use ValidatorTrait; |
||
13 | |||
14 | const TYPE_TEXT = 'text'; |
||
15 | const TYPE_ATTACHMENT = 'attachment'; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $type; |
||
21 | |||
22 | /** |
||
23 | * @var \Kerox\Messenger\Model\Message\Attachment|string |
||
24 | */ |
||
25 | protected $message; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $quickReplies = []; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $metadata; |
||
36 | |||
37 | /** |
||
38 | * Message constructor. |
||
39 | * |
||
40 | * @param \Kerox\Messenger\Model\Message\Attachment|string $message |
||
41 | */ |
||
42 | 9 | public function __construct($message) |
|
43 | { |
||
44 | 9 | if (is_string($message)) { |
|
45 | 4 | $this->isValidString($message, 640); |
|
46 | 4 | $this->type = self::TYPE_TEXT; |
|
47 | 5 | } elseif ($message instanceof Attachment) { |
|
48 | 4 | $this->type = self::TYPE_ATTACHMENT; |
|
49 | } else { |
||
50 | 1 | throw new \InvalidArgumentException('$message must be a string or an instance of Attachment.'); |
|
51 | } |
||
52 | |||
53 | 8 | $this->message = $message; |
|
54 | 8 | } |
|
55 | |||
56 | /** |
||
57 | * @param mixed $quickReplies |
||
58 | * @return \Kerox\Messenger\Model\Message |
||
59 | * @throws \Exception |
||
60 | */ |
||
61 | 1 | public function setQuickReplies(array $quickReplies): Message |
|
68 | |||
69 | /** |
||
70 | * @param \Kerox\Messenger\Model\Message\QuickReply $quickReply |
||
71 | * @return \Kerox\Messenger\Model\Message |
||
72 | */ |
||
73 | 1 | public function addQuickReply(QuickReply $quickReply): Message |
|
79 | |||
80 | /** |
||
81 | * @param mixed $metadata |
||
82 | * @return Message |
||
83 | */ |
||
84 | 1 | public function setMetadata(string $metadata): Message |
|
91 | |||
92 | /** |
||
93 | * @return array |
||
94 | */ |
||
95 | 7 | public function jsonSerialize(): array |
|
105 | } |
||
106 |