TalAter / annyang

:speech_balloon: Speech recognition for your site
https://www.talater.com/annyang/
MIT License
6.57k stars 1.05k forks source link

is there a documented syntax diagram for the command template? #423

Closed sdetweil closed 3 years ago

sdetweil commented 3 years ago

I want to extend an app I wrote, which copied an example from another app. it has optional words

it has

 (ask) appname (to) *

I want to have both tell and ask as optional first words.

but I have never seen a full syntax diagram of what is allowed is it (ask|tell) or (ask) (tell) or something else?

sorry for submitting an issue.. I cannot find any doc that describes this

TalAter commented 3 years ago

The basic way to define commands does not support multiple options for an optional parameter. You can see the full explanation of what is supported in the documentation.

To achieve what you want you can either define two separate commands that point at the same function, like this:

var commands = {
  '(ask) appname (to) *do': myFunction,
  '(tell) appname (to) *do': myFunction,
};

Or better yet, use a regular expression to define your command syntax.

sdetweil commented 3 years ago

thanks but the 'doc' doesn't even describe what 'optional' looks like (surround by ellipsis)

this works correctly

(ask) (tell) appname (to) *

TalAter commented 3 years ago

Just note that your solution of (ask) (tell) appname (to) * isn't just ask or tell. It would accept ask and/or tell, but only in that specific order (i.e., it will accept the sentence ask tell appname to do but not tell ask appname to do). It gets the job done, but it also seems to me like a solution that could lead to hard to debug issues down the line.