Step 14: Capture a comment¶
The user may leave a comment to the order, which can be any phrase. To capture an open-end phrase, we can use a slot with a greedy RegEx.
To the dialog script, add the
getComment
context with a command to capture the user’s comment:Dialog script¶let getComment = context(() => { intent('My comment is $(COMMENT* (.+))', p => { p.play(`I'll' take a note: ${p.COMMENT.value}`); }); });
Update the intent in the
getTime
context: activate thegetComment
context from it and add anotherp.play()
function to prompt the user to leave a comment:Dialog script¶let getTime = context(() => { intent('$(TIME)', '$(T now|asap|right now|as soon as possible)', p => { let time, date; if (p.T) { time = api.moment().tz(p.timeZone).add(30, 'minutes').format("h:mm a"); } if (p.TIME) { time = p.TIME.value; } p.play(`We will deliver your order at ${time}`); // Prompting for leaving comments p.play('Any comments?'); // Activating the getComment context p.then(getComment); }); }); let getComment = context(() => { intent('My comment is $(COMMENT* (.+))', p => { p.play(`I'll' take a note: ${p.COMMENT.value}`); }); });
Now, you can try the dialog with different phrases for a comment.