Module: OnyxCord::REST::Interaction
- Defined in:
- lib/onyxcord/rest/routes/interaction/base.rb,
lib/onyxcord/rest/routes/interaction/response.rb
Overview
API calls for interactions — response management.
Class Method Summary collapse
-
.attachment_payload(attachments) ⇒ Object
Build attachment metadata payload for multipart uploads.
-
.create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components) ⇒ Object
Create a response that results in a modal.
-
.create_interaction_response(interaction_token, interaction_id, type, content = nil, tts = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil, choices = nil, with_response = nil, poll = nil) ⇒ Object
Respond to an interaction.
-
.delete_original_interaction_response(interaction_token, application_id) ⇒ Object
Delete the original response to an interaction.
-
.edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil, flags = nil, poll = nil) ⇒ Object
Edit the original response to an interaction.
-
.get_original_interaction_response(interaction_token, application_id) ⇒ Object
Get the original response to an interaction.
-
.multipart_body(body, attachments) ⇒ Object
Build multipart body with named file fields and JSON payload.
Class Method Details
.attachment_payload(attachments) ⇒ Object
Build attachment metadata payload for multipart uploads. Returns an array of { id:, filename: } hashes.
11 12 13 |
# File 'lib/onyxcord/rest/routes/interaction/base.rb', line 11 def () OnyxCord::MessagePayload.() end |
.create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components) ⇒ Object
Create a response that results in a modal. https://discord.com/developers/docs/interactions/slash-commands#create-interaction-response
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/onyxcord/rest/routes/interaction/base.rb', line 48 def create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components) data = { custom_id: custom_id, title: title, components: components.to_a }.compact OnyxCord::REST.request( :interactions_iid_token_callback, interaction_id, :post, "#{OnyxCord::REST.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback", { type: 9, data: data }.to_json, content_type: :json ) end |
.create_interaction_response(interaction_token, interaction_id, type, content = nil, tts = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil, choices = nil, with_response = nil, poll = nil) ⇒ Object
Respond to an interaction. https://discord.com/developers/docs/interactions/slash-commands#create-interaction-response
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/onyxcord/rest/routes/interaction/base.rb', line 22 def create_interaction_response(interaction_token, interaction_id, type, content = nil, tts = nil, = nil, allowed_mentions = nil, flags = nil, components = nil, = nil, choices = nil, with_response = nil, poll = nil) components = OnyxCord::MessageComponents.payload(components) unless components.nil? flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components) OnyxCord::MessagePayload.validate!(content: content, embeds: , components: components, flags: flags, attachments: , poll: poll) data = { tts: tts, content: content, embeds: , allowed_mentions: allowed_mentions, flags: flags, components: components, attachments: ? () : nil, choices: choices, poll: poll }.compact body = if multipart_body({ type: type, data: data }, ) else { type: type, data: data }.to_json end headers = { content_type: :json } unless OnyxCord::REST.request( :interactions_iid_token_callback, interaction_id, :post, "#{OnyxCord::REST.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback?with_response=#{with_response ? 'true' : 'false'}", body, headers ) end |
.delete_original_interaction_response(interaction_token, application_id) ⇒ Object
Delete the original response to an interaction. https://discord.com/developers/docs/interactions/slash-commands#delete-original-interaction-response
21 22 23 |
# File 'lib/onyxcord/rest/routes/interaction/response.rb', line 21 def delete_original_interaction_response(interaction_token, application_id) OnyxCord::REST::Webhook.(interaction_token, application_id, '@original') end |
.edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil, flags = nil, poll = nil) ⇒ Object
Edit the original response to an interaction. https://discord.com/developers/docs/interactions/slash-commands#edit-original-interaction-response
15 16 17 |
# File 'lib/onyxcord/rest/routes/interaction/response.rb', line 15 def edit_original_interaction_response(interaction_token, application_id, content = nil, = nil, allowed_mentions = nil, components = nil, = nil, flags = nil, poll = nil) OnyxCord::REST::Webhook.(interaction_token, application_id, '@original', content, , allowed_mentions, components, , flags, poll) end |
.get_original_interaction_response(interaction_token, application_id) ⇒ Object
Get the original response to an interaction. https://discord.com/developers/docs/interactions/slash-commands#get-original-interaction-response
9 10 11 |
# File 'lib/onyxcord/rest/routes/interaction/response.rb', line 9 def get_original_interaction_response(interaction_token, application_id) OnyxCord::REST::Webhook.(interaction_token, application_id, '@original') end |
.multipart_body(body, attachments) ⇒ Object
Build multipart body with named file fields and JSON payload.
16 17 18 |
# File 'lib/onyxcord/rest/routes/interaction/base.rb', line 16 def multipart_body(body, ) OnyxCord::MessagePayload.multipart_body(body, ) end |