diff --git a/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts b/sdk/typescript/libraries/bot-solutions/src/authentication/authenticationResponses.ts index 7fd772428c..4074ef3fa5 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 e76188cfee..e1ec1addbf 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,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,35 @@ 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) - }; - - this.addDialog(new OAuthPrompt( - connection.name, - settings, - this.authPromptValidator.bind(this) - )); - } + MultiProviderAuthDialog.acceptedLocales.forEach((locale): void => { + this.addDialog(this.getLocalizedDialog(locale, connection.name, promptSettings[i])); + }); }; - 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): 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; + + 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 +114,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 2ec8eae3b2..8ef7894a00 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 f130209fbb..6843fe50ac 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 703c43392d..e0d2d6e013 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 6d47ec642e..d518a4eaaf 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 04f720122f..cc6615f353 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 79fb6c5ec7..ecb855c43f 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 9149dc093b..eda5036fd9 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.