1 | <?php |
||
7 | class MicrosoftTeamsMessage |
||
8 | { |
||
9 | /** @var array Params payload. */ |
||
10 | protected $payload = []; |
||
11 | |||
12 | /** @var string webhook url of recipient. */ |
||
13 | protected $webhookUrl = null; |
||
14 | |||
15 | /** |
||
16 | * @param string $content |
||
17 | * |
||
18 | * @return self |
||
19 | */ |
||
20 | public static function create(string $content = ''): self |
||
24 | |||
25 | /** |
||
26 | * Message constructor. |
||
27 | * |
||
28 | * @param string $content |
||
29 | */ |
||
30 | 40 | public function __construct(string $content = '') |
|
38 | |||
39 | /** |
||
40 | * Set a title. |
||
41 | * |
||
42 | * @param string $title - title |
||
43 | * @param array $params - optional section can be defined (e.g. [$section = '1']. |
||
44 | * |
||
45 | * @return MicrosoftTeamsMessage $this |
||
46 | */ |
||
47 | 9 | public function title(string $title, array $params = []): self |
|
60 | |||
61 | /** |
||
62 | * Set a summary. |
||
63 | * |
||
64 | * @param string $summary - summary |
||
65 | * |
||
66 | * @return MicrosoftTeamsMessage $this |
||
67 | */ |
||
68 | 1 | public function summary(string $summary): self |
|
74 | |||
75 | /** |
||
76 | * Add a type which is used as theme color. |
||
77 | * |
||
78 | * @param string $type - type of the card |
||
79 | * |
||
80 | * @return MicrosoftTeamsMessage $this |
||
81 | */ |
||
82 | 2 | public function type(string $type): self |
|
88 | |||
89 | /** |
||
90 | * Notification message (Supports Markdown). |
||
91 | * |
||
92 | * @param string $content |
||
93 | * @param array $params - optional section can be defined (e.g. [$section = '1']. |
||
94 | * |
||
95 | * @return MicrosoftTeamsMessage $this |
||
96 | */ |
||
97 | 40 | public function content(string $content, array $params = []): self |
|
109 | |||
110 | /** |
||
111 | * Add an action. |
||
112 | * |
||
113 | * @param string $name - name of the action |
||
114 | * @param string $type - defaults to 'OpenUri' should be one of the following types: |
||
115 | * - OpenUri: Opens a URI in a separate browser or app; optionally targets different URIs based on operating systems |
||
116 | * - HttpPOST: Sends a POST request to a URL |
||
117 | * - ActionCard: Presents one or more input types and associated actions |
||
118 | * - InvokeAddInCommand: Opens an Outlook add-in task pane. |
||
119 | * * @param array $params - optional params (needed for complex types and for section) |
||
120 | * For more information check out: https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference |
||
121 | * |
||
122 | * @return MicrosoftTeamsMessage $this |
||
123 | */ |
||
124 | 10 | public function action(string $name, $type = 'OpenUri', array $params = []): self |
|
150 | |||
151 | /** |
||
152 | * Add a button. |
||
153 | * Wrapper for a potential action by just providing $text and $url params. |
||
154 | * |
||
155 | * @param string $text - label of the button |
||
156 | * @param string $url - url to forward to |
||
157 | * @param array $params - optional params (needed for more complex types and for section) |
||
158 | * For more information check out: https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#openuri-action |
||
159 | * |
||
160 | * @return MicrosoftTeamsMessage $this |
||
161 | */ |
||
162 | 8 | public function button(string $text, string $url = '', array $params = []): self |
|
184 | |||
185 | /** |
||
186 | * Add a startGroup property which marks the start of a logical group of information (only for sections). |
||
187 | * |
||
188 | * @param string|int $sectionId - in which section to put the property, defaults to standard_section |
||
189 | * |
||
190 | * @return MicrosoftTeamsMessage $this |
||
191 | */ |
||
192 | 3 | public function addStartGroupToSection($sectionId = 'standard_section'): self |
|
198 | |||
199 | /** |
||
200 | * Add an activity to a section. |
||
201 | * |
||
202 | * @param string $activityImage |
||
203 | * @param string $activityTitle |
||
204 | * @param string $activitySubtitle |
||
205 | * @param string $activityText |
||
206 | * @param string|int $sectionId - in which section to put the property, defaults to standard_section |
||
207 | * |
||
208 | * @return MicrosoftTeamsMessage $this |
||
209 | */ |
||
210 | 2 | public function activity(string $activityImage = '', string $activityTitle = '', string $activitySubtitle = '', string $activityText = '', $sectionId = 'standard_section'): self |
|
219 | |||
220 | /** |
||
221 | * Add a fact to a section (Supports Markdown). |
||
222 | * |
||
223 | * @param string $name |
||
224 | * @param string $value |
||
225 | * @param string|int $sectionId - in which section to put the property, defaults to standard_section |
||
226 | * |
||
227 | * @return MicrosoftTeamsMessage $this |
||
228 | */ |
||
229 | 4 | public function fact(string $name, string $value, $sectionId = 'standard_section'): self |
|
236 | |||
237 | /** |
||
238 | * Add an image to a section. |
||
239 | * |
||
240 | * @param string $imageUri - The URL to the image. |
||
241 | * @param string $title - A short description of the image. Typically, title is displayed in a tooltip as the user hovers their mouse over the image |
||
242 | * @param string|int $sectionId - in which section to put the property, defaults to standard_section |
||
243 | * |
||
244 | * @return MicrosoftTeamsMessage $this |
||
245 | */ |
||
246 | 4 | public function image(string $imageUri, string $title = '', $sectionId = 'standard_section'): self |
|
256 | |||
257 | /** |
||
258 | * Add a hero image to a section. |
||
259 | * |
||
260 | * @param string $imageUri - The URL to the image. |
||
261 | * @param string $title - A short description of the image. Typically, title is displayed in a tooltip as the user hovers their mouse over the image |
||
262 | * @param string|int $sectionId - in which section to put the property, defaults to standard_section |
||
263 | * |
||
264 | * @return MicrosoftTeamsMessage $this |
||
265 | */ |
||
266 | 3 | public function heroImage(string $imageUri, string $title = '', $sectionId = 'standard_section'): self |
|
276 | |||
277 | /** |
||
278 | * Additional options to pass to message payload object. |
||
279 | * |
||
280 | * @param array $options |
||
281 | * @param string|int $sectionId - optional in which section to put the property |
||
282 | * |
||
283 | * @return MicrosoftTeamsMessage $this |
||
284 | */ |
||
285 | 3 | public function options(array $options, $sectionId = null): self |
|
294 | |||
295 | /** |
||
296 | * Recipient's webhook url. |
||
297 | * |
||
298 | * @param $webhookUrl - url of webhook |
||
299 | * |
||
300 | * @throws CouldNotSendNotification |
||
301 | * |
||
302 | * @return MicrosoftTeamsMessage $this |
||
303 | */ |
||
304 | 7 | public function to(?string $webhookUrl): self |
|
313 | |||
314 | /** |
||
315 | * Get webhook url. |
||
316 | * |
||
317 | * @return string $webhookUrl |
||
318 | */ |
||
319 | 4 | public function getWebhookUrl(): string |
|
323 | |||
324 | /** |
||
325 | * Determine if webhook url is not given. |
||
326 | * |
||
327 | * @return bool |
||
328 | */ |
||
329 | 4 | public function toNotGiven(): bool |
|
333 | |||
334 | /** |
||
335 | * Get payload value for given key. |
||
336 | * |
||
337 | * @param string $key |
||
338 | * |
||
339 | * @return mixed|null |
||
340 | */ |
||
341 | 30 | public function getPayloadValue(string $key) |
|
345 | |||
346 | /** |
||
347 | * Generate a colour code use given by name of type, fallback to primary |
||
348 | * if named color not found the type should be a hex color code. |
||
349 | * |
||
350 | * @param string $type |
||
351 | * |
||
352 | * @return string |
||
353 | */ |
||
354 | 40 | private function generateThemeColourCode($type = 'primary'): string |
|
368 | |||
369 | /** |
||
370 | * Returns params payload. |
||
371 | * |
||
372 | * @return array |
||
373 | */ |
||
374 | 5 | public function toArray(): array |
|
378 | } |
||
379 |