1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 17:31:35 +02:00

changes to WebhookHandler

This commit is contained in:
paulwer 2023-12-22 07:39:49 +01:00
parent c9178a6a01
commit 629c9c1b12

View File

@ -101,6 +101,7 @@ class ProcessBrevoWebhook implements ShouldQueue
case 'soft_bounce': case 'soft_bounce':
case 'hard_bounce': case 'hard_bounce':
case 'invalid_email': case 'invalid_email':
case 'blocked':
return $this->processBounce(); return $this->processBounce();
case 'spam': case 'spam':
return $this->processSpamComplaint(); return $this->processSpamComplaint();
@ -114,29 +115,41 @@ class ProcessBrevoWebhook implements ShouldQueue
} }
// { // {
// "event" : "unique_opened", // "id": 948562,
// "email" : "example@example.com", // "email": "test@example.com",
// "id" : 1, // "message-id": "<202312211546.94160606300@smtp-relay.mailin.fr>",
// "date" : "yyyy-m-d h:i:s", // "date": "2023-12-21 18:34:42",
// "message-id" : "<xxx@msgid.domain>", // "tags": [
// "subject" : "Test subject", // "gMtwiTIJtJxklXCj1OUFANgY6YYynQxV"
// "tag" : "<defined-tag>", // ],
// "sending_ip" : "xxx.xx.xxx.xx", // "tag": "[\"gMtwiTIJtJxklXCj1OUFANgY6YYynQxV\"]",
// "ts_epoch" : 1534486682000, // "event": "unique_opened",
// "template_id" : 1 // "subject": "Reminder: Invoice 0002 from Untitled Company",
// } // "sending_ip": "74.125.208.8",
// { // "ts": 1703180082,
// "event" : "opened", // "ts_epoch": 1703180082286,
// "email" : "frichris@hotmail.fr", // "ts_event": 1703180082,
// "id" : 1, // "link": "",
// "date" : "yyyy-m-d h:i:s", // "sender_email": "user@example.com"
// "message-id" : "<xxx@msgid.domain>", // }
// "subject" : "Test subject", // {
// "tag" : "<defined-tag>", // "id": 948562,
// "sending_ip" : "xxx.xx.xxx.xx", // "email": "test@example.com",
// "ts_epoch" : 1534486682000, // "message-id": "<202312211555.14720890391@smtp-relay.mailin.fr>",
// "template_id" : 1 // "date": "2023-12-21 18:34:53",
// } // "tags": [
// "gMtwiTIJtJxklXCj1OUFANgY6YYynQxV"
// ],
// "tag": "[\"gMtwiTIJtJxklXCj1OUFANgY6YYynQxV\"]",
// "event": "opened",
// "subject": "Reminder: Invoice 0002 from Untitled Company",
// "sending_ip": "74.125.208.8",
// "ts": 1703180093,
// "ts_epoch": 1703180093075,
// "ts_event": 1703180093,
// "link": "",
// "sender_email": "user@example.com"
// }
private function processOpen() private function processOpen()
{ {
@ -163,17 +176,23 @@ class ProcessBrevoWebhook implements ShouldQueue
} }
// { // {
// "event" : "delivered", // "id": 948562,
// "email" : "example@example.com", // "email": "test@example",
// "id" : 1, // "message-id": "<202312211742.12697514322@smtp-relay.mailin.fr>",
// "date" : "yyyy-m-d h:i:s", // "date": "2023-12-21 18:42:31",
// "message-id" : "<xxx@msgid.domain>", // "tags": [
// "subject" : "Test subject", // "gMtwiTIJtJxklXCj1OUFANgY6YYynQxV"
// "tag" : "<defined-tag>", // ],
// "sending_ip" : "xxx.xx.xxx.xx", // "tag": "[\"gMtwiTIJtJxklXCj1OUFANgY6YYynQxV\"]",
// "ts_epoch" : 1534486682000, // "event": "delivered",
// "template_id" : 1 // "subject": "Reminder: Invoice 0002 from Untitled Company",
// } // "sending_ip": "77.32.148.26",
// "ts_event": 1703180551,
// "ts": 1703180551,
// "reason": "sent",
// "ts_epoch": 1703180551324,
// "sender_email": "user@example.com"
// }
private function processDelivery() private function processDelivery()
{ {
$this->invitation->email_status = 'delivered'; $this->invitation->email_status = 'delivered';
@ -199,29 +218,41 @@ class ProcessBrevoWebhook implements ShouldQueue
} }
// { // {
// "event" : "soft_bounce", // "id": 948562,
// "email" : "example@example.com", // "email": "ryder36@example.net",
// "id" : 1, // "message-id": "<202312211744.55168080257@smtp-relay.mailin.fr>",
// "date" : "yyyy-mm-dd hh:i:s", // "date": "2023-12-21 18:44:52",
// "message-id" : "<xxx@msgid.domain>", // "tags": [
// "reason" : "<reason-for-deferred>", // "gMtwiTIJtJxklXCj1OUFANgY6YYynQxV"
// "tag" : "<defined-tag>", // ],
// "sending_ip" : "xxx.xx.xxx.xx", // "tag": "[\"gMtwiTIJtJxklXCj1OUFANgY6YYynQxV\"]",
// "ts_epoch" : 1534486682000, // "event": "soft_bounce",
// "template_id" : 1 // "subject": "Reminder: Invoice 0001 from Untitled Company",
// } // "sending_ip": "77.32.148.26",
// { // "ts_event": 1703180692,
// "event" : "hard_bounce", // "ts": 1703180692,
// "email" : "example@example.com", // "reason": "Unable to find MX of domain example.net",
// "id" : 1, // "ts_epoch": 1703180692382,
// "date" : "yyyy-mm-dd hh:i:s", // "sender_email": "user@example.com"
// "message-id" : "<xxx@msgid.domain>", // }
// "reason" : "<reason-for-deferred>", // {
// "tag" : "<defined-tag>", // "id": 948562,
// "sending_ip" : "xxx.xx.xxx.xx", // "email": "gloria46@example.com",
// "ts_epoch" : 1534486682000, // "message-id": "<202312211744.57456703957@smtp-relay.mailin.fr>",
// "template_id" : 1 // "date": "2023-12-21 18:44:54",
// } // "tags": [
// "gMtwiTIJtJxklXCj1OUFANgY6YYynQxV"
// ],
// "tag": "[\"gMtwiTIJtJxklXCj1OUFANgY6YYynQxV\"]",
// "event": "hard_bounce",
// "subject": "Reminder: Invoice 0001 from Untitled Company",
// "sending_ip": "77.32.148.25",
// "ts_event": 1703180694,
// "ts": 1703180694,
// "reason": "blocked by Admin",
// "ts_epoch": 1703180694175,
// "sender_email": "user@example.com"
// }
// { // {
// "event" : "invalid_email", // "event" : "invalid_email",
// "email" : "example@example.com", // "email" : "example@example.com",
@ -229,11 +260,32 @@ class ProcessBrevoWebhook implements ShouldQueue
// "date" : "yyyy-mm-dd hh:i:s", // "date" : "yyyy-mm-dd hh:i:s",
// "message-id" : "<xxx@msgid.domain>", // "message-id" : "<xxx@msgid.domain>",
// "subject" : "Test subject", // "subject" : "Test subject",
// "tag" : "<defined-tag>", // "tag" : "<defined-tag>",//json of array
// "tags": [
// "company_key"
// ],
// "sending_ip" : "xxx.xx.xxx.xx", // "sending_ip" : "xxx.xx.xxx.xx",
// "ts_epoch" : 1534486682000, // "ts_epoch" : 1534486682000,
// "template_id" : 1 // "template_id" : 1,
// "sender_email": "user@example.com",
// } // }
// {
// "id": 948562,
// "email": "neoma.langosh@example.com",
// "message-id": "<202312211745.65538701430@smtp-relay.mailin.fr>",
// "date": "2023-12-21 18:45:48",
// "tags": [
// "gMtwiTIJtJxklXCj1OUFANgY6YYynQxV"
// ],
// "tag": "[\"gMtwiTIJtJxklXCj1OUFANgY6YYynQxV\"]",
// "event": "blocked",
// "subject": "Reminder: Invoice 0001 from Untitled Company",
// "ts_event": 1703180748,
// "ts": 1703180748,
// "reason": "blocked : due to blacklist user",
// "ts_epoch": 1703180748987,
// "sender_email": "user@example.com"
// }
private function processBounce() private function processBounce()
{ {
@ -241,8 +293,8 @@ class ProcessBrevoWebhook implements ShouldQueue
$this->invitation->save(); $this->invitation->save();
$bounce = new EmailBounce( $bounce = new EmailBounce(
$this->request['tag'], $this->request['tags'][0],
$this->request['From'], // TODO: @turbo124 is this the recipent? $this->request['sender_email'], // TODO: @turbo124 is this the recipent?
$this->request['message-id'] $this->request['message-id']
); );
@ -269,8 +321,12 @@ class ProcessBrevoWebhook implements ShouldQueue
// "id" : 1, // "id" : 1,
// "date" : "yyyy-mm-dd hh:i:s", // "date" : "yyyy-mm-dd hh:i:s",
// "message-id" : "<xxx@msgid.domain>", // "message-id" : "<xxx@msgid.domain>",
// "tag" : "<defined-tag>", // "tag" : "<defined-tag>",//json of array
// "tags": [
// "company_key"
// ],
// "sending_ip" : "xxx.xx.xxx.xx", // "sending_ip" : "xxx.xx.xxx.xx",
// "sender_email": "user@example.com",
// } // }
private function processSpamComplaint() private function processSpamComplaint()
{ {
@ -278,8 +334,8 @@ class ProcessBrevoWebhook implements ShouldQueue
$this->invitation->save(); $this->invitation->save();
$spam = new EmailSpam( $spam = new EmailSpam(
$this->request['tag'], $this->request['tags'][0],
$this->request['From'], // TODO $this->request['sender_email'],
$this->request['message-id'] $this->request['message-id']
); );
@ -362,10 +418,10 @@ class ProcessBrevoWebhook implements ShouldQueue
$messageDetail = $this->getRawMessage($this->request['message-id']); $messageDetail = $this->getRawMessage($this->request['message-id']);
$recipients = collect($messageDetail['recipients'])->flatten()->implode(','); $recipients = $this->request["email"];
$subject = $messageDetail->getSubject() ?? ''; $subject = $messageDetail->getSubject() ?? '';
$events = collect($messageDetail->getEvents())->map(function (GetTransacEmailContentEvents $event) { $events = collect($messageDetail->getEvents())->map(function (GetTransacEmailContentEvents $event) { // @turbo124 event does only contain name & time property, how to handle transformation?!
return [ return [
'bounce_id' => $event?->Details?->BounceID ?? '', 'bounce_id' => $event?->Details?->BounceID ?? '',