diff --git a/.env.example b/.env.example index 81228f00a..b7ba0920d 100644 --- a/.env.example +++ b/.env.example @@ -258,4 +258,3 @@ AZURE_APP_SECRET= # contact_inboxes with no conversation older than 90 days will be removed # REMOVE_STALE_CONTACT_INBOX_JOB_STATUS=false -# CAPTAIN_API_URL=http://localhost:3001/api diff --git a/app/controllers/api/v1/accounts/integrations/captain_controller.rb b/app/controllers/api/v1/accounts/integrations/captain_controller.rb new file mode 100644 index 000000000..88547209c --- /dev/null +++ b/app/controllers/api/v1/accounts/integrations/captain_controller.rb @@ -0,0 +1,20 @@ +class Api::V1::Accounts::Integrations::CaptainController < Api::V1::Accounts::BaseController + before_action :check_admin_authorization? + before_action :fetch_hook + + def sso_url + params_string = + "token=#{URI.encode_www_form_component(@hook['settings']['access_token'])}" \ + "&email=#{URI.encode_www_form_component(@hook['settings']['account_email'])}" \ + "&account_id=#{URI.encode_www_form_component(@hook['settings']['account_id'])}" + + sso_url = "#{ENV.fetch('CAPTAIN_APP_URL', '')}/sso?#{params_string}" + render json: { sso_url: sso_url }, status: :ok + end + + private + + def fetch_hook + @hook = Current.account.hooks.find_by!(app_id: 'captain') + end +end diff --git a/app/javascript/dashboard/api/integrations.js b/app/javascript/dashboard/api/integrations.js index 2b816e603..975857ce1 100644 --- a/app/javascript/dashboard/api/integrations.js +++ b/app/javascript/dashboard/api/integrations.js @@ -32,6 +32,10 @@ class IntegrationsAPI extends ApiClient { deleteHook(hookId) { return axios.delete(`${this.baseUrl()}/integrations/hooks/${hookId}`); } + + fetchCaptainURL() { + return axios.get(`${this.baseUrl()}/integrations/captain/sso_url`); + } } export default new IntegrationsAPI(); diff --git a/app/javascript/dashboard/components/layout/config/sidebarItems/primaryMenu.js b/app/javascript/dashboard/components/layout/config/sidebarItems/primaryMenu.js index 92b8765c6..f019933e0 100644 --- a/app/javascript/dashboard/components/layout/config/sidebarItems/primaryMenu.js +++ b/app/javascript/dashboard/components/layout/config/sidebarItems/primaryMenu.js @@ -17,6 +17,14 @@ const primaryMenuItems = accountId => [ toState: frontendURL(`accounts/${accountId}/dashboard`), toStateName: 'home', }, + { + icon: 'captain', + key: 'captain', + label: 'CAPTAIN', + featureFlag: FEATURE_FLAGS.CAPTAIN, + toState: frontendURL(`accounts/${accountId}/captain`), + toStateName: 'captain', + }, { icon: 'book-contacts', key: 'contacts', diff --git a/app/javascript/dashboard/featureFlags.js b/app/javascript/dashboard/featureFlags.js index 11d6c43de..54b560ed7 100644 --- a/app/javascript/dashboard/featureFlags.js +++ b/app/javascript/dashboard/featureFlags.js @@ -31,4 +31,5 @@ export const FEATURE_FLAGS = { INBOUND_EMAILS: 'inbound_emails', IP_LOOKUP: 'ip_lookup', LINEAR: 'linear_integration', + CAPTAIN: 'captain_integration', }; diff --git a/app/javascript/dashboard/i18n/locale/en/integrations.json b/app/javascript/dashboard/i18n/locale/en/integrations.json index 80742f881..47349d1b1 100644 --- a/app/javascript/dashboard/i18n/locale/en/integrations.json +++ b/app/javascript/dashboard/i18n/locale/en/integrations.json @@ -4,6 +4,12 @@ "DESCRIPTION": "Chatwoot integrates with multiple tools and services to improve your team's efficiency. Explore the list below to configure your favorite apps.", "LEARN_MORE": "Learn more about integrations", "LOADING": "Fetching integrations", + "CAPTAIN": { + "DISABLED": "Captain is not enabled on your account.", + "CLICK_HERE_TO_CONFIGURE": "Click here to configure", + "LOADING_CONSOLE": "Loading Captain Console...", + "FAILED_TO_LOAD_CONSOLE": "Failed to load Captain Console. Please refresh and try again." + }, "WEBHOOK": { "SUBSCRIBED_EVENTS": "Subscribed Events", "FORM": { diff --git a/app/javascript/dashboard/i18n/locale/en/settings.json b/app/javascript/dashboard/i18n/locale/en/settings.json index 445b7244e..dabbff89f 100644 --- a/app/javascript/dashboard/i18n/locale/en/settings.json +++ b/app/javascript/dashboard/i18n/locale/en/settings.json @@ -145,7 +145,11 @@ }, "AVAILABILITY": { "LABEL": "Availability", - "STATUSES_LIST": ["Online", "Busy", "Offline"], + "STATUSES_LIST": [ + "Online", + "Busy", + "Offline" + ], "SET_AVAILABILITY_SUCCESS": "Availability has been set successfully", "SET_AVAILABILITY_ERROR": "Couldn't set availability, please try again" }, @@ -235,6 +239,7 @@ "REPORTS": "Reports", "SETTINGS": "Settings", "CONTACTS": "Contacts", + "CAPTAIN": "Captain", "HOME": "Home", "AGENTS": "Agents", "AGENT_BOTS": "Bots", diff --git a/app/javascript/dashboard/routes/dashboard/Captain.vue b/app/javascript/dashboard/routes/dashboard/Captain.vue new file mode 100644 index 000000000..24ba89272 --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/Captain.vue @@ -0,0 +1,75 @@ + + +