Skip to content

[Notifier] Add options to Microsoft Teams notifier #40738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action;

use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input\InputInterface;

/**
* @author Edouard Lescot <edouard.lescot@gmail.com>
* @author Oskar Stark <oskarstark@googlemail.com>
*
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#actioncard-action
*/
final class ActionCard implements ActionInterface
{
private $options = [];

public function name(string $name): self
{
$this->options['name'] = $name;

return $this;
}

public function input(InputInterface $inputAction): self
{
$this->options['inputs'][] = $inputAction->toArray();

return $this;
}

public function action(ActionCardCompatibleActionInterface $action): self
{
$this->options['actions'][] = $action->toArray();

return $this;
}

public function toArray(): array
{
return $this->options + ['@type' => 'ActionCard'];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action;

/**
* An Action which can be used inside an ActionCard.
*
* @author Oskar Stark <oskarstark@googlemail.com>
*/
interface ActionCardCompatibleActionInterface extends ActionInterface
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action;

/**
* @author Edouard Lescot <edouard.lescot@gmail.com>
* @author Oskar Stark <oskarstark@googlemail.com>
*/
interface ActionInterface
{
public function toArray(): array;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Element;

/**
* @author Edouard Lescot <edouard.lescot@gmail.com>
* @author Oskar Stark <oskarstark@googlemail.com>
*
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#header
*/
final class Header
{
private $options = [];

public function name(string $name): self
{
$this->options['name'] = $name;

return $this;
}

public function value(string $value): self
{
$this->options['value'] = $value;

return $this;
}

public function toArray(): array
{
return $this->options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action;

use Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Element\Header;

/**
* @author Edouard Lescot <edouard.lescot@gmail.com>
* @author Oskar Stark <oskarstark@googlemail.com>
*
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#httppost-action
*/
final class HttpPostAction implements ActionCardCompatibleActionInterface
{
private $options = ['@type' => 'HttpPOST'];

public function name(string $name): self
{
$this->options['name'] = $name;

return $this;
}

public function target(string $url): self
{
$this->options['target'] = $url;

return $this;
}

public function header(Header $header): self
{
$this->options['headers'][] = $header->toArray();

return $this;
}

public function body(string $body): self
{
$this->options['body'] = $body;

return $this;
}

public function bodyContentType(string $contentType): self
{
$this->options['bodyContentType'] = $contentType;

return $this;
}

public function toArray(): array
{
return $this->options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input;

/**
* @author Edouard Lescot <edouard.lescot@gmail.com>
* @author Oskar Stark <oskarstark@googlemail.com>
*/
abstract class AbstractInput implements InputInterface
{
private $options = [];

public function id(string $id): self
{
$this->options['id'] = $id;

return $this;
}

public function isRequired(bool $required): self
{
$this->options['isRequired'] = $required;

return $this;
}

public function title(string $title): self
{
$this->options['title'] = $title;

return $this;
}

public function value(string $value): self
{
$this->options['value'] = $value;

return $this;
}

public function toArray(): array
{
return $this->options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input;

/**
* @author Edouard Lescot <edouard.lescot@gmail.com>
* @author Oskar Stark <oskarstark@googlemail.com>
*
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#dateinput
*/
final class DateInput extends AbstractInput
{
private $options = [];

public function includeTime(bool $includeTime): self
{
$this->options['includeTime'] = $includeTime;

return $this;
}

public function toArray(): array
{
return parent::toArray() + $this->options + ['@type' => 'DateInput'];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input;

/**
* @author Edouard Lescot <edouard.lescot@gmail.com>
* @author Oskar Stark <oskarstark@googlemail.com>
*/
interface InputInterface
{
public function toArray(): array;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\MicrosoftTeams\Action\Input;

use Symfony\Component\Notifier\Exception\InvalidArgumentException;

/**
* @author Edouard Lescot <edouard.lescot@gmail.com>
* @author Oskar Stark <oskarstark@googlemail.com>
*
* @see https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#multichoiceinput
*/
final class MultiChoiceInput extends AbstractInput
{
private const STYLES = [
'expanded',
'normal',
];

private $options = [];

public function choice(string $display, string $value): self
{
$this->options['choices'][] = ['display' => $display, 'value' => $value];

return $this;
}

public function isMultiSelect(bool $multiSelect): self
{
$this->options['isMultiSelect'] = $multiSelect;

return $this;
}

public function style(string $style): self
{
if (!\in_array($style, self::STYLES)) {
throw new InvalidArgumentException(sprintf('Supported styles for "%s" method are: "%s".', __METHOD__, implode('", "', self::STYLES)));
}

$this->options['style'] = $style;

return $this;
}

public function toArray(): array
{
return parent::toArray() + $this->options + ['@type' => 'MultichoiceInput'];
}
}
Loading