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 multipart file uploads for interaction responses via webhook builder #178
base: main
Are you sure you want to change the base?
Support multipart file uploads for interaction responses via webhook builder #178
Conversation
@swarley is this PR good to merge as is? or would you prefer support for |
@robherley If you're up to the task we can get the multi file upload going here, otherwise I can take care of expanding it in a separate PR. I'd like to get it working with multiple files before we tag a new release 🙂. Let me know what you want to do |
@swarley I can add the multi-file attachments in this PR! Just a couple impl questions:
|
I would mark as deprecated, and I'd like to change the API methods to use kwargs in the next major release but currently they need to stay as positional for consistency and semver reasons. |
@swarley multi-file attachments should be supported now: fileA = File.open('/Users/robherley/Pictures/photoA.png')
fileB = File.open('/Users/robherley/Pictures/photoB.png')
event.respond(content: 'photos!') do |builder|
builder.attachments = [fileA, fileB]
end
also noticed the rubocop complaining about unchanged files 🤷 I can fix those if you want |
Summary
Currently, if you wish to attach a file to an interaction via the webhook builder it does not work.
Also, today the webhook builder does not support multiple attachments.
The desired behavior would be as follows:
The methods defined in the webhook API only serialized the interaction data for a json payload:
discordrb/lib/discordrb/data/interaction.rb
Lines 97 to 100 in dc27fe1
This PR adds support for file uploads via the interaction methods that support it. To avoid breaking changes and compatibility with the current method signature, I added an additional nil-by-default param. However, it would be nice to move these all to keyword arguments eventually.
I also added some specs for the modules that were missing them. They don't have complete coverage of the module, but cover the changes introduced in this PR.
Added
Discordrb::Webhooks::Builder#to_payload_hash
: returns relevant hash depending on the presence of@file
or@attachments
Discordrb::API::Interaction
Discordrb::Interaction
Changed
Discordrb::API::Interaction
attachments
as a parameter to#create_interaction_response
Discordrb::API::Webhook
attachments
as a parameter to#token_edit_message
and#token_execute_webhook
Discordrb::Interaction
#respond
,#update_message
,#edit_response
,#send_message
,#edit_message
:#to_payload_hash
instead of#to_json_hash
for webhook builderattachments
param from webhook builder to relevant API methodfile
from webhook builder was only used in#send_message
(bc of#token_execute_webhook
), so it'll be the only method that supports the deprecated param behaviorDeprecated
Discordrb::Webhooks::Builder#file
: added warning log and appropriate yard doc commentsRemoved
None
Fixed
Channel#delete_all_emoji_reactions
test, it was a small mistake with the emoji encoding