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 'hard_bounce':
case 'invalid_email':
case 'blocked':
return $this->processBounce();
case 'spam':
return $this->processSpamComplaint();
@ -114,29 +115,41 @@ class ProcessBrevoWebhook implements ShouldQueue
}
// {
// "event" : "unique_opened",
// "email" : "example@example.com",
// "id" : 1,
// "date" : "yyyy-m-d h:i:s",
// "message-id" : "<xxx@msgid.domain>",
// "subject" : "Test subject",
// "tag" : "<defined-tag>",
// "sending_ip" : "xxx.xx.xxx.xx",
// "ts_epoch" : 1534486682000,
// "template_id" : 1
// }
// {
// "event" : "opened",
// "email" : "frichris@hotmail.fr",
// "id" : 1,
// "date" : "yyyy-m-d h:i:s",
// "message-id" : "<xxx@msgid.domain>",
// "subject" : "Test subject",
// "tag" : "<defined-tag>",
// "sending_ip" : "xxx.xx.xxx.xx",
// "ts_epoch" : 1534486682000,
// "template_id" : 1
// }
// "id": 948562,
// "email": "test@example.com",
// "message-id": "<202312211546.94160606300@smtp-relay.mailin.fr>",
// "date": "2023-12-21 18:34:42",
// "tags": [
// "gMtwiTIJtJxklXCj1OUFANgY6YYynQxV"
// ],
// "tag": "[\"gMtwiTIJtJxklXCj1OUFANgY6YYynQxV\"]",
// "event": "unique_opened",
// "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"
// }
// {
// "id": 948562,
// "email": "test@example.com",
// "message-id": "<202312211555.14720890391@smtp-relay.mailin.fr>",
// "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()
{
@ -163,17 +176,23 @@ class ProcessBrevoWebhook implements ShouldQueue
}
// {
// "event" : "delivered",
// "email" : "example@example.com",
// "id" : 1,
// "date" : "yyyy-m-d h:i:s",
// "message-id" : "<xxx@msgid.domain>",
// "subject" : "Test subject",
// "tag" : "<defined-tag>",
// "sending_ip" : "xxx.xx.xxx.xx",
// "ts_epoch" : 1534486682000,
// "template_id" : 1
// }
// "id": 948562,
// "email": "test@example",
// "message-id": "<202312211742.12697514322@smtp-relay.mailin.fr>",
// "date": "2023-12-21 18:42:31",
// "tags": [
// "gMtwiTIJtJxklXCj1OUFANgY6YYynQxV"
// ],
// "tag": "[\"gMtwiTIJtJxklXCj1OUFANgY6YYynQxV\"]",
// "event": "delivered",
// "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()
{
$this->invitation->email_status = 'delivered';
@ -199,29 +218,41 @@ class ProcessBrevoWebhook implements ShouldQueue
}
// {
// "event" : "soft_bounce",
// "email" : "example@example.com",
// "id" : 1,
// "date" : "yyyy-mm-dd hh:i:s",
// "message-id" : "<xxx@msgid.domain>",
// "reason" : "<reason-for-deferred>",
// "tag" : "<defined-tag>",
// "sending_ip" : "xxx.xx.xxx.xx",
// "ts_epoch" : 1534486682000,
// "template_id" : 1
// }
// {
// "event" : "hard_bounce",
// "email" : "example@example.com",
// "id" : 1,
// "date" : "yyyy-mm-dd hh:i:s",
// "message-id" : "<xxx@msgid.domain>",
// "reason" : "<reason-for-deferred>",
// "tag" : "<defined-tag>",
// "sending_ip" : "xxx.xx.xxx.xx",
// "ts_epoch" : 1534486682000,
// "template_id" : 1
// }
// "id": 948562,
// "email": "ryder36@example.net",
// "message-id": "<202312211744.55168080257@smtp-relay.mailin.fr>",
// "date": "2023-12-21 18:44:52",
// "tags": [
// "gMtwiTIJtJxklXCj1OUFANgY6YYynQxV"
// ],
// "tag": "[\"gMtwiTIJtJxklXCj1OUFANgY6YYynQxV\"]",
// "event": "soft_bounce",
// "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"
// }
// {
// "id": 948562,
// "email": "gloria46@example.com",
// "message-id": "<202312211744.57456703957@smtp-relay.mailin.fr>",
// "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",
// "email" : "example@example.com",
@ -229,11 +260,32 @@ class ProcessBrevoWebhook implements ShouldQueue
// "date" : "yyyy-mm-dd hh:i:s",
// "message-id" : "<xxx@msgid.domain>",
// "subject" : "Test subject",
// "tag" : "<defined-tag>",
// "tag" : "<defined-tag>",//json of array
// "tags": [
// "company_key"
// ],
// "sending_ip" : "xxx.xx.xxx.xx",
// "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()
{
@ -241,8 +293,8 @@ class ProcessBrevoWebhook implements ShouldQueue
$this->invitation->save();
$bounce = new EmailBounce(
$this->request['tag'],
$this->request['From'], // TODO: @turbo124 is this the recipent?
$this->request['tags'][0],
$this->request['sender_email'], // TODO: @turbo124 is this the recipent?
$this->request['message-id']
);
@ -269,8 +321,12 @@ class ProcessBrevoWebhook implements ShouldQueue
// "id" : 1,
// "date" : "yyyy-mm-dd hh:i:s",
// "message-id" : "<xxx@msgid.domain>",
// "tag" : "<defined-tag>",
// "tag" : "<defined-tag>",//json of array
// "tags": [
// "company_key"
// ],
// "sending_ip" : "xxx.xx.xxx.xx",
// "sender_email": "user@example.com",
// }
private function processSpamComplaint()
{
@ -278,8 +334,8 @@ class ProcessBrevoWebhook implements ShouldQueue
$this->invitation->save();
$spam = new EmailSpam(
$this->request['tag'],
$this->request['From'], // TODO
$this->request['tags'][0],
$this->request['sender_email'],
$this->request['message-id']
);
@ -362,10 +418,10 @@ class ProcessBrevoWebhook implements ShouldQueue
$messageDetail = $this->getRawMessage($this->request['message-id']);
$recipients = collect($messageDetail['recipients'])->flatten()->implode(',');
$recipients = $this->request["email"];
$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 [
'bounce_id' => $event?->Details?->BounceID ?? '',