1 | <?php |
||
10 | class Attachment |
||
11 | { |
||
12 | const COLOR_GOOD = 'good'; |
||
13 | const COLOR_WARNING = 'warning'; |
||
14 | const COLOR_DANGER = 'danger'; |
||
15 | |||
16 | /** |
||
17 | * The fallback text to use for clients that don't support attachments. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $fallback; |
||
22 | |||
23 | /** |
||
24 | * Optional text that should appear within the attachment. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $text = ''; |
||
29 | |||
30 | /** |
||
31 | * Optional image that should appear within the attachment. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $imageUrl; |
||
36 | |||
37 | /** |
||
38 | * Optional thumbnail that should appear within the attachment. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $thumbUrl; |
||
43 | |||
44 | /** |
||
45 | * Optional text that should appear above the formatted data. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $preText; |
||
50 | |||
51 | /** |
||
52 | * Optional title for the attachment. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $title; |
||
57 | |||
58 | /** |
||
59 | * Optional title link for the attachment. |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $titleLink; |
||
64 | |||
65 | /** |
||
66 | * Optional author name for the attachment. |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $authorName; |
||
71 | |||
72 | /** |
||
73 | * Optional author link for the attachment. |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | protected $authorLink; |
||
78 | |||
79 | /** |
||
80 | * Optional author icon for the attachment. |
||
81 | * |
||
82 | * @var string |
||
83 | */ |
||
84 | protected $authorIcon; |
||
85 | |||
86 | /** |
||
87 | * The color to use for the attachment. |
||
88 | * |
||
89 | * @var string |
||
90 | */ |
||
91 | protected $color; |
||
92 | |||
93 | /** |
||
94 | * The text to use for the attachment footer. |
||
95 | * |
||
96 | * @var string |
||
97 | */ |
||
98 | protected $footer; |
||
99 | |||
100 | /** |
||
101 | * The icon to use for the attachment footer. |
||
102 | * |
||
103 | * @var string |
||
104 | */ |
||
105 | protected $footerIcon; |
||
106 | |||
107 | /** |
||
108 | * The timestamp to use for the attachment. |
||
109 | * |
||
110 | * @var \DateTime |
||
111 | */ |
||
112 | protected $timestamp; |
||
113 | |||
114 | /** |
||
115 | * The callback id to use for the attachment. |
||
116 | * |
||
117 | * @var string |
||
118 | */ |
||
119 | protected $callbackId; |
||
120 | |||
121 | /** |
||
122 | * The fields of the attachment. |
||
123 | * |
||
124 | * @var \Illuminate\Support\Collection |
||
125 | */ |
||
126 | protected $fields; |
||
127 | |||
128 | /** |
||
129 | * Use message formatting. |
||
130 | * |
||
131 | * @var bool |
||
132 | */ |
||
133 | protected $useMarkdown = false; |
||
134 | |||
135 | /** |
||
136 | * The actions of the attachment. |
||
137 | * |
||
138 | * @var \Illuminate\Support\Collection |
||
139 | */ |
||
140 | protected $actions; |
||
141 | |||
142 | public static function create() |
||
146 | |||
147 | public function __construct() |
||
153 | |||
154 | /** |
||
155 | * Set the fallback text. |
||
156 | * |
||
157 | * @param string $fallback |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function setFallback(string $fallback) |
||
167 | |||
168 | /** |
||
169 | * Set the optional text to appear within the attachment. |
||
170 | * |
||
171 | * @param string $text |
||
172 | * |
||
173 | * @return $this |
||
174 | */ |
||
175 | public function setText($text) |
||
181 | |||
182 | /** |
||
183 | * Set the optional image to appear within the attachment. |
||
184 | * |
||
185 | * @param string $imageUrl |
||
186 | * |
||
187 | * @return $this |
||
188 | */ |
||
189 | public function setImageUrl(string $imageUrl) |
||
195 | |||
196 | /** |
||
197 | * Set the optional thumbnail to appear within the attachment. |
||
198 | * |
||
199 | * @param string $thumbUrl |
||
200 | * |
||
201 | * @return $this |
||
202 | */ |
||
203 | public function setThumbUrl(string $thumbUrl) |
||
209 | |||
210 | /** |
||
211 | * Set the text that should appear above the formatted data. |
||
212 | * |
||
213 | * @param string $preText |
||
214 | * |
||
215 | * @return $this |
||
216 | */ |
||
217 | public function setPreText(string $preText) |
||
223 | |||
224 | /** |
||
225 | * Set the color to use for the attachment. |
||
226 | * |
||
227 | * @param string $color |
||
228 | * |
||
229 | * @return $this |
||
230 | */ |
||
231 | public function setColor($color) |
||
237 | |||
238 | /** |
||
239 | * Set the footer text to use for the attachment. |
||
240 | * |
||
241 | * @param string $footer |
||
242 | * |
||
243 | * @return $this |
||
244 | */ |
||
245 | public function setFooter(string $footer) |
||
251 | |||
252 | /** |
||
253 | * Set the footer icon to use for the attachment. |
||
254 | * |
||
255 | * @param string $footerIcon |
||
256 | * |
||
257 | * @return $this |
||
258 | */ |
||
259 | public function setFooterIcon(string $footerIcon) |
||
265 | |||
266 | /** |
||
267 | * Set the timestamp to use for the attachment. |
||
268 | * |
||
269 | * @param \DateTime $timestamp |
||
270 | * |
||
271 | * @return $this |
||
272 | */ |
||
273 | public function setTimestamp(DateTime $timestamp) |
||
279 | |||
280 | /** |
||
281 | * Set the title to use for the attachment. |
||
282 | * |
||
283 | * @param string $title |
||
284 | * |
||
285 | * @return $this |
||
286 | */ |
||
287 | public function setTitle(string $title) |
||
293 | |||
294 | /** |
||
295 | * Set the title link to use for the attachment. |
||
296 | * |
||
297 | * @param string $titleLink |
||
298 | * |
||
299 | * @return $this |
||
300 | */ |
||
301 | public function setTitleLink(string $titleLink) |
||
307 | |||
308 | /** |
||
309 | * Set the author name to use for the attachment. |
||
310 | * |
||
311 | * @param string $authorName |
||
312 | * |
||
313 | * @return $this |
||
314 | */ |
||
315 | public function setAuthorName(string $authorName) |
||
321 | |||
322 | /** |
||
323 | * Enable simple markup language. |
||
324 | * |
||
325 | * @return $this |
||
326 | */ |
||
327 | public function useMarkdown() |
||
333 | |||
334 | /** |
||
335 | * Set the auhtor link to use for the attachment. |
||
336 | * |
||
337 | * @param string $authorLink |
||
338 | * |
||
339 | * @return $this |
||
340 | */ |
||
341 | public function setAuthorLink(string $authorLink) |
||
347 | |||
348 | /** |
||
349 | * Set the author icon to use for the attachment. |
||
350 | * |
||
351 | * @param string $authorIcon |
||
352 | * |
||
353 | * @return $this |
||
354 | */ |
||
355 | public function setAuthorIcon(string $authorIcon) |
||
361 | |||
362 | /** |
||
363 | * Set the callback id to use for the attachment. |
||
364 | * |
||
365 | * @param string $callbackId |
||
366 | * |
||
367 | * @return $this |
||
368 | */ |
||
369 | public function setCallbackId(string $callbackId) |
||
375 | |||
376 | /** |
||
377 | * Add a field to the attachment. |
||
378 | * |
||
379 | * @param \Spatie\SlashCommand\AttachmentField|array $field |
||
380 | * |
||
381 | * @return $this |
||
382 | * |
||
383 | * @throws \Spatie\SlashCommand\Exceptions\FieldCannotBeAdded |
||
384 | */ |
||
385 | public function addField($field) |
||
402 | |||
403 | /** |
||
404 | * Add the fields for the attachment. |
||
405 | * |
||
406 | * @param array $fields |
||
407 | * |
||
408 | * @return $this |
||
409 | */ |
||
410 | public function addFields(array $fields) |
||
422 | |||
423 | /** |
||
424 | * Set the fields for the attachment. |
||
425 | * |
||
426 | * @param array $fields |
||
427 | * |
||
428 | * @return $this |
||
429 | */ |
||
430 | public function setFields(array $fields) |
||
438 | |||
439 | /** |
||
440 | * Clear all fields for this attachment. |
||
441 | * |
||
442 | * @return $this |
||
443 | */ |
||
444 | public function clearFields() |
||
450 | |||
451 | /** |
||
452 | * @param \Spatie\SlashCommand\AttachmentAction|array $action |
||
453 | * |
||
454 | * @return $this |
||
455 | * @throws \Spatie\SlashCommand\Exceptions\ActionCannotBeAdded |
||
456 | */ |
||
457 | public function addAction($action) |
||
475 | |||
476 | /** |
||
477 | * Add the actions for the attachment. |
||
478 | * |
||
479 | * @param array $actions |
||
480 | * |
||
481 | * @return $this |
||
482 | */ |
||
483 | public function addActions(array $actions) |
||
491 | |||
492 | /** |
||
493 | * Set the actions for the attachment. |
||
494 | * |
||
495 | * @param array $actions |
||
496 | * |
||
497 | * @return $this |
||
498 | */ |
||
499 | public function setActions(array $actions) |
||
507 | |||
508 | /** |
||
509 | * Clear all actions for this attachment. |
||
510 | * |
||
511 | * @return $this |
||
512 | */ |
||
513 | public function clearActions() |
||
519 | |||
520 | /** |
||
521 | * Convert this attachment to its array representation. |
||
522 | * |
||
523 | * @return array |
||
524 | */ |
||
525 | public function toArray() |
||
552 | } |
||
553 |