Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f32af46

Browse files
committed
feature #43139 [Notifier] Mattermost Notifier option to post in an other channel (nathanaelmartel)
This PR was merged into the 5.4 branch. Discussion ---------- [Notifier] Mattermost Notifier option to post in an other channel | Q | A | ------------- | --- | Branch? | 5.4 for features / 4.4 or 5.3 for bug fixes <!-- see below --> | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Commits ------- fdbb3d1 Mattermost Notifier option to post in an other channel
2 parents 99ebc69 + fdbb3d1 commit f32af46

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Mattermost;
13+
14+
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
15+
16+
/**
17+
* @author Nathanaël Martel <[email protected]>
18+
*/
19+
final class MattermostOptions implements MessageOptionsInterface
20+
{
21+
private $options;
22+
23+
public function __construct(array $options = [])
24+
{
25+
$this->options = $options;
26+
}
27+
28+
public function recipient(string $id): self
29+
{
30+
$this->options['recipient_id'] = $id;
31+
32+
return $this;
33+
}
34+
35+
public function toArray(): array
36+
{
37+
$options = $this->options;
38+
unset($options['recipient_id']);
39+
40+
return $options;
41+
}
42+
43+
public function getRecipientId(): ?string
44+
{
45+
return $this->options['recipient_id'] ?? null;
46+
}
47+
}

src/Symfony/Component/Notifier/Bridge/Mattermost/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@ DSN example
77
-----------
88

99
```
10-
MATTERMOST_DSN=mattermost://ACCESS_TOKEN@HOST/PATH?channel=CHANNEL
10+
MATTERMOST_DSN=mattermost://ACCESS_TOKEN@HOST/PATH?channel=CHANNEL_ID
1111
```
1212

1313
where:
1414
- `ACCESS_TOKEN` is your Mattermost access token
1515
- `HOST` is your Mattermost host
1616
- `PATH` is your Mattermost sub-path (optional)
17-
- `CHANNEL` is your Mattermost channel
17+
- `CHANNEL_ID` is your Mattermost default channel id
18+
19+
Usage
20+
-----
21+
22+
```
23+
// to post to another channel
24+
$options = new MattermostOptions();
25+
$options->recipient('{channel_id}');
26+
27+
$message = (new ChatMessage($text))->options($options);
28+
29+
$chatter->send($message);
30+
```
1831

1932
Resources
2033
---------

0 commit comments

Comments
 (0)