1 | <?php namespace Maknz\Slack; |
||
5 | class Message { |
||
6 | |||
7 | /** |
||
8 | * Reference to the Slack client responsible for sending |
||
9 | * the message |
||
10 | * |
||
11 | * @var \Maknz\Slack\Client |
||
12 | */ |
||
13 | protected $client; |
||
14 | |||
15 | /** |
||
16 | * The text to send with the message |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $text; |
||
21 | |||
22 | /** |
||
23 | * The target endpoint the message should be sent to |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $endpoint; |
||
28 | |||
29 | /** |
||
30 | * The channel the message should be sent to |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $channel; |
||
35 | |||
36 | /** |
||
37 | * The username the message should be sent as |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $username; |
||
42 | |||
43 | /** |
||
44 | * The URL to the icon to use |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $icon; |
||
49 | |||
50 | /** |
||
51 | * The type of icon we are using |
||
52 | * |
||
53 | * @var enum |
||
54 | */ |
||
55 | protected $iconType; |
||
56 | |||
57 | /** |
||
58 | * Whether the message text should be interpreted in Slack's |
||
59 | * Markdown-like language |
||
60 | * |
||
61 | * @var boolean |
||
62 | */ |
||
63 | protected $allow_markdown = true; |
||
64 | |||
65 | /** |
||
66 | * The attachment fields which should be formatted with |
||
67 | * Slack's Markdown-like language |
||
68 | * |
||
69 | * @var array |
||
70 | */ |
||
71 | protected $markdown_in_attachments = []; |
||
72 | |||
73 | /** |
||
74 | * An array of attachments to send |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $attachments = []; |
||
79 | |||
80 | /** |
||
81 | * |
||
82 | * @var string |
||
83 | */ |
||
84 | const ICON_TYPE_URL = 'icon_url'; |
||
85 | |||
86 | /** |
||
87 | * |
||
88 | * @var string |
||
89 | */ |
||
90 | const ICON_TYPE_EMOJI = 'icon_emoji'; |
||
91 | |||
92 | /** |
||
93 | * Instantiate a new Message |
||
94 | * |
||
95 | * @param \Maknz\Slack\Client $client |
||
96 | * @return void |
||
|
|||
97 | */ |
||
98 | public function __construct(Client $client) |
||
102 | |||
103 | /** |
||
104 | * Get the message text |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | public function getText() |
||
112 | |||
113 | /** |
||
114 | * Set the message text |
||
115 | * |
||
116 | * @param string $text |
||
117 | * @return $this |
||
118 | */ |
||
119 | public function setText($text) |
||
125 | |||
126 | /** |
||
127 | * Get the message endpoint |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | public function getEndpoint() |
||
135 | |||
136 | /** |
||
137 | * Set the message endpoint |
||
138 | * |
||
139 | * @param string $endpoint |
||
140 | * @return $this |
||
141 | * @throws \InvalidArgumentException |
||
142 | */ |
||
143 | public function setEndpoint($endpoint) |
||
153 | |||
154 | /** |
||
155 | * Get the channel we will post to |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | public function getChannel() |
||
163 | |||
164 | /** |
||
165 | * Set the channel we will post to |
||
166 | * |
||
167 | * @param string $channel |
||
168 | * @return $this |
||
169 | */ |
||
170 | public function setChannel($channel) |
||
176 | |||
177 | /** |
||
178 | * Get the username we will post as |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | public function getUsername() |
||
186 | |||
187 | /** |
||
188 | * Set the username we will post as |
||
189 | * |
||
190 | * @param string $username |
||
191 | * @return $this |
||
192 | */ |
||
193 | public function setUsername($username) |
||
199 | |||
200 | /** |
||
201 | * Get the icon (either URL or emoji) we will post as |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getIcon() |
||
209 | |||
210 | /** |
||
211 | * Set the icon (either URL or emoji) we will post as. |
||
212 | * |
||
213 | * @param string $icon |
||
214 | * @return this |
||
215 | */ |
||
216 | public function setIcon($icon) |
||
239 | |||
240 | /** |
||
241 | * Get the icon type being used, if an icon is set |
||
242 | * |
||
243 | * @return string |
||
244 | */ |
||
245 | public function getIconType() |
||
249 | |||
250 | /** |
||
251 | * Get whether message text should be formatted with |
||
252 | * Slack's Markdown-like language |
||
253 | * |
||
254 | * @return boolean |
||
255 | */ |
||
256 | public function getAllowMarkdown() |
||
260 | |||
261 | /** |
||
262 | * Set whether message text should be formatted with |
||
263 | * Slack's Markdown-like language |
||
264 | * |
||
265 | * @param boolean $value |
||
266 | * @return void |
||
267 | */ |
||
268 | public function setAllowMarkdown($value) |
||
274 | |||
275 | /** |
||
276 | * Enable Markdown formatting for the message |
||
277 | * |
||
278 | * @return void |
||
279 | */ |
||
280 | public function enableMarkdown() |
||
286 | |||
287 | /** |
||
288 | * Disable Markdown formatting for the message |
||
289 | * |
||
290 | * @return void |
||
291 | */ |
||
292 | public function disableMarkdown() |
||
298 | |||
299 | /** |
||
300 | * Get the attachment fields which should be formatted |
||
301 | * in Slack's Markdown-like language |
||
302 | * |
||
303 | * @return array |
||
304 | */ |
||
305 | public function getMarkdownInAttachments() |
||
309 | |||
310 | /** |
||
311 | * Set the attachment fields which should be formatted |
||
312 | * in Slack's Markdown-like language |
||
313 | * |
||
314 | * @param array $fields |
||
315 | * @return void |
||
316 | */ |
||
317 | public function setMarkdownInAttachments(array $fields) |
||
323 | |||
324 | /** |
||
325 | * Change the name of the user the post will be made as |
||
326 | * |
||
327 | * @param string $username |
||
328 | * @return $this |
||
329 | */ |
||
330 | public function from($username) |
||
336 | |||
337 | /** |
||
338 | * Change the endpoint the post will be made to |
||
339 | * |
||
340 | * @param string $endpoint |
||
341 | * @return $this |
||
342 | */ |
||
343 | public function endpoint($endpoint) |
||
347 | |||
348 | /** |
||
349 | * Change the channel the post will be made to |
||
350 | * |
||
351 | * @param string $channel |
||
352 | * @return $this |
||
353 | */ |
||
354 | public function to($channel) |
||
360 | |||
361 | /** |
||
362 | * Chainable method for setting the icon |
||
363 | * |
||
364 | * @param string $icon |
||
365 | * @return $this |
||
366 | */ |
||
367 | public function withIcon($icon) |
||
373 | |||
374 | /** |
||
375 | * Add an attachment to the message |
||
376 | * |
||
377 | * @param mixed $attachment |
||
378 | * @return $this |
||
379 | * @throws \InvalidArgumentException |
||
380 | */ |
||
381 | public function attach($attachment) |
||
406 | |||
407 | /** |
||
408 | * Get the attachments for the message |
||
409 | * |
||
410 | * @return array |
||
411 | */ |
||
412 | public function getAttachments() |
||
416 | |||
417 | /** |
||
418 | * Set the attachments for the message |
||
419 | * |
||
420 | * @param string $attachments |
||
421 | * @return $this |
||
422 | */ |
||
423 | public function setAttachments(array $attachments) |
||
434 | |||
435 | /** |
||
436 | * Remove all attachments for the message |
||
437 | * |
||
438 | * @return $this |
||
439 | */ |
||
440 | public function clearAttachments() |
||
446 | |||
447 | /** |
||
448 | * Send the message |
||
449 | * |
||
450 | * @param string $text The text to send |
||
451 | * @return void |
||
452 | */ |
||
453 | public function send($text = null) |
||
459 | |||
460 | } |
||
461 |
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.