Skip to content

[Notifier] Sendinblue bridge missing parameters #38326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/Sendinblue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ where:
- `API_KEY` is your api key from your Sendinblue account
- `PHONE` is your sender's phone number

You can also add **type**, **tag** and **webUrl** in parameter like the sender.
Those parameters are optional.

See more info at https://developers.sendinblue.com/reference#sendtransacsms

Resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ final class SendinblueTransport extends AbstractTransport

private $apiKey;
private $sender;
private $type;
private $tag;
private $webUrl;

public function __construct(string $apiKey, string $sender, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
public function __construct(string $apiKey, string $sender, string $type, string $tag = null, string $webUrl = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
{
$this->apiKey = $apiKey;
$this->sender = $sender;
$this->type = $type;
$this->tag = $tag;
$this->webUrl = $webUrl;

parent::__construct($client, $dispatcher);
}
Expand All @@ -57,11 +63,7 @@ protected function doSend(MessageInterface $message): SentMessage
}

$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v3/transactionalSMS/sms', [
'json' => [
'sender' => $this->sender,
'recipient' => $message->getPhone(),
'content' => $message->getSubject(),
],
'json' => $this->getPayload($message),
'headers' => [
'api-key' => $this->apiKey,
],
Expand All @@ -80,4 +82,22 @@ protected function doSend(MessageInterface $message): SentMessage

return $message;
}

private function getPayload(MessageInterface $message): array
{
$payload = [
'sender' => $this->sender,
'recipient' => $message->getPhone(),
'content' => $message->getSubject(),
'type' => $this->type,
];
if ($this->tag) {
$payload['tag'] = $this->tag;
}
if ($this->webUrl) {
$payload['webUrl'] = $this->webUrl;
}

return $payload;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ public function create(Dsn $dsn): TransportInterface

$scheme = $dsn->getScheme();
$apiKey = $this->getUser($dsn);
$type = $dsn->getOption('type', 'transactional');
$tag = $dsn->getOption('tag');
$webUrl = $dsn->getOption('webUrl');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

if ('sendinblue' === $scheme) {
return (new SendinblueTransport($apiKey, $sender, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
return (new SendinblueTransport($apiKey, $sender, $type, $tag, $webUrl, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
}

throw new UnsupportedSchemeException($dsn, 'sendinblue', $this->getSupportedSchemes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testSendWithErrorResponseThrows(): void
private function initTransport(?HttpClientInterface $client = null): SendinblueTransport
{
return (new SendinblueTransport(
'api-key', '0611223344', $client ?: $this->createMock(HttpClientInterface::class)
'api-key', '0611223344', 'transactional', null, null, $client ?: $this->createMock(HttpClientInterface::class)
))->setHost('host.test');
}
}