Module: Tramway::Bots::Telegram::Custom::Notify::Text

Extended by:
MessagesManager
Defined in:
lib/tramway/bots/telegram/custom/notify/text.rb

Class Method Summary collapse

Methods included from MessagesManager

log_message, message_to_chat, message_to_user, send_file

Class Method Details

.send_to_channel(bot_id, channel_id, message) ⇒ Object



23
24
25
26
27
# File 'lib/tramway/bots/telegram/custom/notify/text.rb', line 23

def send_to_channel(bot_id, channel_id, message)
  bot_record = Tramway::Bots::Bot.find bot_id
  bot = ::Telegram::Bot::Client.new bot_record.token
  message_to_user bot.api, message, channel_id
end

.send_to_chat(bot_id, chat_id, message, **options) ⇒ Object



17
18
19
20
21
# File 'lib/tramway/bots/telegram/custom/notify/text.rb', line 17

def send_to_chat(bot_id, chat_id, message, **options)
  bot_record = Tramway::Bots::Bot.find bot_id
  bot = ::Telegram::Bot::Client.new bot_record.token
  message_to_chat bot.api, chat_id, message, **options
end

.send_to_user(bot_id, username, message) ⇒ Object



10
11
12
13
14
15
# File 'lib/tramway/bots/telegram/custom/notify/text.rb', line 10

def send_to_user(bot_id, username, message)
  bot_record = Tramway::Bots::Bot.find bot_id
  bot = ::Telegram::Bot::Client.new bot_record.token
  chat = Tramway::Bots::Telegram::Chat.where(bot_id: bot_id).find_by "options ->> 'username' = '#{username}'"
  message_to_user bot.api, message, chat.telegram_chat_id if chat.present?
end