Class: SpreeCmCommissioner::TelegramAlerts::IntegrationSyncFailure

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/telegram_alerts/integration_sync_failure.rb

Instance Method Summary collapse

Instance Method Details

#call(error_message:, data: {}) ⇒ Object

Send Telegram alert for integration sync failure

Parameters:

  • error_message (String)

    The error message

  • data (Hash) (defaults to: {})

    Additional context data (e.g., sync_type, match_id, event_type)



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/spree_cm_commissioner/telegram_alerts/integration_sync_failure.rb', line 9

def call(error_message:, data: {})
  chat_id = ENV.fetch('EXCEPTION_NOTIFIER_TELEGRAM_CHANNEL_ID', nil)
  return failure(nil, 'Telegram chat ID not configured') if chat_id.blank?

  telegram_client = ::Telegram.bots[:exception_notifier]
  return failure(nil, 'Telegram bot not configured') if telegram_client.blank?

  telegram_client.send_message(
    chat_id: chat_id,
    parse_mode: 'HTML',
    text: format_message(error_message, data)
  )

  success(message: 'Alert sent successfully')
rescue StandardError => e
  failure(nil, "Failed to send Telegram alert: #{e.message}")
end