Step 5: Specify alternatives and options

The phrase used to invoke a voice command is called a pattern. At present, our command is invoked by one phrase: I want a pepperoni. However, the users can give a voice command in different ways. For example:

  • I will take a pepperoni

  • Add a pepperoni

  • Add a pepperoni, please and so on

To be sure the voice command is invoked by any of these phrases, we can add alternatives and options to the command pattern.

  • To define alternatives, use the - character.

  • To define optional parts of the user command, enclose these parts in brackets and add | at the end of them.

Dialog script
intent('(I want|I will take|Add) a- pepperoni, please-', p => {
    p.play('Adding pepperoni for you');
});

Now all the above phrases will work.