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

Integrate handling of interactions via outgoing webhooks #1181

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

topi314
Copy link
Contributor

@topi314 topi314 commented May 8, 2022

This pr adds a lightweight hopefully flexible enough implementation of handling interactions via outgoing webhooks

discord docs: https://discord.com/developers/docs/interactions/receiving-and-responding#receiving-an-interaction

how it works:

  • discordgo.Session implements the http.Handler interface(like this you can choose whatever webserver you want)
  • session.ServeHTTP verifies if the interaction comes from discord
  • fires a normal interaction create event with an extra Respond field which holds a function which can be used to the http request discord sent
  • timeout(not responding within 3s) is handled by discordgo(logs at warning level)
  • multiple calls to respond return an error

todo:

  • useful docs

if you have any thoughts about this implementation let me know!

@FedorLap2006 FedorLap2006 added feature Major feature implementation feedback Additional feedback is required labels May 10, 2022
@FedorLap2006 FedorLap2006 changed the title integrate handling of interactions via outgoing webhooks Integrate handling of interactions via outgoing webhooks May 10, 2022
@FedorLap2006 FedorLap2006 force-pushed the master branch 2 times, most recently from 05d8167 to d7b4a48 Compare May 22, 2022 22:16
@@ -381,6 +381,7 @@ type WebhooksUpdate struct {
// InteractionCreate is the data for a InteractionCreate event
type InteractionCreate struct {
*Interaction
Respond func(response *InteractionResponse) error `json:"-"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it's a good idea to place a (potentially) REST method into a gateway event structure.
And while we don't have any other place for storing that, we certainly wouldn't like to mix HTTP and gateway functional.

Copy link
Contributor Author

@topi314 topi314 Jul 12, 2022

Choose a reason for hiding this comment

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

discordgo could provide a separate interaction create event for http interactions

@FedorLap2006 FedorLap2006 added the rest REST API related issues and pull requests label Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Major feature implementation feedback Additional feedback is required rest REST API related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants