diff --git a/src/Symfony/Component/Notifier/Bridge/Mattermost/MattermostOptions.php b/src/Symfony/Component/Notifier/Bridge/Mattermost/MattermostOptions.php new file mode 100644 index 0000000000000..41db757de13bb --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/Mattermost/MattermostOptions.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Bridge\Mattermost; + +use Symfony\Component\Notifier\Message\MessageOptionsInterface; + +/** + * @author Nathanaƫl Martel + */ +final class MattermostOptions implements MessageOptionsInterface +{ + private $options; + + public function __construct(array $options = []) + { + $this->options = $options; + } + + public function recipient(string $id): self + { + $this->options['recipient_id'] = $id; + + return $this; + } + + public function toArray(): array + { + $options = $this->options; + unset($options['recipient_id']); + + return $options; + } + + public function getRecipientId(): ?string + { + return $this->options['recipient_id'] ?? null; + } +} diff --git a/src/Symfony/Component/Notifier/Bridge/Mattermost/README.md b/src/Symfony/Component/Notifier/Bridge/Mattermost/README.md index 6efbc0f59492e..34292145c732f 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mattermost/README.md +++ b/src/Symfony/Component/Notifier/Bridge/Mattermost/README.md @@ -7,14 +7,27 @@ DSN example ----------- ``` -MATTERMOST_DSN=mattermost://ACCESS_TOKEN@HOST/PATH?channel=CHANNEL +MATTERMOST_DSN=mattermost://ACCESS_TOKEN@HOST/PATH?channel=CHANNEL_ID ``` where: - `ACCESS_TOKEN` is your Mattermost access token - `HOST` is your Mattermost host - `PATH` is your Mattermost sub-path (optional) - - `CHANNEL` is your Mattermost channel + - `CHANNEL_ID` is your Mattermost default channel id + +Usage +----- + +``` +// to post to another channel +$options = new MattermostOptions(); +$options->recipient('{channel_id}'); + +$message = (new ChatMessage($text))->options($options); + +$chatter->send($message); +``` Resources ---------