8000 Add options to brevo-notifier like webhook url, tag... · symfony/symfony@7f621a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f621a2

Browse files
committed
Add options to brevo-notifier like webhook url, tag...
1 parent f73be8a commit 7f621a2

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Symfony\Component\Notifier\Bridge\Brevo;
4+
5+
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
6+
7+
final class BrevoOptions implements MessageOptionsInterface
8+
{
9+
public function __construct(
10+
private array $options = [],
11+
) {
12+
}
13+
14+
public function toArray(): array
15+
{
16+
return $this->options;
17+
}
18+
19+
public function getRecipientId(): ?string
20+
{
21+
return null;
22+
}
23+
24+
/**
25+
* @return $this
26+
*/
27+
public function webUrl(string $url): static
28+
{
29+
$this->options['webUrl'] = $url;
30+
31+
return $this;
32+
}
33+
34+
/**
35+
* @return $this
36+
*/
37+
public function type(string $type="transactional"): static
38+
{
39+
$this->options['type'] = $type;
40+
41+
return $this;
42+
}
43+
44+
public function tag(string $tag): static
45+
{
46+
$this->options['tag'] = $tag;
47+
48+
return $this;
49+
}
50+
}

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