Method: Vox::HTTP::Routes::Webhook#execute_webhook

Defined in:
lib/vox/http/routes/webhook.rb

#execute_webhook(webhook_id, webhook_token, wait: :undef, content: :undef, username: :undef, avatar_url: :undef, tts: :undef, file: :undef, embeds: :undef, allowed_mentions: :undef, attachments: :undef) ⇒ Object

Post content to a webhook.

Parameters:

  • webhook_id (String, Integer)

    The ID of the webhook to post to.

  • webhook_token (String)

    The token for the target webhook.

  • wait (true, false) (defaults to: :undef)

    Waits for server confirmation of message send before response, and returns the created message body.

  • content (String) (defaults to: :undef)

    The message contents.

  • username (String) (defaults to: :undef)

    Override the default avatar of the webhook.

  • avatar_url (String) (defaults to: :undef)

    Override the default avatar of the webhook.

  • tts (true, false) (defaults to: :undef)

    If this message is TTS.

  • file (UploadIO) (defaults to: :undef)

    The file being sent.

  • embeds (Array<Hash<Symbol, Object>>) (defaults to: :undef)

    An array of up to 10 [embed](discord.com/developers/docs/resources/channel#embed-object) objects.

  • allowed_mentions (Hash<Symbol, Object>) (defaults to: :undef)

    [Allowed mentions](discord.com/developers/docs/resources/channel#allowed-mentions-object) object for this message.

  • attachments (Hash<String, UploadIO>, Array<UploadIO>) (defaults to: :undef)

    A hash in the form of ‘filename => upload_io` to be referenced in embeds via the `attachment://` URI, or an array of UploadIO who’s filenames are derived from the existing UploadIO object. See [attachment:// docs](discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds).

View On Discord's Docs:



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/vox/http/routes/webhook.rb', line 153

def execute_webhook(webhook_id, webhook_token, wait: :undef, content: :undef, username: :undef,
                    avatar_url: :undef, tts: :undef, file: :undef, embeds: :undef,
                    allowed_mentions: :undef, attachments: :undef)
  params = filter_undef({ wait: wait })
  json = filter_undef({ content: content, username: username, avatar_url: avatar_url, tts: tts, embeds: embeds,
                        allowed_mentions: allowed_mentions })
  route = Route.new(:POST, '/webhooks/%{webhook_id}/%{webhook_token}',
                    webhook_id: webhook_id, webhook_token: webhook_token)

  if file != :undef
    data = { file: file, payload_json: MultiJson.dump(json) }
    request(route, data: data, query: params)
  elsif attachments != :undef
    attachments = attachments.collect { |k, v| UploadIO.new(v.io, v.content_type, k) } if attachments.is_a? Hash
    attach_hash = Array(0...attachments.size).zip(attachments).to_h
    data = attach_hash.merge(payload_json: MultiJson.dump(json))
    request(route, data: data, query: params)
  else
    request(route, json: json, query: params)
  end
end