From acf5e9711eaf01fb30da55881c1beac0d9ad8283 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 2 Feb 2021 15:39:18 -0300 Subject: [PATCH 1/4] Fix multiProviderAuthDialog localization --- .../authentication/authenticationResponses.ts | 2 + .../authentication/multiProviderAuthDialog.ts | 54 +++++++++++++------ .../resources/AuthenticationResponses.de.json | 18 +++++++ .../resources/AuthenticationResponses.es.json | 18 +++++++ .../resources/AuthenticationResponses.fr.json | 18 +++++++ .../resources/AuthenticationResponses.it.json | 18 +++++++ .../resources/AuthenticationResponses.json | 18 +++++++ .../resources/AuthenticationResponses.zh.json | 18 +++++++ .../src/responses/responseManager.ts | 14 +++++ 9 files changed, 162 insertions(+), 16 deletions(-) diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts b/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts index 7fd772428..0d500c16f 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts @@ -16,4 +16,6 @@ export class AuthenticationResponses implements IResponseIdCollection { public static readonly configuredAuthProvidersPrompt: string = 'ConfiguredAuthProvidersPrompt'; public static readonly errorMessageAuthFailure: string = 'ErrorMessageAuthFailure'; public static readonly noLinkedAccount: string = 'NoLinkedAccount'; + public static readonly loginButton : string = 'LoginButton'; + public static readonly loginPrompt : string = 'LoginPrompt'; } diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts b/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts index e76188cfe..cfffe5384 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts @@ -28,6 +28,7 @@ enum DialogIds { * Provides the ability to prompt for which Authentication provider the user wishes to use. */ export class MultiProviderAuthDialog extends ComponentDialog { + private static readonly acceptedLocales: string[] = ["en", "de", "es", "fr", "it", "zh"]; private selectedAuthType: string = ''; private authenticationConnections: IOAuthConnection[]; private responseManager: ResponseManager; @@ -42,7 +43,7 @@ export class MultiProviderAuthDialog extends ComponentDialog { this.authenticationConnections = authenticationConnections; this.responseManager = new ResponseManager( - ['en', 'de', 'es', 'fr', 'it', 'zh'], + MultiProviderAuthDialog.acceptedLocales, [AuthenticationResponses] ); @@ -65,29 +66,50 @@ export class MultiProviderAuthDialog extends ComponentDialog { for (var i = 0; i < this.authenticationConnections.length; ++i) { let connection = this.authenticationConnections[i]; - // We ignore placeholder connections in config that don't have a Name - if (connection.name !== undefined && connection.name.trim().length > 0) { - const settings: OAuthPromptSettings = promptSettings[i] || { - connectionName: connection.name, - title: i18next.t('common:login'), - text: i18next.t('common:loginDescription', connection.name) - }; + MultiProviderAuthDialog.acceptedLocales.forEach(locale => { + this.addDialog(this.getLocalizedDialog(locale, connection.name, promptSettings[i])); + }); - this.addDialog(new OAuthPrompt( - connection.name, - settings, - this.authPromptValidator.bind(this) - )); - } + // // We ignore placeholder connections in config that don't have a Name + // if (connection.name !== undefined && connection.name.trim().length > 0) { + // const settings: OAuthPromptSettings = promptSettings[i] || { + // connectionName: connection.name, + // title: i18next.t('common:login'), + // text: i18next.t('common:loginDescription', connection.name) + // }; + + // this.addDialog(new OAuthPrompt( + // connection.name, + // settings, + // this.authPromptValidator.bind(this) + // )); + // } }; - this.addDialog(new WaterfallDialog(DialogIds.firstStepPrompt, authSteps)); + this.addDialog(new WaterfallDialog(DialogIds.authPrompt, authSteps)); this.addDialog(new ChoicePrompt(DialogIds.providerPrompt)); } else { throw new Error('There is no authenticationConnections value'); } } + private getLocalizedDialog(locale: string, connectionName: string, settings: OAuthPromptSettings) { + const loginButtonActivity: string = this.responseManager.getLocalizedResponse(AuthenticationResponses.loginButton, locale).text; + const loginPromptActivity : string = this.responseManager.getLocalizedResponse(AuthenticationResponses.loginPrompt, locale, new Map([["authType", connectionName]])).text; + + settings = settings || { + connectionName: connectionName, + title: loginButtonActivity, + text: loginPromptActivity + }; + + return new OAuthPrompt( + connectionName + '_' + locale, + settings, + this.authPromptValidator.bind(this) + ); + } + // Validators protected async tokenResponseValidator(promptContext: PromptValidatorContext): Promise { const activity: Activity | undefined = promptContext.recognized.value; @@ -107,7 +129,7 @@ export class MultiProviderAuthDialog extends ComponentDialog { private async promptForProvider(stepContext: WaterfallStepContext): Promise { if (this.authenticationConnections.length === 1) { - const result: string = this.authenticationConnections[0].name; + const result: string = this.authenticationConnections[0].name + '_' + i18next.language.split('-')[0]; return await stepContext.next(result); } diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.de.json b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.de.json index 2ec8eae3b..8ef7894a0 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.de.json +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.de.json @@ -43,5 +43,23 @@ } ], "inputHint": "expectingInput" + }, + "LoginButton": { + "replies": [ + { + "text": "Einloggen", + "speak": "Einloggen" + } + ], + "inputHint": "acceptingInput" + }, + "LoginPrompt": { + "replies": [ + { + "text": "Melden Sie sich in Ihrem {authType}-Konto an", + "speak": "Melden Sie sich in Ihrem {authType}-Konto an" + } + ], + "inputHint": "acceptingInput" } } \ No newline at end of file diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.es.json b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.es.json index f130209fb..6843fe50a 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.es.json +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.es.json @@ -43,5 +43,23 @@ } ], "inputHint": "expectingInput" + }, + "LoginButton": { + "replies": [ + { + "text": "Iniciar sesión", + "speak": "Iniciar sesión" + } + ], + "inputHint": "acceptingInput" + }, + "LoginPrompt": { + "replies": [ + { + "text": "Inicia sesión en tu cuenta de {authType}", + "speak": "Inicia sesión en tu cuenta de {authType}" + } + ], + "inputHint": "acceptingInput" } } \ No newline at end of file diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.fr.json b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.fr.json index 703c43392..e0d2d6e01 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.fr.json +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.fr.json @@ -43,5 +43,23 @@ } ], "inputHint": "expectingInput" + }, + "LoginButton": { + "replies": [ + { + "text": "s'identifier", + "speak": "s'identifier" + } + ], + "inputHint": "acceptingInput" + }, + "LoginPrompt": { + "replies": [ + { + "text": "connectez-vous à votre compte {authType}", + "speak": "connectez-vous à votre compte {authType}" + } + ], + "inputHint": "acceptingInput" } } \ No newline at end of file diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.it.json b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.it.json index 6d47ec642..d518a4eaa 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.it.json +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.it.json @@ -43,5 +43,23 @@ } ], "inputHint": "expectingInput" + }, + "LoginButton": { + "replies": [ + { + "text": "Accesso", + "speak": "Accesso" + } + ], + "inputHint": "acceptingInput" + }, + "LoginPrompt": { + "replies": [ + { + "text": "Accedi al tuo account {authType}", + "speak": "Accedi al tuo account {authType}" + } + ], + "inputHint": "acceptingInput" } } \ No newline at end of file diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.json b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.json index 04f720122..cc6615f35 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.json +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.json @@ -43,5 +43,23 @@ } ], "inputHint": "acceptingInput" + }, + "LoginButton": { + "replies": [ + { + "text": "Login", + "speak": "Login" + } + ], + "inputHint": "acceptingInput" + }, + "LoginPrompt": { + "replies": [ + { + "text": "Sign in to your {authType} account", + "speak": "Sign in to your {authType} account" + } + ], + "inputHint": "acceptingInput" } } diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.zh.json b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.zh.json index 79fb6c5ec..ecb855c43 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.zh.json +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/resources/AuthenticationResponses.zh.json @@ -43,5 +43,23 @@ } ], "inputHint": "expectingInput" + }, + "LoginButton": { + "replies": [ + { + "text": "登錄", + "speak": "登錄" + } + ], + "inputHint": "acceptingInput" + }, + "LoginPrompt": { + "replies": [ + { + "text": "登錄到您的{authType}帳戶", + "speak": "登錄到您的{authType}帳戶" + } + ], + "inputHint": "acceptingInput" } } \ No newline at end of file diff --git a/sdk/typescript/libraries/bot-solutions/src/responses/responseManager.ts b/sdk/typescript/libraries/bot-solutions/src/responses/responseManager.ts index 9149dc093..eda5036fd 100644 --- a/sdk/typescript/libraries/bot-solutions/src/responses/responseManager.ts +++ b/sdk/typescript/libraries/bot-solutions/src/responses/responseManager.ts @@ -56,6 +56,20 @@ export class ResponseManager { return this.parseResponse(template, tokens); } + /** + * Gets a simple response from template with Text, Speak, InputHint, and SuggestedActions set. + * @param templateId The name of the response template. + * @param locale The locale for the response template. + * @param tokens string map of tokens to replace in the response. + * @returns An Activity. + */ + public getLocalizedResponse(templateId: string, locale: string, tokens?: Map): Partial { + const template: ResponseTemplate = this.getResponseTemplate(templateId, locale); + + // create the response the data items + return this.parseResponse(template, tokens); + } + /** * Gets the Text of a response. * @param templateId The name of the response template. From f745a3220e68503c93cf40c06d0b72e8eb6ed3da Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 2 Feb 2021 15:42:49 -0300 Subject: [PATCH 2/4] Remove commented code --- .../src/authentication/multiProviderAuthDialog.ts | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts b/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts index cfffe5384..5c0794e76 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts @@ -69,21 +69,6 @@ export class MultiProviderAuthDialog extends ComponentDialog { MultiProviderAuthDialog.acceptedLocales.forEach(locale => { this.addDialog(this.getLocalizedDialog(locale, connection.name, promptSettings[i])); }); - - // // We ignore placeholder connections in config that don't have a Name - // if (connection.name !== undefined && connection.name.trim().length > 0) { - // const settings: OAuthPromptSettings = promptSettings[i] || { - // connectionName: connection.name, - // title: i18next.t('common:login'), - // text: i18next.t('common:loginDescription', connection.name) - // }; - - // this.addDialog(new OAuthPrompt( - // connection.name, - // settings, - // this.authPromptValidator.bind(this) - // )); - // } }; this.addDialog(new WaterfallDialog(DialogIds.authPrompt, authSteps)); From a37295e26bf78e31aa044ff5a19fb95896dde0a9 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 5 Feb 2021 14:42:58 -0300 Subject: [PATCH 3/4] Fix linting issues --- .../src/authentication/authenticationResponses.ts | 4 ++-- .../src/authentication/multiProviderAuthDialog.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts b/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts index 0d500c16f..4074ef3fa 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts @@ -16,6 +16,6 @@ export class AuthenticationResponses implements IResponseIdCollection { public static readonly configuredAuthProvidersPrompt: string = 'ConfiguredAuthProvidersPrompt'; public static readonly errorMessageAuthFailure: string = 'ErrorMessageAuthFailure'; public static readonly noLinkedAccount: string = 'NoLinkedAccount'; - public static readonly loginButton : string = 'LoginButton'; - public static readonly loginPrompt : string = 'LoginPrompt'; + public static readonly loginButton: string = 'LoginButton'; + public static readonly loginPrompt: string = 'LoginPrompt'; } diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts b/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts index 5c0794e76..e1ec1addb 100644 --- a/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts +++ b/sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts @@ -6,7 +6,8 @@ import { BotFrameworkAdapter, TurnContext } from 'botbuilder'; import { Choice, ChoicePrompt, ComponentDialog, DialogTurnResult, DialogTurnStatus, FoundChoice, OAuthPrompt, PromptValidatorContext, WaterfallDialog, WaterfallStep, WaterfallStepContext, - OAuthPromptSettings } from 'botbuilder-dialogs'; + OAuthPromptSettings, + Dialog} from 'botbuilder-dialogs'; import { TokenStatus } from 'botframework-connector/lib/tokenApi/models'; import { ActionTypes, Activity, ActivityTypes, TokenResponse } from 'botframework-schema'; import i18next from 'i18next'; @@ -16,7 +17,6 @@ import { TokenEvents } from '../tokenEvents'; import { AuthenticationResponses } from './authenticationResponses'; import { OAuthProviderExtensions } from './oAuthProviderExtensions'; import { IProviderTokenResponse } from './providerTokenResponse'; -import { OAuthProvider } from './oAuthProvider'; enum DialogIds { providerPrompt = 'ProviderPrompt', @@ -28,7 +28,7 @@ enum DialogIds { * Provides the ability to prompt for which Authentication provider the user wishes to use. */ export class MultiProviderAuthDialog extends ComponentDialog { - private static readonly acceptedLocales: string[] = ["en", "de", "es", "fr", "it", "zh"]; + private static readonly acceptedLocales: string[] = ['en', 'de', 'es', 'fr', 'it', 'zh']; private selectedAuthType: string = ''; private authenticationConnections: IOAuthConnection[]; private responseManager: ResponseManager; @@ -66,7 +66,7 @@ export class MultiProviderAuthDialog extends ComponentDialog { for (var i = 0; i < this.authenticationConnections.length; ++i) { let connection = this.authenticationConnections[i]; - MultiProviderAuthDialog.acceptedLocales.forEach(locale => { + MultiProviderAuthDialog.acceptedLocales.forEach((locale): void => { this.addDialog(this.getLocalizedDialog(locale, connection.name, promptSettings[i])); }); }; @@ -78,9 +78,9 @@ export class MultiProviderAuthDialog extends ComponentDialog { } } - private getLocalizedDialog(locale: string, connectionName: string, settings: OAuthPromptSettings) { + private getLocalizedDialog(locale: string, connectionName: string, settings: OAuthPromptSettings): Dialog { const loginButtonActivity: string = this.responseManager.getLocalizedResponse(AuthenticationResponses.loginButton, locale).text; - const loginPromptActivity : string = this.responseManager.getLocalizedResponse(AuthenticationResponses.loginPrompt, locale, new Map([["authType", connectionName]])).text; + const loginPromptActivity: string = this.responseManager.getLocalizedResponse(AuthenticationResponses.loginPrompt, locale, new Map([['authType', connectionName]])).text; settings = settings || { connectionName: connectionName,