feat: Integration with Captain (alpha) (#9834)
- Integration with captain (alpha) Co-authored-by: Pranav <pranavrajs@gmail.com>
This commit is contained in:
@@ -10,7 +10,7 @@ class Api::V1::Accounts::Integrations::AppsController < Api::V1::Accounts::BaseC
|
||||
private
|
||||
|
||||
def fetch_apps
|
||||
@apps = Integrations::App.all.select(&:active?)
|
||||
@apps = Integrations::App.all.select { |app| app.active?(Current.account) }
|
||||
end
|
||||
|
||||
def fetch_app
|
||||
|
||||
@@ -9,6 +9,8 @@ class HookJob < ApplicationJob
|
||||
process_slack_integration(hook, event_name, event_data)
|
||||
when 'dialogflow'
|
||||
process_dialogflow_integration(hook, event_name, event_data)
|
||||
when 'captain'
|
||||
process_captain_integration(hook, event_name, event_data)
|
||||
when 'google_translate'
|
||||
google_translate_integration(hook, event_name, event_data)
|
||||
end
|
||||
@@ -35,6 +37,12 @@ class HookJob < ApplicationJob
|
||||
Integrations::Dialogflow::ProcessorService.new(event_name: event_name, hook: hook, event_data: event_data).perform
|
||||
end
|
||||
|
||||
def process_captain_integration(hook, event_name, event_data)
|
||||
return unless ['message.created'].include?(event_name)
|
||||
|
||||
Integrations::Captain::ProcessorService.new(event_name: event_data, hook: hook, event_data: event_data).perform
|
||||
end
|
||||
|
||||
def google_translate_integration(hook, event_name, event_data)
|
||||
return unless ['message.created'].include?(event_name)
|
||||
|
||||
|
||||
@@ -129,7 +129,16 @@ class Inbox < ApplicationRecord
|
||||
end
|
||||
|
||||
def active_bot?
|
||||
agent_bot_inbox&.active? || hooks.where(app_id: 'dialogflow', status: 'enabled').count.positive?
|
||||
agent_bot_inbox&.active? || hooks.where(app_id: %w[dialogflow],
|
||||
status: 'enabled').count.positive? || captain_enabled?
|
||||
end
|
||||
|
||||
def captain_enabled?
|
||||
captain_hook = account.hooks.where(
|
||||
app_id: %w[captain], status: 'enabled'
|
||||
).first
|
||||
|
||||
captain_hook.present? && captain_hook.settings['inbox_ids'].split(',').include?(id.to_s)
|
||||
end
|
||||
|
||||
def inbox_type
|
||||
|
||||
@@ -34,12 +34,14 @@ class Integrations::App
|
||||
end
|
||||
end
|
||||
|
||||
def active?
|
||||
def active?(account)
|
||||
case params[:id]
|
||||
when 'slack'
|
||||
ENV['SLACK_CLIENT_SECRET'].present?
|
||||
when 'linear'
|
||||
Current.account.feature_enabled?('linear_integration')
|
||||
account.feature_enabled?('linear_integration')
|
||||
when 'captain'
|
||||
account.feature_enabled?('captain_integration') && ENV['CAPTAIN_API_URL'].present?
|
||||
else
|
||||
true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user