in experimental/adaptive-dialog/javascript_nodejs/08.todo-bot-with-luis-qnamaker/dialogs/deleteToDoDialog/deleteToDoDialog.js [17:128]
constructor() {
super(DIALOG_ID);
const lgFile = Templates.parseFile(path.join(__dirname, `${DIALOG_ID}.lg`));
this.lgGenerator = new TemplateEngineLanguageGenerator(lgFile);
const dialog = new AdaptiveDialog(DIALOG_ID).configure({
generator: this.lgGenerator,
recognizer: this.createCrossTrainedRecognizer(),
triggers: [
new OnBeginDialog([
// Handle case where there are no items in todo list
new IfCondition().configure(
{
// All conditions are expressed using the common expression language.
// See https://github.com/Microsoft/BotBuilder-Samples/tree/master/experimental/common-expression-language to learn more
condition: new BoolExpression("count(user.lists.todo) == 0 && count(user.lists.grocery) == 0 && count(user.lists.shopping) == 0"),
actions: [
new SendActivity("${DeleteEmptyList()}"),
new EndDialog()
]
}),
// User could have specified the item and/ or list type to delete.
new SetProperty().configure(
{
property: new StringExpression("dialog.itemTitle"),
value: new ValueExpression("=@itemTitle")
}),
new SetProperty().configure(
{
property: new StringExpression("dialog.listType"),
value: new ValueExpression("=@listType")
}),
// Ask for list type first.
new TextInput().configure(
{
property: new StringExpression("dialog.listType"),
prompt: new ActivityTemplate("${GetListType()}"),
value: new ValueExpression("=@listType"),
allowInterruptions: new BoolExpression("!@listType && turn.recognized.score >= 0.7"),
validations: [
// Verify using expressions that the value is one of todo or shopping or grocery
"contains(createArray('todo', 'shopping', 'grocery'), toLower(this.value))",
],
outputFormat: new StringExpression("=toLower(this.value)"),
invalidPrompt: new ActivityTemplate("${GetListType.Invalid()}"),
maxTurnCount: new IntExpression(2),
defaultValue: new ValueExpression("todo"),
defaultValueResponse: new ActivityTemplate("${GetListType.DefaultValueResponse()}")
}),
new IfCondition().configure(
{
condition: new BoolExpression("count(user.lists[dialog.listType]) == 0"),
actions: [
new SendActivity("${NoItemsInList()}"),
new EndDialog()
]
}),
// Ask for title to delete
new ChoiceInput().configure(
{
choices: new ArrayExpression("user.lists[dialog.listType]"),
property: new StringExpression("dialog.itemTitle"),
outputFormat: ChoiceOutputFormat.value,
style: ListStyle.list,
prompt: new ActivityTemplate("${GetItemTitleToDelete()}")
}),
// remove item
new EditArray().configure(
{
itemsProperty: new StringExpression("user.lists[dialog.listType]"),
value: new ValueExpression("=dialog.itemTitle"),
changeType: new EnumExpression(ArrayChangeType.remove)
}),
new SendActivity("${DeleteConfirmationReadBack()}")
]),
// Shows how to use dialog event to capture intent recognition event for more than one intent.
// Alternate to this would be to add two separate OnIntent events.
// This ensures we set any entities recognized by these two intents.
new OnDialogEvent(AdaptiveEvents.recognizedIntent, [
new SetProperty().configure(
{
property: new StringExpression("dialog.itemTitle"),
value: new ValueExpression("=@itemTitle")
}
),
new SetProperty().configure(
{
property: new StringExpression("dialog.listType"),
value: new ValueExpression("=@listType")
}
)
], "#GetTitleToDelete || #GetListType"),
// Help and chitchat is handled by qna
new OnQnAMatch([
// Use code action to render QnA response. This is also a demonstration of how to use code actions to light up custom functionality.
new CodeAction(this.resolveAndSendQnAAnswer.bind(this))
]),
]
});
this.addDialog(dialog);
this.initialDialogId = DIALOG_ID;
}