Class: TelegramBotEngine::DeliveryJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/telegram_bot_engine/delivery_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(chat_id, text, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/jobs/telegram_bot_engine/delivery_job.rb', line 8

def perform(chat_id, text, options = {})
  Telegram.bot.send_message(
    chat_id: chat_id,
    text: text,
    **options.symbolize_keys
  )

  TelegramBotEngine::Event.log(
    event_type: "delivery", action: "delivered",
    chat_id: chat_id,
    details: { text_preview: text.to_s[0, 100] }
  )
rescue Telegram::Bot::Forbidden
  # User blocked the bot - deactivate subscription
  TelegramBotEngine::Subscription.where(chat_id: chat_id).update_all(active: false)
  Rails.logger.info("[TelegramBotEngine] Deactivated subscription for blocked chat: #{chat_id}")

  TelegramBotEngine::Event.log(
    event_type: "delivery", action: "blocked",
    chat_id: chat_id,
    details: { text_preview: text.to_s[0, 100] }
  )
end