diff --git a/src/Symfony/Component/Notifier/Bridge/Brevo/BrevoOptions.php b/src/Symfony/Component/Notifier/Bridge/Brevo/BrevoOptions.php new file mode 100644 index 0000000000000..64d0b531a1e89 --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/Brevo/BrevoOptions.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Bridge\Brevo; + +use Symfony\Component\Notifier\Message\MessageOptionsInterface; + +final class BrevoOptions implements MessageOptionsInterface +{ + public function __construct( + private array $options = [], + ) { + } + + public function toArray(): array + { + return $this->options; + } + + public function getRecipientId(): ?string + { + return null; + } + + /** + * @return $this + */ + public function webUrl(string $url): static + { + $this->options['webUrl'] = $url; + + return $this; + } + + /** + * @return $this + */ + public function type(string $type="transactional"): static + { + $this->options['type'] = $type; + + return $this; + } + + public function tag(string $tag): static + { + $this->options['tag'] = $tag; + + return $this; + } +} diff --git a/src/Symfony/Component/Notifier/Bridge/Brevo/BrevoTransport.php b/src/Symfony/Component/Notifier/Bridge/Brevo/BrevoTransport.php index fec94c8d500f9..c5e48a27e8e7b 100644 --- a/src/Symfony/Component/Notifier/Bridge/Brevo/BrevoTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/Brevo/BrevoTransport.php @@ -54,13 +54,24 @@ protected function doSend(MessageInterface $message): SentMessage } $sender = $message->getFrom() ?: $this->sender; + $options = $message->getOptions()?->toArray() ?? []; + $body = [ + 'sender' => $sender, + 'recipient' => $message->getPhone(), + 'content' => $message->getSubject(), + ]; + if (isset($options['webUrl'])) { + $body['webUrl'] = $options['webUrl']; + } + if (isset($options['type'])) { + $body['type'] = $options['type']; + } + if (isset($options['tag'])) { + $body['tag'] = $options['tag']; + } $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v3/transactionalSMS/sms', [ - 'json' => [ - 'sender' => $sender, - 'recipient' => $message->getPhone(), - 'content' => $message->getSubject(), - ], + 'json' => $body, 'headers' => [ 'api-key' => $this->apiKey, ],