diff --git a/config/Settings.ts b/config/Settings.ts index ad361b5..9e8fda8 100644 --- a/config/Settings.ts +++ b/config/Settings.ts @@ -1,5 +1,6 @@ import { ISetting, + ISettingSelectValue, SettingType, } from '@rocket.chat/apps-engine/definition/settings'; @@ -16,6 +17,7 @@ export enum AppSetting { DialogflowHandoverFailedMessage = 'dialogflow_no_agents_online_for_handover', DialogflowCloseChatMessage = 'dialogflow_close_chat_message', DialogflowHideQuickReplies = 'dialogflow_hide_quick_replies', + DialogflowDefaultLanguage = 'dialogflow_default_language', } export enum ServerSetting { @@ -29,6 +31,36 @@ export enum DefaultMessage { DEFAULT_DialogflowCloseChatMessage = 'Closing the chat, Goodbye', } +export const LanguageCode: Array = [ + { key: 'zh-CN', i18nLabel: 'Chinese - Simplified' }, + { key: 'da', i18nLabel: 'Danish' }, + { key: 'nl', i18nLabel: 'Dutch' }, + { key: 'en', i18nLabel: 'English' }, + { key: 'en-AU', i18nLabel: 'English - Australia' }, + { key: 'en-CA', i18nLabel: 'English - Canada' }, + { key: 'en-GB', i18nLabel: 'English - Great Britain' }, + { key: 'en-IN', i18nLabel: 'English - India' }, + { key: 'en-US', i18nLabel: 'English - US' }, + { key: 'fr-CA', i18nLabel: 'French - Canada' }, + { key: 'fr-FR', i18nLabel: 'French - France' }, + { key: 'de', i18nLabel: 'German' }, + { key: 'hi', i18nLabel: 'Hindi' }, + { key: 'id', i18nLabel: 'Indonesian' }, + { key: 'it', i18nLabel: 'Italian' }, + { key: 'ja', i18nLabel: 'Japanese' }, + { key: 'ko', i18nLabel: 'Korean' }, + { key: 'no', i18nLabel: 'Norwegian' }, + { key: 'pl', i18nLabel: 'Polish' }, + { key: 'pt-BR', i18nLabel: 'Portuguese - Brazil' }, + { key: 'pt', i18nLabel: 'Portuguese - Portugal' }, + { key: 'ru', i18nLabel: 'Russian' }, + { key: 'es', i18nLabel: 'Spanish' }, + { key: 'es-ES', i18nLabel: 'Spanish - Spain' }, + { key: 'sv', i18nLabel: 'Swedish' }, + { key: 'tr', i18nLabel: 'Turkish' }, + { key: 'uk', i18nLabel: 'Ukrainian' }, +]; + export const settings: Array = [ { id: AppSetting.DialogflowBotUsername, @@ -71,6 +103,17 @@ export const settings: Array = [ i18nLabel: 'dialogflow_private_key', required: true, }, + { + id: AppSetting.DialogflowDefaultLanguage, + public: true, + type: SettingType.SELECT, + values: LanguageCode, + packageValue: 'en', + value: 'en', + i18nLabel: 'dialogflow_default_language', + i18nDescription: 'dialogflow_default_language_description', + required: false, + }, { id: AppSetting.DialogflowFallbackResponsesLimit, public: true, diff --git a/i18n/en.json b/i18n/en.json index beddb9f..2265646 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -18,5 +18,34 @@ "dialogflow_hide_quick_replies": "Hide Quick Replies", "dialogflow_hide_quick_replies_description": "If enabled, then all quick-replies will hide when a visitor clicks on any one of them", "dialogflow_handover_failed_message": "Handover Failed Message", - "dialogflow_handover_failed_message_description": "The Bot will send this message to Visitor if the handover failed because no agents were online" + "dialogflow_handover_failed_message_description": "The Bot will send this message to Visitor if the handover failed because no agents were online", + "dialogflow_default_language": "Language", + "dialogflow_default_language_description": "Define the language in which you'd be interacting with the Bot", + "dialogflow_chinese_simplified": "Chinese - Simplified", + "dialogflow_danish": "Danish", + "dialogflow_dutch": "Dutch", + "dialogflow_english": "English", + "dialogflow_english_australia": "English - Australia", + "dialogflow_english_canada": "English - Canada", + "dialogflow_english_great_britain": "English - Great Britain", + "dialogflow_english_india": "English - India", + "dialogflow_english_us": "English - US", + "dialogflow_french_canada": "French - Canada", + "dialogflow_french_france": "French - France", + "dialogflow_german": "German", + "dialogflow_hindi": "Hindi", + "dialogflow_indonesian": "Indonesian", + "dialogflow_italian": "Italian", + "dialogflow_japanese": "Japanese", + "dialogflow_korean": "Korean", + "dialogflow_norwegian": "Norwegian", + "dialogflow_polish": "Polish", + "dialogflow_portuguese-brazil": "Portuguese - Brazil", + "dialogflow_portuguese-portugal": "Portuguese - Portugal", + "dialogflow_russian": "Russian", + "dialogflow_spanish": "Spanish", + "dialogflow_spanish-spain": "Spanish - Spain", + "dialogflow_swedish": "Swedish", + "dialogflow_turkish": "Turkish", + "dialogflow_ukrainian": "Ukrainian" } diff --git a/lib/Dialogflow.ts b/lib/Dialogflow.ts index 4dabbd2..5ed89ba 100644 --- a/lib/Dialogflow.ts +++ b/lib/Dialogflow.ts @@ -42,12 +42,14 @@ class DialogflowClass { sessionId, ); + const languageCode = await getAppSettingValue(read, AppSetting.DialogflowDefaultLanguage) || LanguageCode.EN; + const queryInput = { ...requestType === DialogflowRequestType.EVENT && { event: request, }, ...requestType === DialogflowRequestType.MESSAGE && { - text: { languageCode: LanguageCode.EN, text: request }, + text: { languageCode, text: request }, }, };