Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing webhook thread endpoints and allow overriding webhook message attachments #1390

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,28 @@ func (s *Session) WebhookMessage(webhookID, token, messageID string, options ...
return
}

// 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
// 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
Expand Down Expand Up @@ -2431,6 +2453,41 @@ func (s *Session) WebhookMessageEdit(webhookID, token, messageID string, data *W
return
}

// 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
// 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
Expand All @@ -2442,6 +2499,22 @@ func (s *Session) WebhookMessageDelete(webhookID, token, messageID string, optio
return
}

// 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
// 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.
Expand Down