From b74d48fe5fb5ef0c8f0e24fe41669fed0c30c5b4 Mon Sep 17 00:00:00 2001 From: Vilen Topchii <32271530+vtopc@users.noreply.github.com> Date: Sat, 9 Nov 2024 12:05:33 +0200 Subject: [PATCH] DE-1348 Missing webhook events (#339) fixes #337 --- README.md | 2 +- events/events.go | 14 +++++++++++--- webhooks.go | 5 +++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 75af9d58..2afda084 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Mailgun with Go [![GoDoc](https://godoc.org/github.com/mailgun/mailgun-go?status.svg)](https://godoc.org/github.com/mailgun/mailgun-go/v4) -[![Build Status](https://github.com/mailgun/mailgun-go/workflows/CI/badge.svg)](https://github.com/mailgun/mailgun-go/actions/workflows/main.yml) +[![Build Status](https://github.com/mailgun/mailgun-go/workflows/CI/badge.svg)](https://github.com/mailgun/mailgun-go/actions/workflows/main.yml?query=branch%3Amaster) Go library for interacting with the [Mailgun](https://mailgun.com/) [API](https://documentation.mailgun.com/en/latest/api_reference.html). diff --git a/events/events.go b/events/events.go index d0b96fd8..72405542 100644 --- a/events/events.go +++ b/events/events.go @@ -99,6 +99,8 @@ type Delivered struct { UserVariables interface{} `json:"user-variables"` } +// Failed - Mailgun could not deliver the email to the recipient email server. +// Use for permanent_fail and temporary_fail webhooks. type Failed struct { Generic @@ -114,9 +116,15 @@ type Failed struct { Storage Storage `json:"storage"` DeliveryStatus DeliveryStatus `json:"delivery-status"` - Severity string `json:"severity"` - Reason string `json:"reason"` - UserVariables interface{} `json:"user-variables"` + + // Severity: + // + // - permanent when a message is not delivered; + // + // - temporary when a message is temporarily rejected by an ESP. + Severity string `json:"severity"` + Reason string `json:"reason"` + UserVariables interface{} `json:"user-variables"` } type Stored struct { diff --git a/webhooks.go b/webhooks.go index d93d925a..462855dd 100644 --- a/webhooks.go +++ b/webhooks.go @@ -52,12 +52,13 @@ func (mg *MailgunImpl) ListWebhooks(ctx context.Context) (map[string][]string, e } // CreateWebhook installs a new webhook for your domain. -func (mg *MailgunImpl) CreateWebhook(ctx context.Context, kind string, urls []string) error { +// List of ids - https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Webhooks/#tag/Webhooks +func (mg *MailgunImpl) CreateWebhook(ctx context.Context, id string, urls []string) error { r := newHTTPRequest(generateDomainApiUrl(mg, webhooksEndpoint)) r.setClient(mg.Client()) r.setBasicAuth(basicAuthUser, mg.APIKey()) p := newUrlEncodedPayload() - p.addValue("id", kind) + p.addValue("id", id) for _, url := range urls { p.addValue("url", url) }