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 c389e45

Browse filesBrowse files
committed
[Webhook][RemoteEvent] fix SendgridPayloadConverter category support
1 parent 02cafa9 commit c389e45
Copy full SHA for c389e45

File tree

2 files changed

+24
-1
lines changed
Filter options

2 files changed

+24
-1
lines changed

‎src/Symfony/Component/Mailer/Bridge/Sendgrid/RemoteEvent/SendgridPayloadConverter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Sendgrid/RemoteEvent/SendgridPayloadConverter.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ public function convert(array $payload): AbstractMailerEvent
5151
$event->setDate($date);
5252
$event->setRecipientEmail($payload['email']);
5353
$event->setMetadata([]);
54-
$event->setTags($payload['category'] ?? []);
54+
55+
$tags = [];
56+
// If you send single categories as an array, they will be returned by the webhook as an array.
57+
// If you send single categories as a string, they will be returned by the webhook as a string.
58+
if (isset($payload['category'])) {
59+
$tags = \is_array($payload['category']) ? $payload['category'] : [$payload['category']];
60+
}
61+
$event->setTags($tags);
5562

5663
return $event;
5764
}

‎src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/RemoteEvent/SendgridPayloadConverterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/RemoteEvent/SendgridPayloadConverterTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,20 @@ public function testInvalidDate()
9797
'email' => 'test@example.com',
9898
]);
9999
}
100+
101+
public function testWithStringCategory()
102+
{
103+
$converter = new SendgridPayloadConverter();
104+
105+
$event = $converter->convert([
106+
'event' => 'processed',
107+
'sg_message_id' => '123456',
108+
'timestamp' => '123456789',
109+
'email' => 'test@example.com',
110+
'category' => 'cat facts',
111+
]);
112+
113+
$this->assertInstanceOf(MailerDeliveryEvent::class, $event);
114+
$this->assertSame(['cat facts'], $event->getTags());
115+
}
100116
}

0 commit comments

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