Module: FlowChat::Whatsapp::SendJobSupport

Extended by:
ActiveSupport::Concern
Defined in:
lib/flow_chat/whatsapp/send_job_support.rb

Overview

Module to be included in background jobs for WhatsApp response delivery Only handles sending responses, not processing flows

Instance Method Summary collapse

Instance Method Details

#perform_whatsapp_send(send_data) ⇒ Object

Main job execution method for sending responses



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flow_chat/whatsapp/send_job_support.rb', line 15

def perform_whatsapp_send(send_data)
  config = resolve_whatsapp_config(send_data)
  client = FlowChat::Whatsapp::Client.new(config)

  result = client.send_message(send_data[:msisdn], send_data[:response])

  if result
    Rails.logger.info "WhatsApp message sent successfully: #{result["messages"]&.first&.dig("id")}"
    on_whatsapp_send_success(send_data, result)
  else
    Rails.logger.error "Failed to send WhatsApp message to #{send_data[:msisdn]}"
    raise "WhatsApp API call failed"
  end
rescue => e
  on_whatsapp_send_error(e, send_data)
  handle_whatsapp_send_error(e, send_data, config)
end