How to use the botbuilder-lg.MultiLanguageLG function in botbuilder-lg

To help you get started, we’ve selected a few botbuilder-lg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 05.a.multi-turn-prompt-with-language-fallback / index.js View on Github external
// Import our custom bot class that provides a turn handling function.
const { DialogBot } = require('./bots/dialogBot');
const { UserProfileDialog } = require('./dialogs/userProfileDialog');

// Create the adapter. See https://aka.ms/about-bot-adapter to learn more about using information from
// the .bot file when configuring your adapter.
const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

// Create template engine for language generation.
const templatesPerLocale = new Map();
templatesPerLocale.set('', Templates.parseFile(`${__dirname}/Resources/adapterWithErrorHandler.lg`)),
templatesPerLocale.set('fr', Templates.parseFile(`${__dirname}/Resources/adapterWithErrorHandler.fr-fr.lg`));
const multiLangLG = new MultiLanguageLG(templatesPerLocale);

// Catch-all for errors.
adapter.onTurnError = async (context, error) => {
    // This check writes out errors to console log .vs. app insights.
    // NOTE: In production environment, you should consider logging this to Azure
    //       application insights. See https://aka.ms/bottelemetry for telemetry 
    //       configuration instructions.
    let langResponse = multiLangLG.generate('SomethingWentWrong', {
        message: `${ error }`
    }, context.activity.locale);
    console.error(langResponse);

    // Send a trace activity, which will be displayed in Bot Framework Emulator
    await context.sendTraceActivity(
        'OnTurnError Trace',
        `${ langResponse }`,
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / multilingual / dialogs / mainDialog.js View on Github external
super('MainDialog');

        // Define the main dialog and its related components.
        this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
            this.showMultilingualResult.bind(this)
        ]));

        // The initial child Dialog to run.
        this.initialDialogId = MAIN_WATERFALL_DIALOG;

        var lgTemplatesMap = new Map();
        lgTemplatesMap.set('fr-fr', Templates.parseFile("./resources/root.lg", this.multilingualResolver('fr-fr')));
        lgTemplatesMap.set('en-us', Templates.parseFile("./resources/root.lg", this.multilingualResolver('en-us')));
        lgTemplatesMap.set("", Templates.parseFile("./resources/root.lg", this.multilingualResolver('')));

        this.generator = new MultiLanguageLG(lgTemplatesMap, undefined);
    }