Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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),
new botbuilder_dialogs_adaptive_1.IfCondition('$hangup == true', [
constructor() {
super('AddToDo', [
new TextInput('$title', '@title', `What would you like to call your new todo?`),
new EditArray(ArrayChangeType.push, 'user.todos', '$title'),
new SendActivity(`Added a todo named "{$title}". You can delete it by saying "delete todo named {$title}".`),
new IfCondition(`user.tips.showToDos != true`, [
new SendActivity(`To view your todos just ask me to "show my todos".`),
new SetProperty('user.tips.showToDos', 'true')
])
]);
// Use parents recognizer
this.recognizer = getRecognizer();
// Add interruption rules
this.addRule(new OnIntent('#Cancel', [], [
new CancelAllDialogs('cancelAdd')
]));
}
}
constructor() {
super('main');
// Bind to production/development recognizer
this.recognizer = getRecognizer();
// Handle recognized intents
this.addRule(new OnIntent('#AddToDo', [], [
new AddToDo()
]));
this.addRule(new OnIntent('#DeleteToDo', [], [
new DeleteToDo()
]));
this.addRule(new OnIntent('#ClearToDos', [], [
new ClearToDos()
]));
this.addRule(new OnIntent('#ShowToDos', [], [
new ShowToDos()
]));
this.addRule(new OnUnknownIntent([
constructor() {
super('main');
// Bind to production/development recognizer
this.recognizer = getRecognizer();
// Handle recognized intents
this.addRule(new OnIntent('#AddToDo', [], [
new AddToDo()
]));
this.addRule(new OnIntent('#DeleteToDo', [], [
new DeleteToDo()
]));
this.addRule(new OnIntent('#ClearToDos', [], [
new ClearToDos()
]));
this.addRule(new OnIntent('#ShowToDos', [], [
new ShowToDos()
]));
this.addRule(new OnUnknownIntent([
new IfCondition(`user.greeted != true`, [
new SendActivity(`Hi! I'm a ToDo bot. Say "add a todo named first one" to get started.`),
new SetProperty(`user.greeted`, `true`)
]).else([
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
//=================================================================================================
const askNameDialog = new AdaptiveDialog('AskNameDialog', [
new IfCondition('user.name == null', [
new TextInput('user.name', `Hi! what's your name?`)
constructor() {
super('main');
// Bind to production/development recognizer
this.recognizer = getRecognizer();
// Handle recognized intents
this.addRule(new OnIntent('#AddToDo', [], [
new AddToDo()
]));
this.addRule(new OnIntent('#DeleteToDo', [], [
new DeleteToDo()
]));
this.addRule(new OnIntent('#ClearToDos', [], [
new ClearToDos()
]));
this.addRule(new OnIntent('#ShowToDos', [], [
new ShowToDos()
]));
this.addRule(new OnUnknownIntent([
new IfCondition(`user.greeted != true`, [
new SendActivity(`Hi! I'm a ToDo bot. Say "add a todo named first one" to get started.`),
new SetProperty(`user.greeted`, `true`)
]).else([
new SendActivity(`Say "add a todo named first one" to get started.`)
])
]));
// 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.`),
new botbuilder_dialogs_adaptive_1.EndDialog()
]);
constructor() {
super('main');
// Bind to production/development recognizer
this.recognizer = recognizer_1.getRecognizer();
// Handle recognized intents
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnIntent('#AddToDo', [], [
new addToDo_1.AddToDo()
]));
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnIntent('#DeleteToDo', [], [
new deleteToDo_1.DeleteToDo()
]));
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnIntent('#ClearToDos', [], [
new clearToDos_1.ClearToDos()
]));
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnIntent('#ShowToDos', [], [
new showToDos_1.ShowToDos()
]));
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnUnknownIntent([
new botbuilder_dialogs_adaptive_1.IfCondition(`user.greeted != true`, [
new botbuilder_dialogs_adaptive_1.SendActivity(`Hi! I'm a ToDo bot. Say "add a todo named first one" to get started.`),
new botbuilder_dialogs_adaptive_1.SetProperty(`user.greeted`, `true`)
]).else([
this.recognizer = getRecognizer();
// Handle recognized intents
this.addRule(new OnIntent('#AddToDo', [], [
new AddToDo()
]));
this.addRule(new OnIntent('#DeleteToDo', [], [
new DeleteToDo()
]));
this.addRule(new OnIntent('#ClearToDos', [], [
new ClearToDos()
]));
this.addRule(new OnIntent('#ShowToDos', [], [
new ShowToDos()
]));
this.addRule(new OnUnknownIntent([
new IfCondition(`user.greeted != true`, [
new SendActivity(`Hi! I'm a ToDo bot. Say "add a todo named first one" to get started.`),
new SetProperty(`user.greeted`, `true`)
]).else([
new SendActivity(`Say "add a todo named first one" to get started.`)
])
]));
// Define rules to handle cancel events
this.addRule(new OnDialogEvent('cancelAdd', [
new SendActivity(`Ok... Cancelled adding new todo.`)
]));
constructor() {
super('main');
// Bind to production/development recognizer
this.recognizer = recognizer_1.getRecognizer();
// Handle recognized intents
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnIntent('#AddToDo', [], [
new addToDo_1.AddToDo()
]));
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnIntent('#DeleteToDo', [], [
new deleteToDo_1.DeleteToDo()
]));
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnIntent('#ClearToDos', [], [
new clearToDos_1.ClearToDos()
]));
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnIntent('#ShowToDos', [], [
new showToDos_1.ShowToDos()
]));
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnUnknownIntent([
new botbuilder_dialogs_adaptive_1.IfCondition(`user.greeted != true`, [
new botbuilder_dialogs_adaptive_1.SendActivity(`Hi! I'm a ToDo bot. Say "add a todo named first one" to get started.`),
new botbuilder_dialogs_adaptive_1.SetProperty(`user.greeted`, `true`)
]).else([
new botbuilder_dialogs_adaptive_1.SendActivity(`Say "add a todo named first one" to get started.`)
])
]));
// Define rules to handle cancel events
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnDialogEvent('cancelAdd', [
new botbuilder_dialogs_adaptive_1.SendActivity(`Ok... Cancelled adding new todo.`)
]));
this.triggers.push(new botbuilder_dialogs_adaptive_1.OnDialogEvent('cancelDelete', [
new botbuilder_dialogs_adaptive_1.SendActivity(`Ok...`)