Chore: APIs for agent bots (#676)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-04-07 10:41:18 +05:30
committed by GitHub
parent 4feca1d88d
commit 1cfa756d49
14 changed files with 277 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
class Api::V1::Accounts::InboxesController < Api::BaseController
before_action :check_authorization
before_action :fetch_inbox, only: [:destroy, :update]
before_action :fetch_inbox, except: [:index]
before_action :fetch_agent_bot, only: [:set_agent_bot]
def index
@inboxes = policy_scope(current_account.inboxes)
@@ -10,6 +11,17 @@ class Api::V1::Accounts::InboxesController < Api::BaseController
@inbox.update(inbox_update_params)
end
def set_agent_bot
if @agent_bot
agent_bot_inbox = @inbox.agent_bot_inbox || AgentBotInbox.new(inbox: @inbox)
agent_bot_inbox.agent_bot = @agent_bot
agent_bot_inbox.save!
elsif @inbox.agent_bot_inbox.present?
@inbox.agent_bot_inbox.destroy!
end
head :ok
end
def destroy
@inbox.destroy
head :ok
@@ -21,6 +33,10 @@ class Api::V1::Accounts::InboxesController < Api::BaseController
@inbox = current_account.inboxes.find(params[:id])
end
def fetch_agent_bot
@agent_bot = AgentBot.find(params[:agent_bot]) if params[:agent_bot]
end
def check_authorization
authorize(Inbox)
end

View File

@@ -0,0 +1,8 @@
class Api::V1::AgentBotsController < Api::BaseController
skip_before_action :authenticate_user!
skip_before_action :check_subscription
def index
render json: AgentBot.all
end
end