Class: MaxBotApi::Resources::Debugs

Inherits:
Object
  • Object
show all
Defined in:
lib/max_bot_api/resources/debugs.rb

Overview

Debug helper for sending raw updates/errors to a chat.

Instance Method Summary collapse

Constructor Details

#initialize(client, chat_id: 0) ⇒ Debugs

Returns a new instance of Debugs.



7
8
9
10
# File 'lib/max_bot_api/resources/debugs.rb', line 7

def initialize(client, chat_id: 0)
  @client = client
  @chat_id = chat_id
end

Instance Method Details

#send(update) ⇒ Object

Send raw update debug text to the configured chat.

Parameters:

  • update (Hash)


14
15
16
17
18
19
20
21
# File 'lib/max_bot_api/resources/debugs.rb', line 14

def send(update)
  message = Builders::MessageBuilder.new
                                    .set_chat(@chat_id)
                                    .set_text(update[:debug_raw].to_s)

  @client.request(:post, 'messages', query: { 'chat_id' => @chat_id }, body: message.to_h)
  true
end

#send_err(error) ⇒ Object

Send an error message to the configured chat.

Parameters:

  • error (Exception, String)


25
26
27
28
29
30
31
32
# File 'lib/max_bot_api/resources/debugs.rb', line 25

def send_err(error)
  message = Builders::MessageBuilder.new
                                    .set_chat(@chat_id)
                                    .set_text(error.to_s)

  @client.request(:post, 'messages', query: { 'chat_id' => @chat_id }, body: message.to_h)
  true
end