Skip to content

feat: adapt to webhooks v2#16

Open
null8626 wants to merge 13 commits into
top-gg-community:masterfrom
null8626:v1/webhooks
Open

feat: adapt to webhooks v2#16
null8626 wants to merge 13 commits into
top-gg-community:masterfrom
null8626:v1/webhooks

Conversation

@null8626
Copy link
Copy Markdown
Member

The following pull request is a fragment of a larger pull request.

It adapts the SDK's webhooks functionality to the newer approach. And since this change is obviously breaking, the pull request is a major update.

Copy link
Copy Markdown

@DevYukine DevYukine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than that, LGTM

Comment thread webhooks.go
Comment on lines +113 to +117
if err != nil {
res.WriteHeader(http.StatusBadRequest)

return
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not reject the Webhook with a 400 when you fail to parse, instead respond with 2XX and maybe log an warning or something? this is not an issue for the sender (top.gg) in this case but likely a parsing issue and responding with a non 2XX makes top.gg webhook retry which is likely failing again

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted! Thank you so much for your feedback! Will work on them!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread webhooks.go
Comment on lines +132 to +136
if err = json.Unmarshal(body, payload); err != nil {
res.WriteHeader(http.StatusBadRequest)

return
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, you should not respond with Bad Request on a parsing error on your side

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread webhooks.go Outdated

defer req.Body.Close()

body, err := io.ReadAll(req.Body)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally io.LimitReader is used to prevent some kind of DoS by memory exhaustion as the content can pretty much be sent by anyone.

It may be worth adding it to the client as well e.g. due to the bot description, although not sure if it's unlimited in length or not anymore to be fair

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

@null8626 null8626 Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also done it for the client in #15. See this commit. Nevermind, this one is reverted as the Top.gg API has their own constraints for things like long descriptions.

Copy link
Copy Markdown

@kkrypt0nn kkrypt0nn Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted! Is this what you meant?

Looking good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants