Class: TelegramChatbot::Notification
- Inherits:
-
Object
- Object
- TelegramChatbot::Notification
- Defined in:
- app/models/telegram_chatbot/notification.rb
Class Method Summary collapse
- .bulk_notify_async(message, groups = []) ⇒ Object
- .notify(message, group_id = nil) ⇒ Object
- .notify_async(message, group = nil) ⇒ Object
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(, groups = []) return unless bot.present? && bot.actived? groups.each do |group| notify_async(, 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(, group_id = nil) return if group_id.nil? begin group = ::TelegramChatbot::ChatGroup.find(group_id) client.(chat_id: group.chat_id, text: , 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(, group = nil) return if group.nil? && !group.actived? NotificationWorker.perform_async(, group.id) end |