Step 7: Add several items

The user may want to order several items, for example three burgers or five burritos. Let’s update our voice command to support this behavior.

  1. Add another pattern to invoke the voice command. Inside this pattern, we will use the $(NUMBER) predefined slot to capture the number of ordered items. The command patterns are separated with a comma.

     const itemList = "pepperoni|margherita|burrito|burger|taco|apple pie";
    
     intent(`(I want|I will take|Add|) (a|an|) $(ITEM ${itemList}), (please|)`,
            `(I want|I will take|Add|) $(NUMBER) $(ITEM ${itemList}), (please|)`, p => {
         p.play(`Adding ${p.ITEM.value} for you`, 'Sure', 'Here you go');
     });
    
  2. At present, our voice assistant won’t understand the correct grammar form: Add five burritos. To fix this, we have two options:

    • We can add plural alternatives to our slot variable, like burrito|burritos.

    • We can use Alan’s pluralizer syntax — add an underscore to the item names: burrito_.

    Let’s use the second option:

      const itemList = "pepperoni_|margherita_|burrito_|burger_|taco_|apple pie_";
    
      intent(`(I want|I will take|Add|) (a|an|) $(ITEM ${itemList}), (please|)`,
             `(I want|I will take|Add|) $(NUMBER) $(ITEM ${itemList}), (please|)`, p => {
          p.play(`Adding ${p.ITEM.value} for you`, 'Sure', 'Here you go');
      });