diff --git a/Gemfile b/Gemfile index 1e8605379..53c15b116 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '3.3.3' +ruby '3.2.3' ##-- base gems for rails --## gem 'rack-cors', '2.0.0', require: 'rack/cors' diff --git a/Gemfile.lock b/Gemfile.lock index da19dbb72..0008e13c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -997,7 +997,7 @@ DEPENDENCIES working_hours RUBY VERSION - ruby 3.3.3p89 + ruby 3.2.3p157 BUNDLED WITH 2.5.16 diff --git a/config/integration/apps.yml b/config/integration/apps.yml index 10ba2e056..033e3028c 100644 --- a/config/integration/apps.yml +++ b/config/integration/apps.yml @@ -84,6 +84,7 @@ dialogflow: { 'project_id': { 'type': 'string' }, 'credentials': { 'type': 'object' }, + 'language_code': { 'type': 'string' }, }, 'required': ['project_id', 'credentials'], 'additionalProperties': false, @@ -106,8 +107,71 @@ dialogflow: 'validation-messages': { 'JSON': 'Invalid JSON', 'required': 'Credentials is required' }, }, + { + 'label': 'Dialogflow Language Code', + 'type': 'select', + 'name': 'language_code', + 'options': [ + { 'label': 'Bengali (bn)', 'value': 'bn' }, + { 'label': 'Bengali - Bangladesh (bn-BD)', 'value': 'bn-BD' }, + { 'label': 'Bengali - India (bn-IN)', 'value': 'bn-IN' }, + { 'label': 'Chinese - Cantonese (zh-HK)', 'value': 'zh-HK' }, + { 'label': 'Chinese - Simplified (zh-CN)', 'value': 'zh-CN' }, + { 'label': 'Chinese - Traditional (zh-TW)', 'value': 'zh-TW' }, + { 'label': 'Danish (da)', 'value': 'da' }, + { 'label': 'Dutch (nl)', 'value': 'nl' }, + { 'label': 'English (en)', 'value': 'en' }, + { 'label': 'English - Australia (en-AU)', 'value': 'en-AU' }, + { 'label': 'English - Canada (en-CA)', 'value': 'en-CA' }, + { 'label': 'English - Great Britain (en-GB)', 'value': 'en-GB' }, + { 'label': 'English - India (en-IN)', 'value': 'en-IN' }, + { 'label': 'English - US (en-US)', 'value': 'en-US' }, + { 'label': 'Filipino (fil)', 'value': 'fil' }, + { 'label': 'Filipino - The Philippines (fil-PH)', 'value': 'fil-PH' }, + { 'label': 'Finnish (fi)', 'value': 'fi' }, + { 'label': 'French (fr)', 'value': 'fr' }, + { 'label': 'French - Canada (fr-CA)', 'value': 'fr-CA' }, + { 'label': 'French - France (fr-FR)', 'value': 'fr-FR' }, + { 'label': 'German (de)', 'value': 'de' }, + { 'label': 'Hindi (hi)', 'value': 'hi' }, + { 'label': 'Indonesian (id)', 'value': 'id' }, + { 'label': 'Italian (it)', 'value': 'it' }, + { 'label': 'Japanese (ja)', 'value': 'ja' }, + { 'label': 'Korean (ko)', 'value': 'ko' }, + { 'label': 'Malay (ms)', 'value': 'ms' }, + { 'label': 'Malay - Malaysia (ms-MY)', 'value': 'ms-MY' }, + { 'label': 'Marathi (mr)', 'value': 'mr' }, + { 'label': 'Marathi - India (mr-IN)', 'value': 'mr-IN' }, + { 'label': 'Norwegian (no)', 'value': 'no' }, + { 'label': 'Polish (pl)', 'value': 'pl' }, + { 'label': 'Portuguese - Brazil (pt-BR)', 'value': 'pt-BR' }, + { 'label': 'Portuguese - Portugal (pt-PT)', 'value': 'pt-PT' }, + { 'label': 'Romanian (ro)', 'value': 'ro' }, + { 'label': 'Romanian - Romania (ro-RO)', 'value': 'ro-RO' }, + { 'label': 'Russian (ru)', 'value': 'ru' }, + { 'label': 'Sinhala (si)', 'value': 'si' }, + { 'label': 'Sinhala - Sri Lanka (si-LK)', 'value': 'si-LK' }, + { 'label': 'Spanish (es)', 'value': 'es' }, + { 'label': 'Spanish - Latin America (es-419)', 'value': 'es-419' }, + { 'label': 'Spanish - Spain (es-ES)', 'value': 'es-ES' }, + { 'label': 'Swedish (sv)', 'value': 'sv' }, + { 'label': 'Tamil (ta)', 'value': 'ta' }, + { 'label': 'Tamil - India (ta-IN)', 'value': 'ta-IN' }, + { 'label': 'Tamil - Sri Lanka (ta-LK)', 'value': 'ta-LK' }, + { 'label': 'Tamil - Malaysia (ta-MY)', 'value': 'ta-MY' }, + { 'label': 'Tamil - Singapore (ta-SG)', 'value': 'ta-SG' }, + { 'label': 'Telugu (te)', 'value': 'te' }, + { 'label': 'Telugu - India (te-IN)', 'value': 'te-IN' }, + { 'label': 'Thai (th)', 'value': 'th' }, + { 'label': 'Turkish (tr)', 'value': 'tr' }, + { 'label': 'Ukrainian (uk)', 'value': 'uk' }, + { 'label': 'Vietnamese (vi)', 'value': 'vi' }, + { 'label': 'Vietnamese - Vietnam (vi-VN)', 'value': 'vi-VN' }, + ], + 'value': 'en-US', + }, ] - visible_properties: ['project_id'] + visible_properties: ['project_id', 'language_code'] google_translate: id: google_translate logo: google-translate.png diff --git a/lib/integrations/dialogflow/processor_service.rb b/lib/integrations/dialogflow/processor_service.rb index f3962a66c..d35f7deab 100644 --- a/lib/integrations/dialogflow/processor_service.rb +++ b/lib/integrations/dialogflow/processor_service.rb @@ -71,7 +71,8 @@ class Integrations::Dialogflow::ProcessorService < Integrations::BotProcessorSer def detect_intent(session_id, message) client = ::Google::Cloud::Dialogflow::V2::Sessions::Client.new session = "projects/#{hook.settings['project_id']}/agent/sessions/#{session_id}" - query_input = { text: { text: message, language_code: 'en-US' } } + language_code = hook.settings['language_code'] || 'en-US' + query_input = { text: { text: message, language_code: language_code } } client.detect_intent session: session, query_input: query_input end end diff --git a/spec/lib/integrations/dialogflow/processor_service_spec.rb b/spec/lib/integrations/dialogflow/processor_service_spec.rb index 2b5f36c5a..b3476ba9f 100644 --- a/spec/lib/integrations/dialogflow/processor_service_spec.rb +++ b/spec/lib/integrations/dialogflow/processor_service_spec.rb @@ -153,19 +153,33 @@ describe Integrations::Dialogflow::ProcessorService do let(:google_dialogflow) { Google::Cloud::Dialogflow::V2::Sessions::Client } let(:session_client) { double } let(:session) { double } - let(:query_input) { { text: { text: message, language_code: 'en-US' } } } + let(:language_code) { 'es-419' } let(:processor) { described_class.new(event_name: event_name, hook: hook, event_data: event_data) } before do - hook.update(settings: { 'project_id' => 'test', 'credentials' => 'creds' }) + hook.update(settings: { 'project_id' => 'test', 'credentials' => 'creds', 'language_code' => language_code }) allow(google_dialogflow).to receive(:new).and_return(session_client) + query_input = { text: { text: message, language_code: language_code } } allow(session_client).to receive(:detect_intent).and_return({ session: session, query_input: query_input }) end it 'returns intended response' do response = processor.send(:get_response, conversation.contact_inbox.source_id, message.content) expect(response[:query_input][:text][:text]).to eq(message) - expect(response[:query_input][:text][:language_code]).to eq('en-US') + expect(response[:query_input][:text][:language_code]).to eq(language_code) + end + + context 'when language code is not set on the hook' do + before do + hook.update(settings: { 'project_id' => 'test', 'credentials' => 'creds' }) + allow(session_client).to receive(:detect_intent) + .and_return({ session: session, query_input: { text: { text: message, language_code: 'en-US' } } }) + end + + it 'defaults to en-US' do + response = processor.send(:get_response, conversation.contact_inbox.source_id, message.content) + expect(response[:query_input][:text][:language_code]).to eq('en-US') + end end it 'disables the hook if permission errors are thrown' do