Class: CollavreOpenclaw::CallbacksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/collavre_openclaw/callbacks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/collavre_openclaw/callbacks_controller.rb', line 11

def create
  user = User.find_by(id: params[:user_id])

  unless user
    render json: { error: "User not found" }, status: :not_found
    return
  end

  # Parse payload first
  begin
    payload = JSON.parse(request.raw_post, symbolize_names: true)
  rescue JSON::ParserError
    render json: { error: "Invalid JSON" }, status: :bad_request
    return
  end

  # Authenticate the request via nonce
  auth_result = authenticate_request(user, payload)
  unless auth_result[:success]
    render json: { error: auth_result[:error] }, status: :unauthorized
    return
  end

  # Merge context from pending callback if nonce was used
  if auth_result[:pending_callback]
    payload = merge_pending_callback_context(payload, auth_result[:pending_callback])
  end

  # Process the callback payload
  CallbackProcessorJob.perform_later(user.id, payload.deep_stringify_keys)

  head :ok
end