Skip to content

Commit d039ce7

Browse files
OskarStarkfabpot
authored andcommitted
[Notifier] Add options to Microsoft Teams notifier
1 parent c71c872 commit d039ce7

35 files changed

+2061
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action;
13+
14+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input\InputInterface;
15+
16+
/**
17+
* @author Edouard Lescot <edouard.lescot@gmail.com>
18+
* @author Oskar Stark <oskarstark@googlemail.com>
19+
*
20+
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#actioncard-action
21+
*/
22+
final class ActionCard implements ActionInterface
23+
{
24+
private $options = [];
25+
26+
public function name(string $name): self
27+
{
28+
$this->options['name'] = $name;
29+
30+
return $this;
31+
}
32+
33+
public function input(InputInterface $inputAction): self
34+
{
35+
$this->options['inputs'][] = $inputAction->toArray();
36+
37+
return $this;
38+
}
39+
40+
public function action(ActionCardCompatibleActionInterface $action): self
41+
{
42+
$this->options['actions'][] = $action->toArray();
43+
44+
return $this;
45+
}
46+
47+
public function toArray(): array
48+
{
49+
return $this->options + ['@type' => 'ActionCard'];
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action;
13+
14+
/**
15+
* An Action which can be used inside an ActionCard.
16+
*
17+
* @author Oskar Stark <oskarstark@googlemail.com>
18+
*/
19+
interface ActionCardCompatibleActionInterface extends ActionInterface
20+
{
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action;
13+
14+
/**
15+
* @author Edouard Lescot <edouard.lescot@gmail.com>
16+
* @author Oskar Stark <oskarstark@googlemail.com>
17+
*/
18+
interface ActionInterface
19+
{
20+
public function toArray(): array;
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Element;
13+
14+
/**
15+
* @author Edouard Lescot <edouard.lescot@gmail.com>
16+
* @author Oskar Stark <oskarstark@googlemail.com>
17+
*
18+
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#header
19+
*/
20+
final class Header
21+
{
22+
private $options = [];
23+
24+
public function name(string $name): self
25+
{
26+
$this->options['name'] = $name;
27+
28+
return $this;
29+
}
30+
31+
public function value(string $value): self
32+
{
33+
$this->options['value'] = $value;
34+
35+
return $this;
36+
}
37+
38+
public function toArray(): array
39+
{
40+
return $this->options;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action;
13+
14+
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Element\Header;
15+
16+
/**
17+
* @author Edouard Lescot <edouard.lescot@gmail.com>
18+
* @author Oskar Stark <oskarstark@googlemail.com>
19+
*
20+
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#httppost-action
21+
*/
22+
final class HttpPostAction implements ActionCardCompatibleActionInterface
23+
{
24+
private $options = ['@type' => 'HttpPOST'];
25+
26+
public function name(string $name): self
27+
{
28+
$this->options['name'] = $name;
29+
30+
return $this;
31+
}
32+
33+
public function target(string $url): self
34+
{
35+
$this->options['target'] = $url;
36+
37+
return $this;
38+
}
39+
40+
public function header(Header $header): self
41+
{
42+
$this->options['headers'][] = $header->toArray();
43+
44+
return $this;
45+
}
46+
47+
public function body(string $body): self
48+
{
49+
$this->options['body'] = $body;
50+
51+
return $this;
52+
}
53+
54+
public function bodyContentType(string $contentType): self
55+
{
56+
$this->options['bodyContentType'] = $contentType;
57+
58+
return $this;
59+
}
60+
61+
public function toArray(): array
62+
{
63+
return $this->options;
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input;
13+
14+
/**
15+
* @author Edouard Lescot <edouard.lescot@gmail.com>
16+
* @author Oskar Stark <oskarstark@googlemail.com>
17+
*/
18+
abstract class AbstractInput implements InputInterface
19+
{
20+
private $options = [];
21+
22+
public function id(string $id): self
23+
{
24+
$this->options['id'] = $id;
25+
26+
return $this;
27+
}
28+
29+
public function isRequired(bool $required): self
30+
{
31+
$this->options['isRequired'] = $required;
32+
33+
return $this;
34+
}
35+
36+
public function title(string $title): self
37+
{
38+
$this->options['title'] = $title;
39+
40+
return $this;
41+
}
42+
43+
public function value(string $value): self
44+
{
45+
$this->options['value'] = $value;
46+
47+
return $this;
48+
}
49+
50+
public function toArray(): array
51+
{
52+
return $this->options;
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input;
13+
14+
/**
15+
* @author Edouard Lescot <edouard.lescot@gmail.com>
16+
* @author Oskar Stark <oskarstark@googlemail.com>
17+
*
18+
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#dateinput
19+
*/
20+
final class DateInput extends AbstractInput
21+
{
22+
private $options = [];
23+
24+
public function includeTime(bool $includeTime): self
25+
{
26+
$this->options['includeTime'] = $includeTime;
27+
28+
return $this;
29+
}
30+
31+
public function toArray(): array
32+
{
33+
return parent::toArray() + $this->options + ['@type' => 'DateInput'];
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input;
13+
14+
/**
15+
* @author Edouard Lescot <edouard.lescot@gmail.com>
16+
* @author Oskar Stark <oskarstark@googlemail.com>
17+
*/
18+
interface InputInterface
19+
{
20+
public function toArray(): array;
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input;
13+
14+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
15+
16+
/**
17+
* @author Edouard Lescot <edouard.lescot@gmail.com>
18+
* @author Oskar Stark <oskarstark@googlemail.com>
19+
*
20+
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#multichoiceinput
21+
*/
22+
final class MultiChoiceInput extends AbstractInput
23+
{
24+
private const STYLES = [
25+
'expanded',
26+
'normal',
27+
];
28+
29+
private $options = [];
30+
31+
public function choice(string $display, string $value): self
32+
{
33+
$this->options['choices'][] = ['display' => $display, 'value' => $value];
34+
35+
return $this;
36+
}
37+
38+
public function isMultiSelect(bool $multiSelect): self
39+
{
40+
$this->options['isMultiSelect'] = $multiSelect;
41+
42+
return $this;
43+
}
44+
45+
public function style(string $style): self
46+
{
47+
if (!\in_array($style, self::STYLES)) {
48+
throw new InvalidArgumentException(sprintf('Supported styles for "%s" method are: "%s".', __METHOD__, implode('", "', self::STYLES)));
49+
}
50+
51+
$this->options['style'] = $style;
52+
53+
return $this;
54+
}
55+
56+
public function toArray(): array
57+
{
58+
return parent::toArray() + $this->options + ['@type' => 'MultichoiceInput'];
59+
}
60+
}

0 commit comments

Comments
 (0)