1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01: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,28 +115,40 @@ 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,
// "ts_epoch": 1703180082286,
// "ts_event": 1703180082,
// "link": "",
// "sender_email": "user@example.com"
// } // }
// { // {
// "event" : "opened", // "id": 948562,
// "email" : "frichris@hotmail.fr", // "email": "test@example.com",
// "id" : 1, // "message-id": "<202312211555.14720890391@smtp-relay.mailin.fr>",
// "date" : "yyyy-m-d h:i:s", // "date": "2023-12-21 18:34:53",
// "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": "opened",
// "template_id" : 1 // "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,16 +176,22 @@ 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()
{ {
@ -199,28 +218,40 @@ 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,
// "ts": 1703180692,
// "reason": "Unable to find MX of domain example.net",
// "ts_epoch": 1703180692382,
// "sender_email": "user@example.com"
// } // }
// { // {
// "event" : "hard_bounce", // "id": 948562,
// "email" : "example@example.com", // "email": "gloria46@example.com",
// "id" : 1, // "message-id": "<202312211744.57456703957@smtp-relay.mailin.fr>",
// "date" : "yyyy-mm-dd hh:i:s", // "date": "2023-12-21 18:44:54",
// "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": "hard_bounce",
// "template_id" : 1 // "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",
@ -229,10 +260,31 @@ 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 ?? '',