1 | <?php |
||
7 | class Message |
||
8 | { |
||
9 | /** |
||
10 | * Reference to the Slack client responsible for sending |
||
11 | * the message. |
||
12 | * |
||
13 | * @var \Maknz\Slack\Client |
||
14 | */ |
||
15 | protected $client; |
||
16 | |||
17 | /** |
||
18 | * The text to send with the message. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $text; |
||
23 | |||
24 | /** |
||
25 | * The channel the message should be sent to. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $channel; |
||
30 | |||
31 | /** |
||
32 | * The username the message should be sent as. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $username; |
||
37 | |||
38 | /** |
||
39 | * The URL to the icon to use. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $icon; |
||
44 | |||
45 | /** |
||
46 | * The type of icon we are using. |
||
47 | * |
||
48 | * @var enum |
||
49 | */ |
||
50 | protected $iconType; |
||
51 | |||
52 | /** |
||
53 | * Whether the message text should be interpreted in Slack's |
||
54 | * Markdown-like language. |
||
55 | * |
||
56 | * @var bool |
||
57 | */ |
||
58 | protected $allow_markdown = true; |
||
59 | |||
60 | /** |
||
61 | * The attachment fields which should be formatted with |
||
62 | * Slack's Markdown-like language. |
||
63 | * |
||
64 | * @var array |
||
65 | */ |
||
66 | protected $markdown_in_attachments = []; |
||
67 | |||
68 | /** |
||
69 | * An array of attachments to send. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $attachments = []; |
||
74 | |||
75 | /** |
||
76 | * @var string |
||
77 | */ |
||
78 | const ICON_TYPE_URL = 'icon_url'; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | */ |
||
83 | const ICON_TYPE_EMOJI = 'icon_emoji'; |
||
84 | |||
85 | /** |
||
86 | * Instantiate a new Message. |
||
87 | * |
||
88 | * @param \Maknz\Slack\Client $client |
||
89 | * @return void |
||
|
|||
90 | */ |
||
91 | public function __construct(Client $client) |
||
95 | |||
96 | /** |
||
97 | * Get the message text. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getText() |
||
105 | |||
106 | /** |
||
107 | * Set the message text. |
||
108 | * |
||
109 | * @param string $text |
||
110 | * @return $this |
||
111 | */ |
||
112 | public function setText($text) |
||
118 | |||
119 | /** |
||
120 | * Get the channel we will post to. |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | public function getChannel() |
||
128 | |||
129 | /** |
||
130 | * Set the channel we will post to. |
||
131 | * |
||
132 | * @param string $channel |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function setChannel($channel) |
||
141 | |||
142 | /** |
||
143 | * Get the username we will post as. |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | public function getUsername() |
||
151 | |||
152 | /** |
||
153 | * Set the username we will post as. |
||
154 | * |
||
155 | * @param string $username |
||
156 | * @return $this |
||
157 | */ |
||
158 | public function setUsername($username) |
||
164 | |||
165 | /** |
||
166 | * Get the icon (either URL or emoji) we will post as. |
||
167 | * |
||
168 | * @return string |
||
169 | */ |
||
170 | public function getIcon() |
||
174 | |||
175 | /** |
||
176 | * Set the icon (either URL or emoji) we will post as. |
||
177 | * |
||
178 | * @param string $icon |
||
179 | * @return $this |
||
180 | */ |
||
181 | public function setIcon($icon) |
||
199 | |||
200 | /** |
||
201 | * Get the icon type being used, if an icon is set. |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getIconType() |
||
209 | |||
210 | /** |
||
211 | * Get whether message text should be formatted with |
||
212 | * Slack's Markdown-like language. |
||
213 | * |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function getAllowMarkdown() |
||
220 | |||
221 | /** |
||
222 | * Set whether message text should be formatted with |
||
223 | * Slack's Markdown-like language. |
||
224 | * |
||
225 | * @param bool $value |
||
226 | * @return void |
||
227 | */ |
||
228 | public function setAllowMarkdown($value) |
||
234 | |||
235 | /** |
||
236 | * Enable Markdown formatting for the message. |
||
237 | * |
||
238 | * @return void |
||
239 | */ |
||
240 | public function enableMarkdown() |
||
246 | |||
247 | /** |
||
248 | * Disable Markdown formatting for the message. |
||
249 | * |
||
250 | * @return void |
||
251 | */ |
||
252 | public function disableMarkdown() |
||
258 | |||
259 | /** |
||
260 | * Get the attachment fields which should be formatted |
||
261 | * in Slack's Markdown-like language. |
||
262 | * |
||
263 | * @return array |
||
264 | */ |
||
265 | public function getMarkdownInAttachments() |
||
269 | |||
270 | /** |
||
271 | * Set the attachment fields which should be formatted |
||
272 | * in Slack's Markdown-like language. |
||
273 | * |
||
274 | * @param array $fields |
||
275 | * @return void |
||
276 | */ |
||
277 | public function setMarkdownInAttachments(array $fields) |
||
283 | |||
284 | /** |
||
285 | * Change the name of the user the post will be made as. |
||
286 | * |
||
287 | * @param string $username |
||
288 | * @return $this |
||
289 | */ |
||
290 | public function from($username) |
||
296 | |||
297 | /** |
||
298 | * Change the channel the post will be made to. |
||
299 | * |
||
300 | * @param string $channel |
||
301 | * @return $this |
||
302 | */ |
||
303 | public function to($channel) |
||
309 | |||
310 | /** |
||
311 | * Chainable method for setting the icon. |
||
312 | * |
||
313 | * @param string $icon |
||
314 | * @return $this |
||
315 | */ |
||
316 | public function withIcon($icon) |
||
322 | |||
323 | /** |
||
324 | * Add an attachment to the message. |
||
325 | * |
||
326 | * @param mixed $attachment |
||
327 | * @return $this |
||
328 | */ |
||
329 | public function attach($attachment) |
||
349 | |||
350 | /** |
||
351 | * Get the attachments for the message. |
||
352 | * |
||
353 | * @return array |
||
354 | */ |
||
355 | public function getAttachments() |
||
359 | |||
360 | /** |
||
361 | * Set the attachments for the message. |
||
362 | * |
||
363 | * @param array $attachments |
||
364 | * @return $this |
||
365 | */ |
||
366 | public function setAttachments(array $attachments) |
||
376 | |||
377 | /** |
||
378 | * Remove all attachments for the message. |
||
379 | * |
||
380 | * @return $this |
||
381 | */ |
||
382 | public function clearAttachments() |
||
388 | |||
389 | /** |
||
390 | * Send the message. |
||
391 | * |
||
392 | * @param string $text The text to send |
||
393 | * @return void |
||
394 | */ |
||
395 | public function send($text = null) |
||
405 | } |
||
406 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.