Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[RemoteEvent][Webhook] Add Brevo support#51264

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.4fromblaugueux:brevo-webhook
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
1 change: 1 addition & 0 deletionssrc/Symfony/Component/Mailer/Bridge/Brevo/CHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,4 +4,5 @@ CHANGELOG
6.4
---

* Add support for `RemoteEvent` and `Webhook`
* Add the bridge as a replacement of the deprecated Sendinblue one
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Mailer\Bridge\Brevo\RemoteEvent;

use Symfony\Component\RemoteEvent\Event\Mailer\AbstractMailerEvent;
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
use Symfony\Component\RemoteEvent\Exception\ParseException;
use Symfony\Component\RemoteEvent\PayloadConverterInterface;

final class BrevoPayloadConverter implements PayloadConverterInterface
{
public function convert(array $payload): AbstractMailerEvent
{
if (\in_array($payload['event'], ['request', 'deferred', 'delivered', 'soft_bounce', 'hard_bounce', 'invalid_email', 'blocked', 'error'], true)) {
$name = match ($payload['event']) {
'request' => MailerDeliveryEvent::RECEIVED,
'deferred' => MailerDeliveryEvent::DEFERRED,
'delivered' => MailerDeliveryEvent::DELIVERED,
'soft_bounce' => MailerDeliveryEvent::BOUNCE,
'hard_bounce' => MailerDeliveryEvent::BOUNCE,
'invalid_email' => MailerDeliveryEvent::DROPPED,
'blocked' => MailerDeliveryEvent::DROPPED,
'error' => MailerDeliveryEvent::DROPPED,
};

$event = new MailerDeliveryEvent($name, $payload['message-id'], $payload);
} else {
$name = match ($payload['event']) {
'click' => MailerEngagementEvent::CLICK,
'unsubscribed' => MailerEngagementEvent::UNSUBSCRIBE,
'unique_opened' => MailerEngagementEvent::OPEN,
'opened' => MailerEngagementEvent::OPEN,
'proxy_open' => MailerEngagementEvent::OPEN,
'complaint' => MailerEngagementEvent::SPAM,
default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
};
$event = new MailerEngagementEvent($name, $payload['message-id'], $payload);
}

if (!$date = \DateTimeImmutable::createFromFormat('U', $payload['ts_event'])) {
throw new ParseException(sprintf('Invalid date "%s".', $payload['ts_event']));
}

if (
\in_array($payload['event'], ['deferred', 'soft_bounce', 'hard_bounce', 'invalid_email', 'blocked', 'error'], true)
&& isset($payload['reason'])
) {
$event->setReason($payload['reason']);
}

$event->setDate($date);
$event->setRecipientEmail($payload['email']);
$event->setTags($payload['tags']);

return $event;
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Mailer\Bridge\Brevo\Tests\Webhook;

use Symfony\Component\Mailer\Bridge\Brevo\RemoteEvent\BrevoPayloadConverter;
use Symfony\Component\Mailer\Bridge\Brevo\Webhook\BrevoRequestParser;
use Symfony\Component\Webhook\Client\RequestParserInterface;
use Symfony\Component\Webhook\Test\AbstractRequestParserTestCase;

class BrevoRequestParserTest extends AbstractRequestParserTestCase
{
protected function createRequestParser(): RequestParserInterface
{
return new BrevoRequestParser(new BrevoPayloadConverter());
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
{
"id": 814119,
"email": "example@gmail.com",
"message-id": "<202305311400.29297141656@smtp-relay.mailin.fr>",
"date": "2023-05-31 16:00:08",
"tags": [
"tag1",
"tag2"
],
"tag": "[\"tag1\",\"tag2\"]",
"event": "blocked",
"subject": "Subject Line",
"ts_event": 1685541608,
"ts": 1685541608,
"reason": "blocked : due to unsubscribed user",
"ts_epoch": 1685541608993
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DROPPED, '<202305311400.29297141656@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['tag1', 'tag2']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685541608));
$wh->setReason('blocked : due to unsubscribed user');

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
{
"id": 814119,
"email": "example@gmail.com",
"message-id": "<202305311408.17112967225@smtp-relay.mailin.fr>",
"date": "2023-05-31 16:08:28",
"tags": [
"welcome",
"tag2"
],
"tag": "[\"welcome\",\"tag2\"]",
"event": "click",
"subject": "Subject Line",
"sending_ip": "127.0.0.1",
"ts": 1685542108,
"ts_epoch": 1685542108462,
"ts_event": 1685542108,
"link": "https://www.google.com"
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::CLICK, '<202305311408.17112967225@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['welcome', 'tag2']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685542108));

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
{
"event": "complaint",
"email": "example@gmail.com",
"id": 814119,
"date": "2020-10-09 00:00:00",
"ts": 1604933619,
"message-id": "<201798300811.5787683@smtp-relay.mailin.fr>",
"ts_event": 1604933654,
"X-Mailin-custom": "some_custom_header",
"tags": ["transac_messages"]
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::SPAM, '<201798300811.5787683@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['transac_messages']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
{
"event":"deferred",
"email": "example@domain.com",
"id": 814119,
"date": "2020-10-09 00:00:00",
"ts": 1604933619,
"message-id": "<202305311400.29297141656@smtp-relay.mailin.fr>",
"ts_event": 1604933654,
"subject": "My first Transactional",
"X-Mailin-custom": "some_custom_header",
"sending_ip": "127.0.0.1",
"ts_epoch": 1604933654,
"template_id": 22,
"tags": ["transac_messages"],
"reason": "spam"
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DEFERRED, '<202305311400.29297141656@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@domain.com');
$wh->setTags(['transac_messages']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));
$wh->setReason('spam');

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
{
"id": 814119,
"email": "example@gmail.com",
"message-id": "<202305311328.81899448177@smtp-relay.mailin.fr>",
"date": "2023-05-31 15:28:33",
"tags": [
"tag1",
"tag2"
],
"tag": "[\"tag1\",\"tag2\"]",
"event": "delivered",
"subject": "Subject Line",
"sending_ip": "127.0.0.1",
"ts_event": 1685539713,
"ts": 1685539713,
"reason": "sent",
"ts_epoch": 1685539713018
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DELIVERED, '<202305311328.81899448177@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['tag1', 'tag2']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685539713));

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
{
"event": "invalid_email",
"email": "example@gmail.com",
"id": 814119,
"date": "2020-10-09 00:00:00",
"ts": 1604933619,
"message-id": "<201798300811.5787683@smtp-relay.mailin.fr>",
"ts_event": 1604933654,
"subject": "My first Transactional",
"X-Mailin-custom": "some_custom_header",
"template_id": 22,
"tags": ["transac_messages"],
"ts_epoch": 1604933623
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DROPPED, '<201798300811.5787683@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['transac_messages']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
{
"id": 814119,
"email": "example@gmail.com",
"message-id": "<202305311437.85220493321@smtp-relay.mailin.fr>",
"date": "2023-05-31 16:37:07",
"tags": [
"welcome",
"tag2"
],
"tag": "[\"welcome\",\"tag2\"]",
"event": "hard_bounce",
"subject": "Subject Line",
"sending_ip": "127.0.0.1",
"ts_event": 1685543827,
"ts": 1685543827,
"reason": "550-5.1.1 The email account that you tried to reach does not exist. Please try\n 550-5.1.1 double-checking the recipient's email address for typos or\n 550-5.1.1 unnecessary spaces. Learn more at\n 550 5.1.1 https://support.google.com/mail/?p=NoSuchUser g14-20020a5d698e000000b0030aefbb8608si2668200wru.496 - gsmtp",
"ts_epoch": 1685543827372
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::BOUNCE, '<202305311437.85220493321@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['welcome', 'tag2']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685543827));
$wh->setReason("550-5.1.1 The email account that you tried to reach does not exist. Please try\n 550-5.1.1 double-checking the recipient's email address for typos or\n 550-5.1.1 unnecessary spaces. Learn more at\n 550 5.1.1 https://support.google.com/mail/?p=NoSuchUser g14-20020a5d698e000000b0030aefbb8608si2668200wru.496 - gsmtp");

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
{
"event": "invalid_email",
"email": "example@gmail.com",
"id": 625895,
"date": "2020-10-09 00:00:00",
"ts": 1604933619,
"message-id": "<201798300811.5787683@smtp-relay.mailin.fr>",
"ts_event": 1604933654,
"subject": "My first Transactional",
"X-Mailin-custom": "some_custom_header",
"template_id": 22,
"tags": ["transac_messages"],
"ts_epoch": 1604933623
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;

$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DROPPED, '<201798300811.5787683@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['transac_messages']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
{
"id": 814119,
"email": "example@gmail.com",
"message-id": "<202305311408.17112967225@smtp-relay.mailin.fr>",
"date": "2023-05-31 16:45:09",
"tags": [
"welcome",
"tag2"
],
"tag": "[\"welcome\",\"tag2\"]",
"event": "opened",
"subject": "Subject Line",
"sending_ip": "127.0.0.1",
"ts": 1685544309,
"ts_epoch": 1685544309368,
"ts_event": 1685544309,
"link": ""
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, '<202305311408.17112967225@smtp-relay.mailin.fr>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['welcome', 'tag2']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1685544309));

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
{
"event": "proxy_open",
"email": "example@gmail.com",
"id": 1,
"date": "2020-10-09 00:00:00",
"message-id": "<201798300811.5787683@relay.domain.com>",
"subject": "My first Transactional",
"tags": ["transactionalTag"],
"sending_ip": "127.0.0.1",
"s_epoch": 1534486682000,
"template_id": 1,
"ts": 1604933654,
"ts_event": 1604933654
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
<?php

use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;

$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, '<201798300811.5787683@relay.domain.com>', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR));
$wh->setRecipientEmail('example@gmail.com');
$wh->setTags(['transactionalTag']);
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1604933654));

return $wh;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
{
"id": 814119,
"email": "example@gmail.com",
"message-id": "<202305311313.92192897094@smtp-relay.mailin.fr>",
"date": "2023-05-31 15:13:08",
"tags": [
"tag1",
"tag2"
],
"tag": "[\"tag1\",\"tag2\"]",
"event": "request",
"subject": "Subject Line",
"sending_ip": "127.0.0.1",
"ts_event": 1685538788,
"ts": 1685538788,
"reason": "sent",
"ts_epoch": 1685538788179
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp