2020-06-12 17:42:47 +00:00
|
|
|
class Api::V1::Accounts::Integrations::SlackController < Api::V1::Accounts::BaseController
|
|
|
|
before_action :fetch_hook, only: [:update, :destroy]
|
|
|
|
|
|
|
|
def create
|
|
|
|
builder = Integrations::Slack::HookBuilder.new(
|
2020-09-12 17:39:55 +00:00
|
|
|
account: Current.account,
|
2020-06-12 17:42:47 +00:00
|
|
|
code: params[:code],
|
|
|
|
inbox_id: params[:inbox_id]
|
|
|
|
)
|
|
|
|
@hook = builder.perform
|
2020-06-22 07:49:26 +00:00
|
|
|
create_chatwoot_slack_channel
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2020-06-22 07:49:26 +00:00
|
|
|
create_chatwoot_slack_channel
|
2020-06-12 17:42:47 +00:00
|
|
|
render json: @hook
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@hook.destroy
|
|
|
|
|
|
|
|
head :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def fetch_hook
|
2020-09-12 17:39:55 +00:00
|
|
|
@hook = Integrations::Hook.where(account: Current.account).find_by(app_id: 'slack')
|
2020-06-22 07:49:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_chatwoot_slack_channel
|
|
|
|
channel = params[:channel] || 'customer-conversations'
|
|
|
|
builder = Integrations::Slack::ChannelBuilder.new(
|
|
|
|
hook: @hook, channel: channel
|
|
|
|
)
|
|
|
|
builder.perform
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|
|
|
|
end
|