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

support allowing webhook edits with files, and responding to interactions with files #931

Merged
merged 15 commits into from Jul 30, 2021
Merged

Conversation

plally
Copy link
Contributor

@plally plally commented May 14, 2021

Webhook edits and as a result interaction followups support uploading files
https://discord.com/developers/docs/resources/webhook#edit-webhook-message

While not documented it is also possible to include files in slash command responses

This implements the same functionality as #913. and that pr may be closed if this one is approved.

@plally plally marked this pull request as ready for review May 18, 2021 16:03
@plally plally mentioned this pull request May 18, 2021
@CarsonHoffman
Copy link
Collaborator

Is there any particular reason that EncodeWithFiles is exported here? It seems to me like this is pretty firmly internal details, and exposing it in the library's interface might cause additional confusion around file handling (e.g. I can see someone calling this function to then use as the value of a file).

@plally
Copy link
Contributor Author

plally commented Jun 18, 2021

The function would be useful to anyone implementing an http interactions endpoint. Anyone who wants to respond with files to an http interactions request would need to do this.

Maybe theres a better solution that would be clearer to users of the library. like making a method on interactions to get the response body? If you still think it should be unexported thats also fine

restapi.go Outdated Show resolved Hide resolved
@CarsonHoffman
Copy link
Collaborator

Having given it another thought, since having the function exported seems like the way to go, I'm not sure that EncodeWithFiles is the best name for the function—"encode" is quite ambiguous, and the name of the function doesn't really describe what it does without the additional context of it being an HTTP body that contains JSON in a part. The first thought that comes to my mind would be something like JSONBodyWithFiles; do you have any opinions on this?

@plally
Copy link
Contributor Author

plally commented Jun 19, 2021

Im happy to rename the function to JSONBodyWithFiles or anything better anyone else thinks of. I agree EncodeWithFiles isn't great.
maybe something like MultipartBodyWithJSON would be a better description of what it returns?

@SirFist
Copy link

SirFist commented Jun 24, 2021

Not sure if you'd want it to fall under this PR or another, but this could be expanded to also cover uploading files when editing messages as they also support it now. Everything also seems to support editing attachments too, which might be sensible to have covered alongside this functionality?

@plally plally requested a review from CarsonHoffman July 4, 2021 05:12
interactions.go Outdated
Type InteractionResponseType `json:"type,omitempty"`
Data *InteractionResponseData `json:"data,omitempty"`
Type InteractionResponseType `json:"type,omitempty"`
Files []*File `json:"-"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to me like this field would be better situated inside InteractionResponseData next to Content, Embeds, etc. just like WebhookEdit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My original reasoning was that Files aren't really part of the response structure, more just things that get passed alongside the response. You could even return just {"type":4} as the response if it contains files as well.

@CarsonHoffman CarsonHoffman merged commit ab47f12 into bwmarrin:master Jul 30, 2021
FedorLap2006 pushed a commit to FedorLap2006/discordgo that referenced this pull request Jul 30, 2021
…ions with files (bwmarrin#931)

* allow files in webhook message edits

* add Files to WebhookEdit struct

* move the construction of the multipart body for files into a shared function

* allow  interaction responses to have files

* go fmt

* fix err shadowing

* document MakeFilesBody

* rename MakeFilesBody -> EncodeWithFiles. fix InteractionRespond responding twice

* use resp in InteractionRespond files, add basic-command-with-files example command

* import strings and go fmt

* EncodeWithFiles -> MultiPartBodyWithJSON

* go fmt

* fix example for slash_commands

* move files to responsedata
CarsonHoffman added a commit that referenced this pull request Aug 9, 2021
* Interactions: the Buttons (#933)

* Interactions: buttons

* Doc fix

* Gofmt fix

* Fix typo

* Remaking interaction data into interface

* Godoc fix

* Gofmt fix

* Godoc fix

* InteractionData helper functions and some fixes in slash commands example

* Fix components example

* Yet another fix of components example

* Fix interaction unmarshaling

* Gofmt fix

* Godoc fix

* Gofmt fix

* Corrected naming and docs

* Rolled back API version

* Requested fixes

* Added support of components to webhook and regular messages

* Fix components unmarshaling

* Godoc fix

* Requested fixes

* Fixed unmarshaling issues

* Components example: cleanup

* Added components tracking to state

* Requested fixes

* Renaming fix

* Remove more named returns

* Minor English fixes

Co-authored-by: Carson Hoffman <c@rsonhoffman.com>

* Doc fix

* Gofmt fix

* Fix typo

* Remaking interaction data into interface

* Godoc fix

* Gofmt fix

* Godoc fix

* InteractionData helper functions and some fixes in slash commands example

* Fix components example

* Yet another fix of components example

* Fix interaction unmarshaling

* Godoc fix

* Gofmt fix

* Corrected naming and docs

* Rolled back API version

* Requested fixes

* Added support of components to webhook and regular messages

* Interactions: select menus

* Example fix

* Merge fix

* Some fixes

* Added missing documentation

* Fix components unmarshaling

* Godoc fix

* Requested fixes

* Fixed unmarshaling issues

* Components example: cleanup

* Gofmt fix

* Godoc fix

* URL field renaming fix

* Added flags to followups

* Updated components example

* Fixed typo in components example

* Merge fix

* Improve handling of invalid interaction situations

* support allowing webhook edits with files, and responding to interactions with files (#931)

* allow files in webhook message edits

* add Files to WebhookEdit struct

* move the construction of the multipart body for files into a shared function

* allow  interaction responses to have files

* go fmt

* fix err shadowing

* document MakeFilesBody

* rename MakeFilesBody -> EncodeWithFiles. fix InteractionRespond responding twice

* use resp in InteractionRespond files, add basic-command-with-files example command

* import strings and go fmt

* EncodeWithFiles -> MultiPartBodyWithJSON

* go fmt

* fix example for slash_commands

* move files to responsedata

* Merge fixes

* Fixed rebase consequences

Co-authored-by: Carson Hoffman <c@rsonhoffman.com>
Co-authored-by: plally <pierce@vulpes.dev>
jccit pushed a commit to jccit/discordgo that referenced this pull request Sep 14, 2021
…ions with files (bwmarrin#931)

* allow files in webhook message edits

* add Files to WebhookEdit struct

* move the construction of the multipart body for files into a shared function

* allow  interaction responses to have files

* go fmt

* fix err shadowing

* document MakeFilesBody

* rename MakeFilesBody -> EncodeWithFiles. fix InteractionRespond responding twice

* use resp in InteractionRespond files, add basic-command-with-files example command

* import strings and go fmt

* EncodeWithFiles -> MultiPartBodyWithJSON

* go fmt

* fix example for slash_commands

* move files to responsedata
jccit pushed a commit to jccit/discordgo that referenced this pull request Sep 14, 2021
* Interactions: the Buttons (bwmarrin#933)

* Interactions: buttons

* Doc fix

* Gofmt fix

* Fix typo

* Remaking interaction data into interface

* Godoc fix

* Gofmt fix

* Godoc fix

* InteractionData helper functions and some fixes in slash commands example

* Fix components example

* Yet another fix of components example

* Fix interaction unmarshaling

* Gofmt fix

* Godoc fix

* Gofmt fix

* Corrected naming and docs

* Rolled back API version

* Requested fixes

* Added support of components to webhook and regular messages

* Fix components unmarshaling

* Godoc fix

* Requested fixes

* Fixed unmarshaling issues

* Components example: cleanup

* Added components tracking to state

* Requested fixes

* Renaming fix

* Remove more named returns

* Minor English fixes

Co-authored-by: Carson Hoffman <c@rsonhoffman.com>

* Doc fix

* Gofmt fix

* Fix typo

* Remaking interaction data into interface

* Godoc fix

* Gofmt fix

* Godoc fix

* InteractionData helper functions and some fixes in slash commands example

* Fix components example

* Yet another fix of components example

* Fix interaction unmarshaling

* Godoc fix

* Gofmt fix

* Corrected naming and docs

* Rolled back API version

* Requested fixes

* Added support of components to webhook and regular messages

* Interactions: select menus

* Example fix

* Merge fix

* Some fixes

* Added missing documentation

* Fix components unmarshaling

* Godoc fix

* Requested fixes

* Fixed unmarshaling issues

* Components example: cleanup

* Gofmt fix

* Godoc fix

* URL field renaming fix

* Added flags to followups

* Updated components example

* Fixed typo in components example

* Merge fix

* Improve handling of invalid interaction situations

* support allowing webhook edits with files, and responding to interactions with files (bwmarrin#931)

* allow files in webhook message edits

* add Files to WebhookEdit struct

* move the construction of the multipart body for files into a shared function

* allow  interaction responses to have files

* go fmt

* fix err shadowing

* document MakeFilesBody

* rename MakeFilesBody -> EncodeWithFiles. fix InteractionRespond responding twice

* use resp in InteractionRespond files, add basic-command-with-files example command

* import strings and go fmt

* EncodeWithFiles -> MultiPartBodyWithJSON

* go fmt

* fix example for slash_commands

* move files to responsedata

* Merge fixes

* Fixed rebase consequences

Co-authored-by: Carson Hoffman <c@rsonhoffman.com>
Co-authored-by: plally <pierce@vulpes.dev>
@FedorLap2006 FedorLap2006 added this to the v0.24.0 milestone Feb 27, 2022
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.

None yet

4 participants