8000 feature #58786 [Notifier] [Brevo][SMS] Brevo sms notifier add options… · symfony/symfony@ae5843f · GitHub
[go: up one dir, main page]

Skip to content

Commit ae5843f

Browse files
committed
feature #58786 [Notifier] [Brevo][SMS] Brevo sms notifier add options (ikerib)
This PR was squashed before being merged into the 7.3 branch. Discussion ---------- [Notifier] [Brevo][SMS] Brevo sms notifier add options | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Added webhook, tag options to brevo notifier | License | MIT I have used brevo-notifier and I realized that it was missing some options like the url address of the webhook, tags... I have added them. I hope that I did well the pull request and everything related... Commits ------- 1791f01 [Notifier] [Brevo][SMS] Brevo sms notifier add options
2 parents 7d38047 + 1791f01 commit ae5843f

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\Brevo;
13+
14+
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
15+
16+
final class BrevoOptions implements MessageOptionsInterface
17+
{
18+
public function __construct(
19+
private array $options = [],
20+
) {
21+
}
22+
23+
public function toArray(): array
24+
{
25+
return $this->options;
26+
}
27+
28+
public function getRecipientId(): ?string
29+
{
30+
return null;
31+
}
32+
33+
/**
34+
* @return $this
35+
*/
36+
public function webUrl(string $url): static
37+
{
38+
$this->options['webUrl'] = $url;
39+
40+
return $this;
41+
}
42+
43+
/**
44+
* @return $this
45+
*/
46+
public function type(string $type="transactional"): static
47+
{
48+
$this->options['type'] = $type;
49+
50+
return $this;
51+
}
52+
53+
public function tag(string $tag): static
54+
{
55+
$this->options['tag'] = $tag;
56+
57+
return $this;
58+
}
59+
}

src/Symfony/Component/Notifier/Bridge/Brevo/BrevoTransport.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,24 @@ protected function doSend(MessageInterface $message): SentMessage
5454
}
5555

5656
$sender = $message->getFrom() ?: $this->sender;
57+
$options = $message->getOptions()?->toArray() ?? [];
58+
$body = [
59+
'sender' => $sender,
60+
'recipient' => $message->getPhone(),
61+
'content' => $message->getSubject(),
62+
];
63+
if (isset($options['webUrl'])) {
64+
$body['webUrl'] = $options['webUrl'];
65+
}
66+
if (isset($options['type'])) {
67+
$body['type'] = $options['type'];
68+
}
69+
if (isset($options['tag'])) {
70+
$body['tag'] = $options['tag'];
71+
}
5772

5873
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v3/transactionalSMS/sms', [
59-
'json' => [
60-
'sender' => $sender,
61-
'recipient' => $message->getPhone(),
62-
'content' => $message->getSubject(),
63-
],
74+
'json' => $body,
6475
'headers' => [
6576
'api-key' => $this->apiKey,
6677
],

0 commit comments

Comments
 (0)
0