How to use botbuilder-lg - 10 common examples

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-tools / packages / LGvscodeExt / src / providers / diagnostics.ts View on Github external
function updateDiagnostics(document: vscode.TextDocument, collection: vscode.DiagnosticCollection): void {
    // special case
    if(document.fileName.endsWith('.git')) {
        return;
    }
    
	if (util.isLgFile(document.fileName)) {
        var diagnostics = new StaticChecker().checkFile(document.uri.fsPath);
        var vscodeDiagnostics: vscode.Diagnostic[] = [];
        const confDiagLevel = vscode.workspace.getConfiguration().get('LG.Expression.ignoreUnknownFunction');
        const confCustomFuncListSetting: string = vscode.workspace.getConfiguration().get('LG.Expression.customFunctionList');
        var customFunctionList: string[] = [];
        if (confCustomFuncListSetting.length >= 1) {
            customFunctionList = confCustomFuncListSetting.split(",").map(u => u.trim());
        }
        diagnostics.forEach(u => {
            const isUnkownFuncDiag: boolean = u.message.includes("it's not a built-in function or a customized function in expression");
            if (isUnkownFuncDiag === true){
                let ignored = false;
                const funcName = extractFuncName(u.message);
                console.log(funcName);
                if (customFunctionList.includes(funcName)) {
                    ignored = true;
                } else {
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 / BotFramework-Composer / Composer / packages / lib / indexers / src / lgIndexer.ts View on Github external
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { LGParser, StaticChecker, DiagnosticSeverity, Diagnostic } from 'botbuilder-lg';
import get from 'lodash/get';

import { FileInfo, LgFile, LgTemplate } from './type';
import { getBaseName } from './utils/help';

const lgStaticChecker = new StaticChecker();

function index(files: FileInfo[]): LgFile[] {
  if (files.length === 0) return [];
  const lgFiles: LgFile[] = [];
  for (const file of files) {
    if (file.name.endsWith('.lg')) {
      const diagnostics = lgStaticChecker.checkText(file.content, file.path);
      let templates: LgTemplate[] = [];
      try {
        templates = parse(file.content, '');
      } catch (err) {
        console.error(err);
      }
      lgFiles.push({
        id: getBaseName(file.name, '.lg'),
        relativePath: file.relativePath,
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 / 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()}")
                    }),