Module: Telegram::Bot::Client::RequestBodyFormatter

Extended by:
RequestBodyFormatter
Included in:
RequestBodyFormatter
Defined in:
lib/telegram/bot/client/request_body_formatter.rb

Overview

Encodes nested hashes and arrays as json and extract File objects from them to the top level. Top-level File objects are handled by httpclient. More details: core.telegram.org/bots/api#sending-files

Instance Method Summary collapse

Instance Method Details

#format(body, action) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/telegram/bot/client/request_body_formatter.rb', line 14

def format(body, action)
  body = body.dup
  case action.to_s
  when 'sendMediaGroup'
    extract_files_from_array!(body, :media)
  when 'editMessageMedia'
    replace_field(body, :media) do |value|
      files = {}
      extract_files_from_hash(value, files).tap { body.merge!(files) }
    end
  end
  body.each do |key, val|
    body[key] = val.to_json if val.is_a?(Hash) || val.is_a?(Array)
  end
end