Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
// Handle unknown intents
dialogs.addRule(new OnUnknownIntent([
new InitProperty('dialog.list', 'array'),
new TextInput("dialog.item", "What is your name?"),
new EditArray(ArrayChangeType.push, 'dialog.list', 'dialog.item'),
new SendActivity('Your name in an array: {dialog.list}')
]));
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('ClearToDos', [
new LogAction(`ClearToDos: todos = {user.todos}`),
new IfCondition(`user.todos != null`, [
new EditArray(ArrayChangeType.clear, 'user.todos'),
new SendActivity(`All todos removed.`)
]).else([
new SendActivity(`No todos to clear.`)
])
]);
// Use parents recognizer
this.recognizer = getRecognizer();
}
}
constructor() {
super('DeleteToDo', [
new LogAction(`DeleteToDo: todos = {user.todos}`),
new IfCondition(`user.todos != null`, [
new SetProperty('$title', '@title'),
new ChoiceInput('$title', `Which todo would you like to remove?`, 'user.todos'),
new EditArray(ArrayChangeType.remove, 'user.todos', '$title'),
new SendActivity(`Deleted the todo named "{$title}".`),
new IfCondition(`user.tips.clearToDos != true`, [
new SendActivity(`You can delete all your todos by saying "delete all todos".`),
new SetProperty('user.tips.clearToDos', 'true')
])
]).else([
new SendActivity(`No todos to delete.`)
])
]);
// Use parents recognizer
this.recognizer = getRecognizer();
// Add interruption rules
this.addRule(new OnIntent('#Cancel', [], [
new CancelAllDialogs('cancelDelete')