Class: CollavreOpenclaw::CallbackProcessorJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/collavre_openclaw/callback_processor_job.rb

Constant Summary collapse

DEDUP_WINDOW =
5.seconds

Instance Method Summary collapse

Instance Method Details

#perform(user_id, payload) ⇒ Object



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

def perform(user_id, payload)
  @user = User.find_by(id: user_id)
  return unless @user

  # Symbolize keys for consistent access
  payload = payload.deep_symbolize_keys

  Rails.logger.info("[CollavreOpenclaw] Processing callback for user #{user_id}, type: #{payload[:type]}")

  case payload[:type]&.to_s
  when "response"
    handle_response(payload)
  when "proactive"
    handle_proactive(payload)
  when "error"
    handle_error(payload)
  else
    # Default: try to handle as response for backward compatibility
    if payload[:content].present? || payload[:message].present?
      handle_response(payload)
    else
      Rails.logger.warn("[CollavreOpenclaw] Unknown callback type: #{payload[:type]}")
    end
  end
end