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.

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 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/`));
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 for telemetry 
    //       configuration instructions.
    let langResponse = multiLangLG.generate('SomethingWentWrong', {
        message: `${ error }`
    }, context.activity.locale);

    // 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

        // Define the main dialog and its related components.
        this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [

        // 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);