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.

  1. To the voice script, add the getComment context with a command to capture the user’s comment:

    let getComment = context(() => {
        intent('My comment is $(COMMENT* (.+))', p => {
            p.play(`I'll' take a note: ${p.COMMENT.value}`);
        });
    });
    
  2. Update the intent in the getTime context: activate the getComment context from it and add another p.play() function to prompt the user to leave a comment:

     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}`);
         });
     });
    

    Web page source | Voice script

Now, you can try the dialog with different phrases for a comment.