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

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 attachment_payload(attachments)
  OnyxCord::MessagePayload.attachment_payload(attachments)
end

.create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components) ⇒ Object



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



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, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = 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: embeds, components: components, flags: flags, attachments: attachments, poll: poll)
  data = { tts: tts, content: content, embeds: embeds, allowed_mentions: allowed_mentions, flags: flags, components: components, attachments: attachments ? attachment_payload(attachments) : nil, choices: choices, poll: poll }.compact

  body = if attachments
           multipart_body({ type: type, data: data }, attachments)
         else
           { type: type, data: data }.to_json
         end

  headers = { content_type: :json } unless attachments

  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



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.token_delete_message(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



15
16
17
# File 'lib/onyxcord/rest/routes/interaction/response.rb', line 15

def edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil, flags = nil, poll = nil)
  OnyxCord::REST::Webhook.token_edit_message(interaction_token, application_id, '@original', content, embeds, allowed_mentions, components, attachments, flags, poll)
end

.get_original_interaction_response(interaction_token, application_id) ⇒ Object



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.token_get_message(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, attachments)
  OnyxCord::MessagePayload.multipart_body(body, attachments)
end