Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬
Ruby actioncablechat-widgetconversationcustomer-supportdashboarddesigndockerdocker-imageherokuintercomjavascriptlivechatopensourcerailsrubysassvuejswhatsappzendesk
fix(voice): collect account auth tokens before security rollout (#16244)
Muhsin Kelotha0dfab92823f
diff --git a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.jsonindex c1dcd7746ac..1111f66abe9 100644--- a/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json+++ b/app/javascript/dashboard/i18n/locale/en/inboxMgmt.json@@ -775,7 +775,7 @@"DESCRIPTION": "Enable voice calling on this inbox. Agents will be able to make and receive phone calls."},"CREDENTIALS": {- "DESCRIPTION": "Voice calling requires Twilio API Key credentials. These are used to generate tokens for agent voice connections."+ "DESCRIPTION": "Voice calling requires an Account Auth Token for webhook verification and API key credentials for calls."},"INBOUND": {"LABEL": "Allow incoming calls",diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/settingsPage/VoiceConfigurationPage.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/settingsPage/VoiceConfigurationPage.vueindex 136b91c7627..818c6416a7a 100644--- a/app/javascript/dashboard/routes/dashboard/settings/inbox/settingsPage/VoiceConfigurationPage.vue+++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/settingsPage/VoiceConfigurationPage.vue@@ -29,14 +29,12 @@ export default {inboundCallsEnabled: this.inbox.inbound_calls_enabled !== false,apiKeySid: this.inbox.api_key_sid || '',apiKeySecret: '',+ authToken: '',isUpdating: false,isTogglingInbound: false,};},computed: {- isVoiceConfigured() {- return !!this.inbox.voice_configured;- },hasApiKeySid() {return !!this.inbox.api_key_sid;},@@ -44,10 +42,13 @@ export default {return this.hasApiKeySid && !!this.inbox.has_api_key_secret;},needsCredentials() {+ return this.voiceEnabled && !this.hasExistingCredentials;+ },+ needsAccountAuthToken() {return (this.voiceEnabled &&- !this.isVoiceConfigured &&- !this.hasExistingCredentials+ this.hasApiKeySid &&+ !this.inbox.account_auth_token_configured);},needsApiKeySid() {@@ -55,6 +56,7 @@ export default {},isSubmitDisabled() {if (!this.voiceEnabled) return false;+ if (this.needsAccountAuthToken && !this.authToken) return true;if (this.needsCredentials) {if (this.needsApiKeySid && !this.apiKeySid) return true;return !this.apiKeySecret;@@ -90,14 +92,13 @@ export default {this.isTogglingInbound = false;}},- // Saves on toggle, except when enabling still needs API key credentials: then we- // reveal the inputs and wait for the user to submit them.+ // SMS upgrades collect the account token separately from API key credentials.async handleVoiceToggle(newValue) {if (this.isUpdating) return;const previousValue = this.voiceEnabled;this.voiceEnabled = newValue;- if (this.needsCredentials) return;+ if (this.needsAccountAuthToken || this.needsCredentials) return;try {await this.updateVoiceSettings();@@ -109,13 +110,16 @@ export default {try {await this.updateVoiceSettings();} catch (_) {- this.voiceEnabled = false;+ this.voiceEnabled = this.inbox.voice_enabled || false;}},async updateVoiceSettings() {this.isUpdating = true;try {const channelPayload = { voice_enabled: this.voiceEnabled };+ if (this.needsAccountAuthToken) {+ channelPayload.auth_token = this.authToken;+ }if (this.needsCredentials) {if (this.needsApiKeySid) {@@ -130,6 +134,7 @@ export default {channel: channelPayload,});this.apiKeySecret = '';+ this.authToken = '';useAlert(this.$t('INBOX_MGMT.EDIT.API.SUCCESS_MESSAGE'));} catch (error) {useAlert(this.$t('INBOX_MGMT.EDIT.API.ERROR_MESSAGE'));@@ -163,7 +168,10 @@ export default {</SettingsToggleSection></div>- <div v-if="voiceEnabled && needsCredentials" class="flex flex-col gap-4">+ <div+ v-if="needsAccountAuthToken || needsCredentials"+ class="flex flex-col gap-4"+ ><p class="text-sm text-n-slate-11">{{ $t('INBOX_MGMT.VOICE_CONFIGURATION.CREDENTIALS.DESCRIPTION') }}</p>@@ -174,6 +182,14 @@ export default {:placeholder="$t('INBOX_MGMT.ADD.VOICE.TWILIO.API_KEY_SID.PLACEHOLDER')"/><NextInput+ v-if="needsAccountAuthToken"+ v-model="authToken"+ type="password"+ :label="$t('INBOX_MGMT.ADD.VOICE.TWILIO.AUTH_TOKEN.LABEL')"+ :placeholder="$t('INBOX_MGMT.ADD.VOICE.TWILIO.AUTH_TOKEN.PLACEHOLDER')"+ />+ <NextInput+ v-if="needsCredentials"v-model="apiKeySecret"type="password":label="$t('INBOX_MGMT.ADD.VOICE.TWILIO.API_KEY_SECRET.LABEL')"@@ -224,7 +240,7 @@ export default {</SettingsFieldSection></div>- <div v-if="needsCredentials">+ <div v-if="needsAccountAuthToken || needsCredentials"><NextButton:disabled="isSubmitDisabled":is-loading="isUpdating"diff --git a/app/views/api/v1/models/_inbox.json.jbuilder b/app/views/api/v1/models/_inbox.json.jbuilderindex 5622b2a351e..f7db925f1f6 100644--- a/app/views/api/v1/models/_inbox.json.jbuilder+++ b/app/views/api/v1/models/_inbox.json.jbuilder@@ -163,6 +163,7 @@ if resource.twilio? && resource.channel.respond_to?(:voice_enabled?)json.inbound_calls_enabled resource.channel.inbound_calls_enabled?json.recording_enabled resource.channel.try(:recording_enabled?)json.transcription_enabled resource.channel.try(:transcription_enabled?)+ json.account_auth_token_configured resource.channel.try(:account_auth_token_configured?) == truejson.voice_configured resource.channel.try(:twiml_app_sid).present?json.has_api_key_secret resource.channel.try(:api_key_secret).present?if resource.channel.try(:twiml_app_sid).present?diff --git a/enterprise/app/controllers/concerns/twilio_voice_credentials.rb b/enterprise/app/controllers/concerns/twilio_voice_credentials.rbnew file mode 100644index 00000000000..963fd46a739--- /dev/null+++ b/enterprise/app/controllers/concerns/twilio_voice_credentials.rb@@ -0,0 +1,16 @@+module Concerns::TwilioVoiceCredentials+ private++ def reauthorize_and_update_channel(channel_attributes)+ channel = @inbox.channel+ attributes = permitted_params(channel_attributes)[:channel]+ if channel.is_a?(Channel::TwilioSms) && attributes[:voice_enabled] == true+ attributes.require(:auth_token) if channel.api_key_sid.present? && !channel.account_auth_token_configured?+ attributes.require(:api_key_sid) if channel.api_key_sid.blank?+ attributes.require(:api_key_secret) if channel.api_key_secret.blank?+ channel.provider_config = channel.provider_config.merge('account_auth_token_configured' => true)+ end++ super+ end+enddiff --git a/enterprise/app/controllers/enterprise/api/v1/accounts/inboxes_controller.rb b/enterprise/app/controllers/enterprise/api/v1/accounts/inboxes_controller.rbindex 1e8c747695c..4a769fbd419 100644--- a/enterprise/app/controllers/enterprise/api/v1/accounts/inboxes_controller.rb+++ b/enterprise/app/controllers/enterprise/api/v1/accounts/inboxes_controller.rb@@ -1,5 +1,6 @@module Enterprise::Api::V1::Accounts::InboxesControllerextend ActiveSupport::Concern+ include Concerns::TwilioVoiceCredentialsdef inbox_attributessuper + ee_inbox_attributes@@ -123,6 +124,7 @@ module Enterprise::Api::V1::Accounts::InboxesControllerapi_key_sid: config[:api_key_sid],api_key_secret: config[:api_key_secret],medium: :sms,+ provider_config: { 'account_auth_token_configured' => true },voice_enabled: true)diff --git a/enterprise/app/models/enterprise/channel/twilio_sms.rb b/enterprise/app/models/enterprise/channel/twilio_sms.rbindex c3f5580d145..2e440200f17 100644--- a/enterprise/app/models/enterprise/channel/twilio_sms.rb+++ b/enterprise/app/models/enterprise/channel/twilio_sms.rb@@ -13,6 +13,10 @@ module Enterprise::Channel::TwilioSmsendend+ def account_auth_token_configured?+ provider_config['account_auth_token_configured'] == true+ end+def initiate_call(to:, conference_sid: nil, agent_id: nil)Voice::Provider::Twilio::Adapter.new(self).initiate_call(to: to,