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

Commitd6fa9a8

Browse files
bug#59376 [RemoteEvent][Webhook] FixSendgridRequestParser andSendgridPayloadConverter (ericabouaf)
This PR was merged into the 6.4 branch.Discussion----------[RemoteEvent][Webhook] Fix `SendgridRequestParser` and `SendgridPayloadConverter`| Q | A| ------------- | ---| Branch? | 6.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues || License | MITAccording tohttps://www.twilio.com/docs/sendgrid/for-developers/tracking-events/event#event-objects, not all webhook events contains a `sg_message_id` in the payload. In the case of a delayed or [asynchronous bounce](https://www.twilio.com/docs/sendgrid/ui/sending-email/bounces#asynchronous-bounces), the message ID will be unavailable.The current implementation rejects the webhook call with "Payload is malformed".We should use the always present `sg_event_id` instead.For BC reasons, I did not want to change the id of the RemoteEvent, so I kept `sg_message_id` if present, but fallback to `sg_event_id` instead so that the webhook is not rejected.Commits-------93a4398 [RemoteEvent][Webhook] fix SendgridRequestParser & SendgridPayloadConverter in case of missing sg_message_id
2 parents82011ee +93a4398 commitd6fa9a8

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function convert(array $payload): AbstractMailerEvent
3131
'deferred' => MailerDeliveryEvent::DEFERRED,
3232
'bounce' => MailerDeliveryEvent::BOUNCE,
3333
};
34-
$event =newMailerDeliveryEvent($name,$payload['sg_message_id'],$payload);
34+
$event =newMailerDeliveryEvent($name,$payload['sg_message_id'] ??$payload['sg_event_id'],$payload);
3535
$event->setReason($payload['reason'] ??'');
3636
}else {
3737
$name =match ($payload['event']) {
@@ -41,7 +41,7 @@ public function convert(array $payload): AbstractMailerEvent
4141
'spamreport' => MailerEngagementEvent::SPAM,
4242
default =>thrownewParseException(sprintf('Unsupported event "%s".',$payload['event'])),
4343
};
44-
$event =newMailerEngagementEvent($name,$payload['sg_message_id'],$payload);
44+
$event =newMailerEngagementEvent($name,$payload['sg_message_id'] ??$payload['sg_event_id'],$payload);
4545
}
4646

4747
if (!$date = \DateTimeImmutable::createFromFormat('U',$payload['timestamp'])) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,19 @@ public function testInvalidDate()
9797
'email' =>'test@example.com',
9898
]);
9999
}
100+
101+
publicfunctiontestAsynchronousBounce()
102+
{
103+
$converter =newSendgridPayloadConverter();
104+
105+
$event =$converter->convert([
106+
'event' =>'bounce',
107+
'sg_event_id' =>'123456',
108+
'timestamp' =>'123456789',
109+
'email' =>'test@example.com',
110+
]);
111+
112+
$this->assertInstanceOf(MailerDeliveryEvent::class,$event);
113+
$this->assertSame('123456',$event->getId());
114+
}
100115
}

‎src/Symfony/Component/Mailer/Bridge/Sendgrid/Webhook/SendgridRequestParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function doParse(Request $request, string $secret): ?AbstractMailerEve
4848
!isset($content[0]['email'])
4949
|| !isset($content[0]['timestamp'])
5050
|| !isset($content[0]['event'])
51-
|| !isset($content[0]['sg_message_id'])
51+
|| !isset($content[0]['sg_event_id'])
5252
) {
5353
thrownewRejectWebhookException(406,'Payload is malformed.');
5454
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp