diff --git a/config/Settings.ts b/config/Settings.ts index 0ae76fd..4619d3d 100644 --- a/config/Settings.ts +++ b/config/Settings.ts @@ -12,6 +12,7 @@ export enum AppSetting { DialogflowServiceUnavailableMessage = 'dialogflow_service_unavailable_message', DialogflowCloseChatMessage = 'dialogflow_close_chat_message', DialogflowHideQuickReplies = 'dialogflow_hide_quick_replies', + DialogflowLanguage = 'dialogflow_language', } export enum DefaultMessage { @@ -21,6 +22,36 @@ export enum DefaultMessage { DEFAULT_UnsupportedAudioFormatMessage = 'Sorry! Only *.wav, *.opus and *.oga extension files are supported as audio input', } +export const LanguageCode = [ + { 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, @@ -83,6 +114,16 @@ export const settings: Array = [ i18nDescription: 'show_only_text_messages_description', required: true, }, + { + id: AppSetting.DialogflowLanguage, + public: true, + type: SettingType.SELECT, + values: LanguageCode, + packageValue: 'en', + value: 'en', + i18nLabel: 'dialogflow_language', + required: true, + }, { id: AppSetting.DialogflowHandoverMessage, public: true, diff --git a/i18n/en.json b/i18n/en.json index fad1ee5..e2e6c4c 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -16,5 +16,33 @@ "show_only_text_messages": "Show only Text Messages", "show_only_text_messages_description": "If this Setting is Enabled, then the bot will always reply back with a text message, even when a visitor sends a audio message.", "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_hide_quick_replies_description": "If enabled, then all quick-replies will hide when a visitor clicks on any one of them", + "dialogflow_language": "Language", + "chinese_simplified": "Chinese - Simplified", + "danish": "Danish", + "dutch": "Dutch", + "english": "English", + "english_australia": "English - Australia", + "english_canada": "English - Canada", + "english_great_britain": "English - Great Britain", + "english_india": "English - India", + "english_us": "English - US", + "french_canada": "French - Canada", + "french_france": "French - France", + "german": "German", + "hindi": "Hindi", + "indonesian": "Indonesian", + "italian": "Italian", + "japanese": "Japanese", + "korean": "Korean", + "norwegian": "Norwegian", + "polish": "Polish", + "portuguese-brazil": "Portuguese - Brazil", + "portuguese-portugal": "Portuguese - Portugal", + "russian": "Russian", + "spanish": "Spanish", + "spanish-spain": "Spanish - Spain", + "swedish": "Swedish", + "turkish": "Turkish", + "ukrainian": "Ukrainian" } diff --git a/lib/Dialogflow.ts b/lib/Dialogflow.ts index b6ff97c..62b72ef 100644 --- a/lib/Dialogflow.ts +++ b/lib/Dialogflow.ts @@ -20,12 +20,14 @@ class DialogflowClass { requestType: DialogflowRequestType): Promise { const serverURL = await this.getServerURL(read, modify, http, sessionId); + const languageCode = await getAppSettingValue(read, AppSetting.DialogflowLanguage); + const queryInput = { ...requestType === DialogflowRequestType.EVENT && { event: request }, - ...requestType === DialogflowRequestType.MESSAGE && { text: { languageCode: LanguageCode.EN, text: request } }, - ...requestType === DialogflowRequestType.AUDIO && { audioConfig: { languageCode: AudioLanguageCode.EN_US } }, + ...requestType === DialogflowRequestType.MESSAGE && { text: { languageCode, text: request } }, + ...requestType === DialogflowRequestType.AUDIO && { audioConfig: { languageCode } }, ...requestType === DialogflowRequestType.AUDIO_OGG && - { audioConfig: { audioEncoding: DialogflowInputAudioEncoding.ENCODING_OGG, sampleRateHertz: 16000, languageCode: AudioLanguageCode.EN_US } }, + { audioConfig: { audioEncoding: DialogflowInputAudioEncoding.ENCODING_OGG, sampleRateHertz: 16000, languageCode } }, }; const { value: onlyTextMessage } = await read.getEnvironmentReader().getSettings().getById(AppSetting.DialogflowShowOnlyTextMessages);