12345678910111213141516171819202122232425262728293031323334353637383940 |
- class WebhooksController < ApplicationController
- skip_before_filter :authenticate_user!
- def create
- user = User.find_by_id(params[:user_id])
- if user
- agent = user.agents.find_by_id(params[:agent_id])
- if agent
- response, status = agent.trigger_webhook(params.except(:action, :controller, :agent_id, :user_id))
- if response.is_a?(String)
- render :text => response, :status => status || 200
- elsif response.is_a?(Hash)
- render :json => response, :status => status || 200
- else
- head :ok
- end
- else
- render :text => "agent not found", :status => :not_found
- end
- else
- render :text => "user not found", :status => :not_found
- end
- end
- end
|