-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMessage.php
More file actions
144 lines (116 loc) · 3.87 KB
/
Message.php
File metadata and controls
144 lines (116 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
namespace SlackPhp\BlockKit\Surfaces;
use SlackPhp\BlockKit\{FauxProperty,
Property,
Surfaces\MessageDirective\DeleteOriginal,
Surfaces\MessageDirective\ReplaceOriginal,
Surfaces\MessageDirective\ResponseType};
use SlackPhp\BlockKit\Blocks\Block;
use SlackPhp\BlockKit\Collections\{AttachmentCollection, BlockCollection};
use SlackPhp\BlockKit\Hydration\OmitType;
use SlackPhp\BlockKit\Validation\{RequiresAnyOf, UniqueIds, ValidCollection, ValidString};
/**
* @see https://api.slack.com/surfaces
*/
#[OmitType, RequiresAnyOf('blocks', 'text', 'attachments')]
class Message extends Surface
{
#[Property, ValidCollection(50, 0), UniqueIds]
public BlockCollection $blocks;
#[FauxProperty('response_type')]
public ?ResponseType $responseType;
#[FauxProperty('replace_original')]
public ?ReplaceOriginal $replaceOriginal;
#[FauxProperty('delete_original')]
public ?DeleteOriginal $deleteOriginal;
#[Property, ValidString]
public ?string $text;
#[Property, ValidCollection(10, 0)]
public AttachmentCollection $attachments;
#[Property]
public ?bool $mrkdwn;
#[Property, ValidString]
public ?string $threadTs;
/**
* @param BlockCollection|array<Block|string>|null $blocks
* @param AttachmentCollection|array<Attachment>|null $attachments
*/
public function __construct(
BlockCollection|array|null $blocks = null,
?ResponseType $directive = null,
?string $text = null,
AttachmentCollection|array|null $attachments = null,
?bool $mrkdwn = null,
?string $threadTs = null,
?bool $ephemeral = null,
?bool $replaceOriginal = null,
?bool $deleteOriginal = null,
) {
parent::__construct($blocks);
$this->attachments = AttachmentCollection::wrap($attachments);
$this->responseType($directive ?? ($ephemeral ? ResponseType::EPHEMERAL : null));
$this->text($text);
$this->mrkdwn($mrkdwn);
$this->threadTs($threadTs);
$this->replaceOriginal($replaceOriginal);
$this->deleteOriginal($deleteOriginal);
}
/**
* Configures message to send privately to the user.
*
* This is default behavior for most interactions, and doesn't necessarily need to be explicitly configured.
*/
public function ephemeral(): static
{
return $this->responseType(ResponseType::EPHEMERAL);
}
/**
* Configures message to send to the entire channel.
*/
public function inChannel(): static
{
return $this->responseType(ResponseType::IN_CHANNEL);
}
/**
* Configures message to "replace_original" mode.
*/
public function replaceOriginal(ReplaceOriginal|array|bool|null $replaceOriginal = true): static
{
$this->replaceOriginal = ReplaceOriginal::fromValue($replaceOriginal);
return $this;
}
/**
* Configures message to "delete_original" mode.
*/
public function deleteOriginal(DeleteOriginal|array|bool|null $deleteOriginal = true): static
{
$this->deleteOriginal = DeleteOriginal::fromValue($deleteOriginal);
return $this;
}
public function responseType(ResponseType|array|null $responseType): static
{
$this->responseType = ResponseType::fromValue($responseType);
return $this;
}
public function text(?string $text): static
{
$this->text = $text;
return $this;
}
public function mrkdwn(?bool $mrkdwn): static
{
$this->mrkdwn = $mrkdwn;
return $this;
}
public function threadTs(?string $threadTs): static
{
$this->threadTs = $threadTs;
return $this;
}
public function attachments(AttachmentCollection|Attachment|null ...$attachments): static
{
$this->attachments->append(...$attachments);
return $this;
}
}