Class: TelegramChatbot::Notification

Inherits:
Object
  • Object
show all
Defined in:
app/models/telegram_chatbot/notification.rb

Class Method Summary collapse

Class Method Details

.bulk_notify_async(message, groups = []) ⇒ Object



3
4
5
6
7
8
9
# File 'app/models/telegram_chatbot/notification.rb', line 3

def self.bulk_notify_async(message, groups = [])
  return unless bot.present? && bot.actived?

  groups.each do |group|
    notify_async(message, group)
  end
end

.notify(message, group_id = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/telegram_chatbot/notification.rb', line 17

def self.notify(message, group_id = nil)
  return if group_id.nil?

  begin
    group = ::TelegramChatbot::ChatGroup.find(group_id)
    client.send_message(chat_id: group.chat_id, text: message, parse_mode: :HTML) if group.actived?
  rescue ActiveRecord::RecordNotFound => e
    logger.info "Find not found chat_group ID: #{group_id}"
  rescue ::Telegram::Bot::Forbidden => e
    group.update(actived: false, reason: e)
  end
end

.notify_async(message, group = nil) ⇒ Object



11
12
13
14
15
# File 'app/models/telegram_chatbot/notification.rb', line 11

def self.notify_async(message, group = nil)
  return if group.nil? && !group.actived?

  NotificationWorker.perform_async(message, group.id)
end