Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions config/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<ISetting> = [
{
id: AppSetting.DialogflowBotUsername,
Expand Down Expand Up @@ -83,6 +114,16 @@ export const settings: Array<ISetting> = [
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,
Expand Down
30 changes: 29 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
8 changes: 5 additions & 3 deletions lib/Dialogflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class DialogflowClass {
requestType: DialogflowRequestType): Promise<IDialogflowMessage> {
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);
Expand Down