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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Notifier] [Brevo][SMS] Brevo sms notifier add options
  • Loading branch information
ikerib authored and fabpot committed Jan 5, 2025
commit 1791f011aa3cd46f792fd5f0e34d6ab4a643abb9
59 changes: 59 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/Brevo/BrevoOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* 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;
}
}
21 changes: 16 additions & 5 deletions src/Symfony/Component/Notifier/Bridge/Brevo/BrevoTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
Loading