Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Add multiple language support - text messages #49

Merged
merged 7 commits into from
Dec 21, 2021
Merged
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
43 changes: 43 additions & 0 deletions config/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ISetting,
ISettingSelectValue,
SettingType,
} from '@rocket.chat/apps-engine/definition/settings';

Expand All @@ -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 {
Expand All @@ -29,6 +31,36 @@ export enum DefaultMessage {
DEFAULT_DialogflowCloseChatMessage = 'Closing the chat, Goodbye',
}

export const LanguageCode: Array<ISettingSelectValue> = [
{ 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 @@ -71,6 +103,17 @@ export const settings: Array<ISetting> = [
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,
Expand Down
31 changes: 30 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 3 additions & 1 deletion lib/Dialogflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
};

Expand Down