From ceb8ed8ce5538c74c6bc4ebb79519c2c3c87705e Mon Sep 17 00:00:00 2001 From: merlinfuchs Date: Fri, 9 Jun 2023 13:35:54 +0200 Subject: [PATCH 1/4] allow overriding webhook message attachments --- webhook.go | 1 + 1 file changed, 1 insertion(+) diff --git a/webhook.go b/webhook.go index 9209b7095..dc0affac4 100644 --- a/webhook.go +++ b/webhook.go @@ -47,4 +47,5 @@ type WebhookEdit struct { Embeds *[]*MessageEmbed `json:"embeds,omitempty"` Files []*File `json:"-"` AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"` + Attachments *[]*MessageAttachment `json:"attachments,omitempty"` } From c5bf7658f6b61730916b0f86c0c9eaa00a4df24b Mon Sep 17 00:00:00 2001 From: merlinfuchs Date: Fri, 9 Jun 2023 13:37:42 +0200 Subject: [PATCH 2/4] add missing webhook thread endpoints --- restapi.go | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/restapi.go b/restapi.go index b2d69598f..969376f0c 100644 --- a/restapi.go +++ b/restapi.go @@ -2401,6 +2401,28 @@ func (s *Session) WebhookMessage(webhookID, token, messageID string, options ... return } +// WebhookMessage gets a webhook message. +// webhookID : The ID of a webhook +// token : The auth token for the webhook +// messageID : The ID of message to get +// threadID : Get a message in the specified thread within a webhook's channel. +func (s *Session) WebhookThreadMessage(webhookID, token, threadID, messageID string, options ...RequestOption) (message *Message, err error) { + uri := EndpointWebhookMessage(webhookID, token, messageID) + + v := url.Values{} + v.Set("thread_id", threadID) + uri += "?" + v.Encode() + + body, err := s.RequestWithBucketID("GET", uri, nil, EndpointWebhookToken("", ""), options...) + if err != nil { + return + } + + err = Unmarshal(body, &message) + + return +} + // WebhookMessageEdit edits a webhook message and returns a new one. // webhookID : The ID of a webhook // token : The auth token for the webhook @@ -2431,6 +2453,41 @@ func (s *Session) WebhookMessageEdit(webhookID, token, messageID string, data *W return } +// WebhookMessageEdit edits a webhook message in a thread and returns a new one. +// webhookID : The ID of a webhook +// token : The auth token for the webhook +// messageID : The ID of message to edit +// threadID : Edits a message in the specified thread within a webhook's channel. +func (s *Session) WebhookThreadMessageEdit(webhookID, token, threadID, messageID string, data *WebhookEdit, options ...RequestOption) (st *Message, err error) { + uri := EndpointWebhookMessage(webhookID, token, messageID) + + v := url.Values{} + v.Set("thread_id", threadID) + uri += "?" + v.Encode() + + var response []byte + if len(data.Files) > 0 { + contentType, body, err := MultipartBodyWithJSON(data, data.Files) + if err != nil { + return nil, err + } + + response, err = s.request("PATCH", uri, contentType, body, uri, 0, options...) + if err != nil { + return nil, err + } + } else { + response, err = s.RequestWithBucketID("PATCH", uri, data, EndpointWebhookToken("", ""), options...) + + if err != nil { + return nil, err + } + } + + err = unmarshal(response, &st) + return +} + // WebhookMessageDelete deletes a webhook message. // webhookID : The ID of a webhook // token : The auth token for the webhook @@ -2442,6 +2499,22 @@ func (s *Session) WebhookMessageDelete(webhookID, token, messageID string, optio return } +// WebhookMessageDelete deletes a webhook message. +// webhookID : The ID of a webhook +// token : The auth token for the webhook +// messageID : The ID of a message to edit +// threadID : Deletes a message in the specified thread within a webhook's channel. +func (s *Session) WebhookThreadMessageDelete(webhookID, token, threadID, messageID string, options ...RequestOption) (err error) { + uri := EndpointWebhookMessage(webhookID, token, messageID) + + v := url.Values{} + v.Set("thread_id", threadID) + uri += "?" + v.Encode() + + _, err = s.RequestWithBucketID("DELETE", uri, nil, EndpointWebhookToken("", ""), options...) + return +} + // MessageReactionAdd creates an emoji reaction to a message. // channelID : The channel ID. // messageID : The message ID. From 600778209f0a07b2d2b68ebd61677cdba11df1a8 Mon Sep 17 00:00:00 2001 From: merlinfuchs Date: Fri, 9 Jun 2023 16:46:44 +0200 Subject: [PATCH 3/4] fix lint --- restapi.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/restapi.go b/restapi.go index 969376f0c..0b2fa8e77 100644 --- a/restapi.go +++ b/restapi.go @@ -2401,7 +2401,7 @@ func (s *Session) WebhookMessage(webhookID, token, messageID string, options ... return } -// WebhookMessage gets a webhook message. +// WebhookThreadMessage gets a webhook message. // webhookID : The ID of a webhook // token : The auth token for the webhook // messageID : The ID of message to get @@ -2453,7 +2453,7 @@ func (s *Session) WebhookMessageEdit(webhookID, token, messageID string, data *W return } -// WebhookMessageEdit edits a webhook message in a thread and returns a new one. +// WebhookThreadMessageEdit edits a webhook message in a thread and returns a new one. // webhookID : The ID of a webhook // token : The auth token for the webhook // messageID : The ID of message to edit @@ -2499,7 +2499,7 @@ func (s *Session) WebhookMessageDelete(webhookID, token, messageID string, optio return } -// WebhookMessageDelete deletes a webhook message. +// WebhookThreadMessageDelete deletes a webhook message. // webhookID : The ID of a webhook // token : The auth token for the webhook // messageID : The ID of a message to edit From ab6b94fccf64401a632049a802adb41fcc7c939e Mon Sep 17 00:00:00 2001 From: merlinfuchs Date: Mon, 19 Jun 2023 20:35:59 +0200 Subject: [PATCH 4/4] attachments field is added in separate PR --- webhook.go | 1 - 1 file changed, 1 deletion(-) diff --git a/webhook.go b/webhook.go index dc0affac4..9209b7095 100644 --- a/webhook.go +++ b/webhook.go @@ -47,5 +47,4 @@ type WebhookEdit struct { Embeds *[]*MessageEmbed `json:"embeds,omitempty"` Files []*File `json:"-"` AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"` - Attachments *[]*MessageAttachment `json:"attachments,omitempty"` }