How to use the botbuilder-dialogs-adaptive.RegExpRecognizer function in botbuilder-dialogs-adaptive

To help you get started, we’ve selected a few botbuilder-dialogs-adaptive 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-js / samples / 30. stateMachineDialog / src / index.ts View on Github external
// Route activity to bot.
        await bot.onTurn(context);
    });
});

// Initialize bots root dialog
const dialogs = new StateMachineDialog('main', 'offHook');
bot.rootDialog = dialogs;

// offHook state
const offHook = dialogs.addState('offHook', [
    new SendActivity(`☎️ off hook`),
    new SendActivity(`say "place a call" to get started.`)
]);
offHook.permit('callDialed', 'ringing');
offHook.recognizer = new RegExpRecognizer().addIntent('PlaceCallIntent', /place .*call/i);
offHook.addRule(new OnIntent('PlaceCallIntent', [], [
    new EmitEvent('callDialed')
]));


// ringing state
const ringing = dialogs.addState('ringing', [
    new SendActivity(`☎️ ring... ring...`),
    new ConfirmInput('$answer', `Would you like to answer it?`, true),
    new IfCondition('$answer == true', [
        new EmitEvent('callConnected')
    ])
]);
ringing.permit('callConnected', 'connected');
github microsoft / botbuilder-js / samples / 30. stateMachineDialog / lib / index.js View on Github external
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        // Route activity to bot.
        await bot.onTurn(context);
    });
});
// Initialize bots root dialog
const dialogs = new botbuilder_dialogs_adaptive_1.StateMachineDialog('main', 'offHook');
bot.rootDialog = dialogs;
// offHook state
const offHook = dialogs.addState('offHook', [
    new botbuilder_dialogs_adaptive_1.SendActivity(`☎️ off hook`),
    new botbuilder_dialogs_adaptive_1.SendActivity(`say "place a call" to get started.`)
]);
offHook.permit('callDialed', 'ringing');
offHook.recognizer = new botbuilder_dialogs_adaptive_1.RegExpRecognizer().addIntent('PlaceCallIntent', /place .*call/i);
offHook.addRule(new botbuilder_dialogs_adaptive_1.OnIntent('PlaceCallIntent', [
    new botbuilder_dialogs_adaptive_1.EmitEvent('callDialed')
]));
// ringing state
const ringing = dialogs.addState('ringing', [
    new botbuilder_dialogs_adaptive_1.SendActivity(`☎️ ring... ring...`),
    new botbuilder_dialogs_adaptive_1.ConfirmInput('$answer', `Would you like to answer it?`, true),
    new botbuilder_dialogs_adaptive_1.IfCondition('$answer == true', [
        new botbuilder_dialogs_adaptive_1.EmitEvent('callConnected')
    ])
]);
ringing.permit('callConnected', 'connected');
// connected state
const connected = dialogs.addState('connected', [
    new botbuilder_dialogs_adaptive_1.SendActivity(`📞 talk... talk... talk... ☹️`),
    new botbuilder_dialogs_adaptive_1.ConfirmInput('$hangup', `Heard enough yet?`, true),
github microsoft / botbuilder-js / samples / 50. todo-bot / src / rootDialog / recognizer.ts View on Github external
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { RegExpRecognizer, Recognizer } from 'botbuilder-dialogs-adaptive';
import { intents } from '../schema';

export function getRecognizer(): Recognizer {
    switch (process.env.NODE_ENV) {
        case 'development':
        default:
            return devRecognizer;
    }
}

const devRecognizer = new RegExpRecognizer()
    .addIntent(intents.AddToDo, /(?:add|create) .*(?:to-do|todo|task) .*(?:called|named) (?<title>.*)/i)
    .addIntent(intents.AddToDo, /(?:add|create) .*(?:to-do|todo|task)/i)
    .addIntent(intents.DeleteToDo, /(?:delete|remove|clear) .*(?:to-do|todo|task) .*(?:called|named) (?&lt;title&gt;.*)/i)
    .addIntent(intents.DeleteToDo, /(?:delete|remove|clear) .*(?:to-do|todo|task)/i)
    .addIntent(intents.ClearToDos, /(?:delete|remove|clear) (?:all|every) (?:to-dos|todos|tasks)/i)
    .addIntent(intents.ShowToDos, /(?:show|see|view) .*(?:to-do|todo|task)/i)
    .addIntent(intents.Help, /^help/i)
    .addIntent(intents.Cancel, /^cancel/i);

</title>
github microsoft / botbuilder-js / samples / 05. beginDialog / src / index.ts View on Github external
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        // Route activity to bot.
        await bot.onTurn(context);
    });
});

// Initialize bots root dialog
const dialogs = new AdaptiveDialog();
bot.rootDialog = dialogs;

//=================================================================================================
// Rules
//=================================================================================================

dialogs.recognizer = new RegExpRecognizer().addIntent('JokeIntent', /tell .*joke/i);

// Tell the user a joke
dialogs.addRule(new OnIntent('#JokeIntent', [], [
    new BeginDialog('TellJokeDialog')
]));

// Handle unknown intents
dialogs.addRule(new OnUnknownIntent([
    new BeginDialog('AskNameDialog')
]));


//=================================================================================================
// Child Dialogs
//=================================================================================================
github microsoft / botbuilder-js / samples / 05. beginDialog / lib / index.js View on Github external
bot.conversationState = new botbuilder_1.ConversationState(new botbuilder_1.MemoryStorage());
bot.userState = new botbuilder_1.UserState(new botbuilder_1.MemoryStorage());
// Listen for incoming activities.
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        // Route activity to bot.
        await bot.onTurn(context);
    });
});
// Initialize bots root dialog
const dialogs = new botbuilder_dialogs_adaptive_1.AdaptiveDialog();
bot.rootDialog = dialogs;
//=================================================================================================
// Rules
//=================================================================================================
dialogs.recognizer = new botbuilder_dialogs_adaptive_1.RegExpRecognizer().addIntent('JokeIntent', /tell .*joke/i);
// Tell the user a joke
dialogs.addRule(new botbuilder_dialogs_adaptive_1.OnIntent('#JokeIntent', [], [
    new botbuilder_dialogs_adaptive_1.BeginDialog('TellJokeDialog')
]));
// Handle unknown intents
dialogs.addRule(new botbuilder_dialogs_adaptive_1.OnUnknownIntent([
    new botbuilder_dialogs_adaptive_1.BeginDialog('AskNameDialog')
]));
//=================================================================================================
// Child Dialogs
//=================================================================================================
const askNameDialog = new botbuilder_dialogs_adaptive_1.AdaptiveDialog('AskNameDialog', [
    new botbuilder_dialogs_adaptive_1.IfCondition('user.name == null', [
        new botbuilder_dialogs_adaptive_1.TextInput('user.name', `Hi! what's your name?`)
    ]),
    new botbuilder_dialogs_adaptive_1.SendActivity(`Hi {user.name}. It's nice to meet you.`),
github microsoft / botbuilder-js / samples / 04. onIntent / lib / index.js View on Github external
// Create bots DialogManager and bind to state storage
const bot = new botbuilder_dialogs_1.DialogManager();
bot.conversationState = new botbuilder_1.ConversationState(new botbuilder_1.MemoryStorage());
bot.userState = new botbuilder_1.UserState(new botbuilder_1.MemoryStorage());
// Listen for incoming activities.
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        // Route activity to bot.
        await bot.onTurn(context);
    });
});
// Initialize bots root dialog
const dialogs = new botbuilder_dialogs_adaptive_1.AdaptiveDialog();
bot.rootDialog = dialogs;
// Create recognizer
dialogs.recognizer = new botbuilder_dialogs_adaptive_1.RegExpRecognizer().addIntent('JokeIntent', /tell .*joke/i);
// Tell the user a joke
dialogs.triggers.push(new botbuilder_dialogs_adaptive_1.OnIntent('#JokeIntent', [], [
    new botbuilder_dialogs_adaptive_1.SendActivity(`Why did the 🐔 cross the 🛣️?`),
    new botbuilder_dialogs_adaptive_1.EndTurn(),
    new botbuilder_dialogs_adaptive_1.SendActivity(`To get to the other side...`)
]));
// Handle unknown intents
dialogs.triggers.push(new botbuilder_dialogs_adaptive_1.OnUnknownIntent([
    new botbuilder_dialogs_adaptive_1.IfCondition('user.name == null', [
        new botbuilder_dialogs_adaptive_1.TextInput('user.name', `Hi! what's your name?`)
    ]),
    new botbuilder_dialogs_adaptive_1.SendActivity(`Hi {user.name}. It's nice to meet you.`)
]));
//# sourceMappingURL=index.js.map
github microsoft / botbuilder-js / samples / 50. todo-bot / lib / rootDialog / recognizer.js View on Github external
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const botbuilder_dialogs_adaptive_1 = require("botbuilder-dialogs-adaptive");
const schema_1 = require("../schema");
function getRecognizer() {
    switch (process.env.NODE_ENV) {
        case 'development':
        default:
            return devRecognizer;
    }
}
exports.getRecognizer = getRecognizer;
const devRecognizer = new botbuilder_dialogs_adaptive_1.RegExpRecognizer()
    .addIntent(schema_1.intents.AddToDo, /(?:add|create) .*(?:to-do|todo|task) .*(?:called|named) (?<title>.*)/i)
    .addIntent(schema_1.intents.AddToDo, /(?:add|create) .*(?:to-do|todo|task)/i)
    .addIntent(schema_1.intents.DeleteToDo, /(?:delete|remove|clear) .*(?:to-do|todo|task) .*(?:called|named) (?&lt;title&gt;.*)/i)
    .addIntent(schema_1.intents.DeleteToDo, /(?:delete|remove|clear) .*(?:to-do|todo|task)/i)
    .addIntent(schema_1.intents.ClearToDos, /(?:delete|remove|clear) (?:all|every) (?:to-dos|todos|tasks)/i)
    .addIntent(schema_1.intents.ShowToDos, /(?:show|see|view) .*(?:to-do|todo|task)/i)
    .addIntent(schema_1.intents.Help, /^help/i)
    .addIntent(schema_1.intents.Cancel, /^cancel/i);
//# sourceMappingURL=recognizer.js.map</title>
github microsoft / botbuilder-js / samples / 04. onIntent / src / index.ts View on Github external
bot.userState = new UserState(new MemoryStorage());

// Listen for incoming activities.
server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        // Route activity to bot.
        await bot.onTurn(context);
    });
});

// Initialize bots root dialog
const dialogs = new AdaptiveDialog();
bot.rootDialog = dialogs;

// Create recognizer
dialogs.recognizer = new RegExpRecognizer().addIntent('JokeIntent', /tell .*joke/i);

// Tell the user a joke
dialogs.addRule(new OnIntent('#JokeIntent', [], [
    new SendActivity(`Why did the 🐔 cross the 🛣️?`),
    new EndTurn(),
    new SendActivity(`To get to the other side...`)
]));

// Handle unknown intents
dialogs.addRule(new OnUnknownIntent([
    new IfCondition('user.name == null', [
        new TextInput('user.name', `Hi! what's your name?`)
    ]),
    new SendActivity(`Hi {user.name}. It's nice to meet you.`)
]));