Class: TeBot::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/te_bot/message.rb

Defined Under Namespace

Classes: Audio, Command, Document, Format, Query, Text, Voice

Constant Summary collapse

GENERAL_MESSAGE_TYPES =
%i[text query document audio voice]
MESSAGE_TYPES =
%I[command text query document audio voice]

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Message

Returns a new instance of Message.



8
9
10
11
12
13
14
# File 'lib/te_bot/message.rb', line 8

def initialize(body)
  data = body.dig("message") || body.dig("edited_message") ||
    body.dig("inline_query") || body.dig("chosen_inline_result") ||
    body.dig("chosen_inline_result") || {}

  @message = Format.new(data)
end

Instance Method Details

#callObject



33
34
35
# File 'lib/te_bot/message.rb', line 33

def call
  handler&.call
end

#dataObject



16
17
18
# File 'lib/te_bot/message.rb', line 16

def data
  @message
end

#handlerObject



27
28
29
30
31
# File 'lib/te_bot/message.rb', line 27

def handler
  return unless data || data.content
  content_class = data.content.class.name.split("::").last.downcase
  @formats[content_class]
end