Class: Abot::Info::TelegramSender

Inherits:
Object
  • Object
show all
Defined in:
lib/abot/info/telegram_sender.rb

Constant Summary collapse

SENDED_LOST_COINS =
{}
SENDED_ERROR =
{}
SENDED_SELL_ERROR =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTelegramSender

Returns a new instance of TelegramSender.



11
12
13
14
# File 'lib/abot/info/telegram_sender.rb', line 11

def initialize
  @chat_id = DatabaseTable::TG_NAME
  @token = DatabaseTable::TG_TOKEN
end

Instance Attribute Details

#chat_idObject (readonly)

Returns the value of attribute chat_id.



6
7
8
# File 'lib/abot/info/telegram_sender.rb', line 6

def chat_id
  @chat_id
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/abot/info/telegram_sender.rb', line 6

def token
  @token
end

Instance Method Details

#send_lost_coins(coins_without_order) ⇒ Object



25
26
27
28
29
# File 'lib/abot/info/telegram_sender.rb', line 25

def send_lost_coins(coins_without_order)
  coins_without_order.each do |coin|
    send_message("WARNING обнаружена монета без ордера: #{coin}") if SENDED_LOST_COINS[coin].to_i == 3
  end
end

#send_message(text) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/abot/info/telegram_sender.rb', line 16

def send_message(text)
  Telegram::Bot::Client.run(token) do |bot|
    message = bot.api.send_message(chat_id: chat_id, text: text)
    if message['ok'] == true
      bot.api.pin_chat_message(chat_id: chat_id, message_id: message.dig('result', 'message_id'))
    end
  end
end