How to use the botbuilder-lg.Templates.parseFile 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
const { BotFrameworkAdapter, ConversationState, MemoryStorage, UserState, ActivityFactory } = require('botbuilder');

// 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(
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 06.using-cards / index.js View on Github external
// Import required bot services.
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
const { BotFrameworkAdapter, MemoryStorage, ConversationState, UserState } = require('botbuilder');

// This bot's main dialog.
const { RichCardsBot } = require('./bots/richCardsBot');
const { MainDialog } = require('./dialogs/mainDialog');

// Create adapter. See https://aka.ms/about-bot-adapter to learn more about adapters.
const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

// Create template engine for language generation.
const lgTemplates = Templates.parseFile('./resources/AdapterWithErrorHandler.lg');

// 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.
    console.error(lgTemplates.evaluate('SomethingWentWrong', {
        message: `${ error }`
    }));

    // Send a trace activity, which will be displayed in Bot Framework Emulator
    await context.sendTraceActivity(
        'OnTurnError Trace',
        `${ error }`,
        'https://www.botframework.com/schemas/error',
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 20.custom-functions / index.js View on Github external
// Create HTTP server
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
    console.log(`\n${ server.name } listening to ${ server.url }`);
    console.log('\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator');
    console.log('\nTo talk to your bot, open the emulator select "Open Bot"');
});

// Create adapter.
// See https://aka.ms/about-bot-adapter to learn more about how bots work.
const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

const lgTemplates = Templates.parseFile(path.join(__dirname, './resources/AdapterWithErrorHandler.lg'));

// Catch-all for errors.
const onTurnErrorHandler = 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.
    console.error(lgTemplates.evaluate('SomethingWentWrong', {
        message: `${ error }`
    }));

    // Send a trace activity, which will be displayed in Bot Framework Emulator
    await context.sendTraceActivity(
        'OnTurnError Trace',
        `${ error }`,
        'https://www.botframework.com/schemas/error',
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 13.core-bot / index.js View on Github external
const { MainDialog } = require('./dialogs/mainDialog');

// the bot's booking dialog
const { BookingDialog } = require('./dialogs/bookingDialog');
const BOOKING_DIALOG = 'bookingDialog';

// Create adapter.
// See https://aka.ms/about-bot-adapter to learn more about adapters.
const adapter = new BotFrameworkAdapter({
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
});

// Create template engine for language generation.
console.log(path.join(__dirname, './resources/AdapterWithErrorHandler.lg'));
const lgTemplates = Templates.parseFile(path.join(__dirname, './resources/AdapterWithErrorHandler.lg'));

// 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.
    console.error(lgTemplates.evaluate('SomethingWentWrong', {
        message: `${ error }`
    }));

    // Send a trace activity, which will be displayed in Bot Framework Emulator
    await context.sendTraceActivity(
        'OnTurnError Trace',
        `${ error }`,
        'https://www.botframework.com/schemas/error',
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 06.using-cards / dialogs / mainDialog.js View on Github external
constructor() {
        super('MainDialog');

        // Define the main dialog and its related components.
        this.addDialog(new ChoicePrompt('cardPrompt'));
        this.addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
            this.choiceCardStep.bind(this),
            this.showCardStep.bind(this)
        ]));

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

        this.lgTemplates = Templates.parseFile('./resources/MainDialog.lg');
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 13.core-bot / bots / dialogAndWelcomeBot.js View on Github external
constructor(conversationState, userState, dialog) {
        super(conversationState, userState, dialog);

        const lgTemplates = Templates.parseFile('./resources/welcomeCard.lg');

        // Actions to include in the welcome card. These are passed to LG and are then included in the generated Welcome card.
        const actions = {
            actions: [
                {
                    title: 'Get an overview',
                    url: 'https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0'
                },
                {
                    title: 'Ask a question',
                    url: 'https://stackoverflow.com/questions/tagged/botframework'
                },
                {
                    title: 'Learn how to deploy',
                    url: 'https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-deploy-azure?view=azure-bot-service-4.0'
                }
github microsoft / BotBuilder-Samples / experimental / adaptive-dialog / javascript_nodejs / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
constructor() {
        super('userProfileDialog');
        let lgFile = Templates.parseFile(path.join(__dirname, "userProfileDialog.lg"));
        let userProfileAdaptiveDialog = new AdaptiveDialog(ROOT_DIALOG).configure({
            generator: new TemplateEngineLanguageGenerator(lgFile),
            triggers: [
                new OnBeginDialog([
                    // Ask for user's age and set it in user.userProfile scope.
                    new TextInput().configure(
                    {
                        // Set the output of the text input to this property in memory.
                        property: new StringExpression("user.userProfile.Transport"),
                        prompt: new ActivityTemplate("${ModeOfTransportPrompt.Text()}")
                    }),
                    new TextInput().configure(
                    {
                        property: new StringExpression("user.userProfile.Name"),
                        prompt: new ActivityTemplate("${AskForName()}")
                    }),
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / multilingual / dialogs / mainDialog.js View on Github external
constructor() {
        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);
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 13.core-bot / dialogs / bookingDialog.js View on Github external
super(id || 'bookingDialog');

        this.addDialog(new TextPrompt(TEXT_PROMPT))
            .addDialog(new ConfirmPrompt(CONFIRM_PROMPT))
            .addDialog(new DateResolverDialog(DATE_RESOLVER_DIALOG))
            .addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
                this.destinationStep.bind(this),
                this.originStep.bind(this),
                this.travelDateStep.bind(this),
                this.confirmStep.bind(this),
                this.finalStep.bind(this)
            ]));

        this.initialDialogId = WATERFALL_DIALOG;

        this.lgTemplates = Templates.parseFile(path.join(__dirname, '../resources/BookingDialog.lg'));
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / language-generation / 05.multi-turn-prompt / dialogs / userProfileDialog.js View on Github external
this.addDialog(new ChoicePrompt(CHOICE_PROMPT));
        this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
        this.addDialog(new NumberPrompt(NUMBER_PROMPT, this.agePromptValidator));

        this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
            this.transportStep.bind(this),
            this.nameStep.bind(this),
            this.nameConfirmStep.bind(this),
            this.ageStep.bind(this),
            this.confirmStep.bind(this),
            this.summaryStep.bind(this)
        ]));

        this.initialDialogId = WATERFALL_DIALOG;

        this.lgTemplates = Templates.parseFile('./Resources/UserProfileDialog.lg');
    }