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

Appearance settings

Commit bdd2f75

Browse filesBrowse files
committed
[Webhook] Add Mailchimp webhook (fixes #50285)
[Webhook] Add Mailchimp webhook (fixes #50285)
1 parent 4266345 commit bdd2f75
Copy full SHA for bdd2f75
Expand file treeCollapse file tree

25 files changed

+670
-0
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,6 +2587,7 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
25872587
if ($webhookEnabled) {
25882588
$webhookRequestParsers = [
25892589
MailerBridge\Brevo\Webhook\BrevoRequestParser::class => 'mailer.webhook.request_parser.brevo',
2590+
MailerBridge\Mailchimp\Webhook\MailchimpRequestParser::class => 'mailer.webhook.request_parser.mailchimp',
25902591
MailerBridge\Mailgun\Webhook\MailgunRequestParser::class => 'mailer.webhook.request_parser.mailgun',
25912592
MailerBridge\Mailjet\Webhook\MailjetRequestParser::class => 'mailer.webhook.request_parser.mailjet',
25922593
MailerBridge\Postmark\Webhook\PostmarkRequestParser::class => 'mailer.webhook.request_parser.postmark',

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer_webhook.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer_webhook.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Mailer\Bridge\Brevo\RemoteEvent\BrevoPayloadConverter;
1515
use Symfony\Component\Mailer\Bridge\Brevo\Webhook\BrevoRequestParser;
16+
use Symfony\Component\Mailer\Bridge\Mailchimp\RemoteEvent\MailchimpPayloadConverter;
17+
use Symfony\Component\Mailer\Bridge\Mailchimp\Webhook\MailchimpRequestParser;
1618
use Symfony\Component\Mailer\Bridge\Mailgun\RemoteEvent\MailgunPayloadConverter;
1719
use Symfony\Component\Mailer\Bridge\Mailgun\Webhook\MailgunRequestParser;
1820
use Symfony\Component\Mailer\Bridge\Mailjet\RemoteEvent\MailjetPayloadConverter;
@@ -48,5 +50,10 @@
4850
->set('mailer.webhook.request_parser.sendgrid', SendgridRequestParser::class)
4951
->args([service('mailer.payload_converter.sendgrid')])
5052
->alias(SendgridRequestParser::class, 'mailer.webhook.request_parser.sendgrid')
53+
54+
->set('mailer.payload_converter.mailchimp', MailchimpPayloadConverter::class)
55+
->set('mailer.webhook.request_parser.mailchimp', MailchimpRequestParser::class)
56+
->args([service('mailer.payload_converter.mailchimp'), param('webhook.routing.service'), param('webhook.routing.secret')])
57+
->alias(MailchimpRequestParser::class, 'mailer.webhook.request_parser.mailchimp')
5158
;
5259
};
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Bridge\Mailchimp\RemoteEvent;
13+
14+
use Symfony\Component\RemoteEvent\Event\Mailer\AbstractMailerEvent;
15+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
16+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
17+
use Symfony\Component\RemoteEvent\Exception\ParseException;
18+
use Symfony\Component\RemoteEvent\PayloadConverterInterface;
19+
20+
final class MailchimpPayloadConverter implements PayloadConverterInterface
21+
{
22+
public function convert(array $payload): AbstractMailerEvent
23+
{
24+
if (!\in_array($payload['event'], ['send', 'deferral', 'hard_bounce', 'soft_bounce', 'delivered', 'open', 'click', 'spam', 'unsub', 'reject'], true)) {
25+
throw new ParseException(sprintf('Unsupported event "%s".', $payload['event']));
26+
}
27+
if (\in_array($payload['event'], ['send', 'deferral', 'soft_bounce', 'hard_bounce', 'delivered', 'reject'], true)) {
28+
$name = match ($payload['event']) {
29+
'send' => MailerDeliveryEvent::RECEIVED,
30+
'deferral', 'soft_bounce' => MailerDeliveryEvent::DEFERRED,
31+
'hard_bounce' => MailerDeliveryEvent::BOUNCE,
32+
'delivered' => MailerDeliveryEvent::DELIVERED,
33+
'reject' => MailerDeliveryEvent::DROPPED,
34+
};
35+
36+
$event = new MailerDeliveryEvent($name, $payload['msg']['_id'], $payload);
37+
// reason is only available on failed messages
38+
$event->setReason($this->getReason($payload));
39+
} else {
40+
$name = match ($payload['event']) {
41+
'click' => MailerEngagementEvent::CLICK,
42+
'open' => MailerEngagementEvent::OPEN,
43+
'spam' => MailerEngagementEvent::SPAM,
44+
'unsub' => MailerEngagementEvent::UNSUBSCRIBE,
45+
};
46+
$event = new MailerEngagementEvent($name, $payload['msg']['_id'], $payload);
47+
}
48+
49+
if (!$date = \DateTimeImmutable::createFromFormat('U', $payload['msg']['ts'])) {
50+
throw new ParseException(sprintf('Invalid date "%s".', $payload['msg']['ts']));
51+
}
52+
$event->setDate($date);
53+
$event->setRecipientEmail($payload['msg']['email']);
54+
$event->setMetadata($payload['msg']['metadata']);
55+
$event->setTags($payload['msg']['tags']);
56+
57+
return $event;
58+
}
59+
60+
private function getReason(array $payload): string
61+
{
62+
if (null !== $payload['msg']['diag']) {
63+
return $payload['msg']['diag'];
64+
}
65+
if (null !== $payload['msg']['bounce_description']) {
66+
return $payload['msg']['bounce_description'];
67+
}
68+
if (null !== $payload['msg']['smtp_events'] && null !== $payload['msg']['smtp_events']['diag']) {
69+
return $payload['msg']['smtp_events']['diag'];
70+
}
71+
return '';
72+
}
73+
}
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"mandrill_events": {
3+
"ts": 1365109999,
4+
"event": "click",
5+
"msg": {
6+
"ts": 1365109999,
7+
"subject": "Foo bar",
8+
"email": "foo@example.com",
9+
"sender": "bar@example.com",
10+
"tags": [
11+
"my_tag_1",
12+
"my_tag_2"
13+
],
14+
"smtp_events": null,
15+
"opens": [
16+
{
17+
"ts": 1365110000
18+
}
19+
],
20+
"clicks": [
21+
{
22+
"ts": 1365110000,
23+
"url": "https://www.example.com"
24+
}
25+
],
26+
"state": "sent",
27+
"metadata": {
28+
"mandrill-var-1": "foo",
29+
"mandrill-var-2": "bar"
30+
},
31+
"_id": "7761630",
32+
"_version": "123",
33+
"subaccount": null,
34+
"diag": null,
35+
"bounce_description": null,
36+
"template": null
37+
}
38+
},
39+
"X-Mandrill-Signature": "+Hk40WMuK9Ef/ebv0xBW7KOYdgw="
40+
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
4+
5+
$wh = new MailerEngagementEvent(MailerEngagementEvent::CLICK, '7761630', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['mandrill_events']);
6+
$wh->setRecipientEmail('foo@example.com');
7+
$wh->setTags(['my_tag_1', 'my_tag_2']);
8+
$wh->setMetadata(['mandrill-var-1' => 'foo', 'mandrill-var-2' => 'bar']);
9+
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1365109999));
10+
11+
return $wh;
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"mandrill_events": {
3+
"ts": 1365109999,
4+
"event": "deferral",
5+
"msg": {
6+
"ts": 1365109999,
7+
"subject": "Foo bar",
8+
"email": "foo@example.com",
9+
"sender": "bar@example.com",
10+
"tags": [
11+
"my_tag_1",
12+
"my_tag_2"
13+
],
14+
"smtp_events": null,
15+
"opens": null,
16+
"clicks": null,
17+
"state": "sent",
18+
"metadata": {
19+
"mandrill-var-1": "foo",
20+
"mandrill-var-2": "bar"
21+
},
22+
"_id": "7761631",
23+
"_version": "123",
24+
"subaccount": null,
25+
"diag": null,
26+
"bounce_description": null,
27+
"template": null
28+
}
29+
},
30+
"X-Mandrill-Signature": "YxB6lg2eNzLGhUMjnB6+2Kb6AIk="
31+
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
4+
5+
$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DEFERRED, '7761631', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['mandrill_events']);
6+
$wh->setRecipientEmail('foo@example.com');
7+
$wh->setTags(['my_tag_1', 'my_tag_2']);
8+
$wh->setMetadata(['mandrill-var-1' => 'foo', 'mandrill-var-2' => 'bar']);
9+
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1365109999));
10+
$wh->setReason('');
11+
12+
return $wh;
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"mandrill_events": {
3+
"ts": 1365109999,
4+
"event": "delivered",
5+
"msg": {
6+
"ts": 1365109999,
7+
"subject": "Foo bar",
8+
"email": "foo@example.com",
9+
"sender": "bar@example.com",
10+
"tags": [
11+
"my_tag_1",
12+
"my_tag_2"
13+
],
14+
"smtp_events": null,
15+
"opens": null,
16+
"clicks": null,
17+
"state": "sent",
18+
"metadata": {
19+
"mandrill-var-1": "foo",
20+
"mandrill-var-2": "bar"
21+
},
22+
"_id": "7761632",
23+
"_version": "123",
24+
"subaccount": null,
25+
"diag": null,
26+
"bounce_description": null,
27+
"template": null
28+
}
29+
},
30+
"X-Mandrill-Signature": "7YD/bSKyk1H8aXyThI+TRbz+nRs="
31+
}
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
4+
5+
$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DELIVERED, '7761632', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['mandrill_events']);
6+
$wh->setRecipientEmail('foo@example.com');
7+
$wh->setTags(['my_tag_1', 'my_tag_2']);
8+
$wh->setMetadata(['mandrill-var-1' => 'foo', 'mandrill-var-2' => 'bar']);
9+
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1365109999));
10+
return $wh;
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"mandrill_events": {
3+
"ts": 1365109999,
4+
"event": "hard_bounce",
5+
"msg": {
6+
"ts": 1365109999,
7+
"subject": "Foo bar",
8+
"email": "foo@example.com",
9+
"sender": "bar@example.com",
10+
"tags": [
11+
"my_tag_1",
12+
"my_tag_2"
13+
],
14+
"smtp_events": null,
15+
"opens": null,
16+
"clicks": null,
17+
"state": "sent",
18+
"metadata": {
19+
"mandrill-var-1": "foo",
20+
"mandrill-var-2": "bar"
21+
},
22+
"_id": "7761633",
23+
"_version": "123",
24+
"subaccount": null,
25+
"diag": null,
26+
"bounce_description": "hard bounce",
27+
"template": null
28+
}
29+
},
30+
"X-Mandrill-Signature": "Dcz4HUG731pt489yED5eAzgEMrc="
31+
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
4+
5+
$wh = new MailerDeliveryEvent(MailerDeliveryEvent::BOUNCE, '7761633', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['mandrill_events']);
6+
$wh->setRecipientEmail('foo@example.com');
7+
$wh->setTags(['my_tag_1', 'my_tag_2']);
8+
$wh->setMetadata(['mandrill-var-1' => 'foo', 'mandrill-var-2' => 'bar']);
9+
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1365109999));
10+
$wh->setReason('hard bounce');
11+
return $wh;
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"mandrill_events": {
3+
"ts": 1365109999,
4+
"event": "open",
5+
"msg": {
6+
"ts": 1365109999,
7+
"subject": "Foo bar",
8+
"email": "foo@example.com",
9+
"sender": "bar@example.com",
10+
"tags": [
11+
"my_tag_1",
12+
"my_tag_2"
13+
],
14+
"smtp_events": null,
15+
"opens": [
16+
{
17+
"ts": 1365110000
18+
}
19+
],
20+
"clicks": null,
21+
"state": "sent",
22+
"metadata": {
23+
"mandrill-var-1": "foo",
24+
"mandrill-var-2": "bar"
25+
},
26+
"_id": "7761634",
27+
"_version": "123",
28+
"subaccount": null,
29+
"diag": null,
30+
"bounce_description": null,
31+
"template": null
32+
}
33+
},
34+
"X-Mandrill-Signature": "pWPElKIMolTDzVrQcev5sfqmFLo="
35+
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
4+
5+
$wh = new MailerEngagementEvent(MailerEngagementEvent::OPEN, '7761634', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['mandrill_events']);
6+
$wh->setRecipientEmail('foo@example.com');
7+
$wh->setTags(['my_tag_1', 'my_tag_2']);
8+
$wh->setMetadata(['mandrill-var-1' => 'foo', 'mandrill-var-2' => 'bar']);
9+
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1365109999));
10+
11+
return $wh;
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"mandrill_events": {
3+
"ts": 1365109999,
4+
"event": "reject",
5+
"msg": {
6+
"ts": 1365109999,
7+
"subject": "Foo bar",
8+
"email": "foo@example.com",
9+
"sender": "bar@example.com",
10+
"tags": [
11+
"my_tag_1",
12+
"my_tag_2"
13+
],
14+
"smtp_events": null,
15+
"opens": null,
16+
"clicks": null,
17+
"state": "sent",
18+
"metadata": {
19+
"mandrill-var-1": "foo",
20+
"mandrill-var-2": "bar"
21+
},
22+
"_id": "7761635",
23+
"_version": "123",
24+
"subaccount": null,
25+
"diag": null,
26+
"bounce_description": null,
27+
"template": null
28+
}
29+
},
30+
"X-Mandrill-Signature": "uyKNzz9l9vXpcesnxGpJf1pfyuE="
31+
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
4+
5+
$wh = new MailerDeliveryEvent(MailerDeliveryEvent::DROPPED, '7761635', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: JSON_THROW_ON_ERROR)['mandrill_events']);
6+
$wh->setRecipientEmail('foo@example.com');
7+
$wh->setTags(['my_tag_1', 'my_tag_2']);
8+
$wh->setMetadata(['mandrill-var-1' => 'foo', 'mandrill-var-2' => 'bar']);
9+
$wh->setDate(\DateTimeImmutable::createFromFormat('U', 1365109999));
10+
$wh->setReason('');
11+
12+
return $wh;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.