Commands

ICommand

Each plugin can have multiple commands.

Also see ILocalizedCommand.

Each command has the following properties:

Member Type Description
name string Friendly-name of the command (not necessarily the words used to call it). Should be title-cased.
match string | string[] |IDynamicMatch The word(s) the user can say to execute this command. Use "#" in the string as an ordinal place holder. Use "*" as a wildcard placeholder. Lastly, a function IDynamicMatch can be used for the most advanced cases.
description string (optional) Detailed description visible in the options page.
global boolean (default: false) let the command match on any page (not restricted by the match of the Plugin)
pageFn (transcript: string, ...matchOutput: any) => Promise<any> (optional) An async function to run on the page when the command is called. Special matches (* and #) will be arguments after the transcript string argument, and will come in the order they are specified in the match property. There will be a number argument if the match string accepts an ordinal (eg. has a #) in it, or a string argument if the match string accepts a wildcard (eg. has a * in it).

Also see fn vs. pageFn.
delay number | number[] (optional) How long to wait for additional input for before executing this command. Overrides delay that is built-in for commands with match strings that end in ordinals or wildcards.

Useful when you want to allow time for a more accurate transcript, or for more words to come through.

Use an array with indices that correspond to the different match strings if you should have different delays based on the match string.

Use 0 to override dynamically calculated delay and to execute command immediately on match.
nice INiceCommand (optional) See INiceCommand.
fn (transcript: string, ...matchOutput: any) => any (optional) An async function that runs in the Chrome extension context when the command is called. First arg is the transcript that matched, rest of arguments are what's returned from the match command.

Also see fn vs. pageFn.
test () => void (optional but recommended) Selenium unit test for this command.

fn vs. pageFn

NOTE

pageFn runs in the context of the page so it has access to the DOM, but doesn't have access to Chrome extension APIs like chrome.tabs. fn on the other hand runs in the (sandboxed) context of the Chrome extension; it doesn't have access to the page or it's DOM but it does have access to the Chrome extension APIs. pageFn is preferred unless you need access to extension APIs.

IDynamicMatch

A function that decides whether a command matches based on a transcript input for more dynamic command word possibilities.

Member Type Description
fn (transcript: string) =>MatchResult| undefined A function that takes in the transcript and returns a MatchResultif the command should execute on the given transcript.
description string Used to decribe to the user what command words match. Seen in plugins list in options.

MatchResult

Type: boolean|any[]

Array of args to pass over to pageFn.

-or-

false if there is a partial match. If there is a partial match we will delay other commands that might already want to execute.

E.g.

Imagine there's a command word for reddit and a dynamic match command for reddit message that are both valid on a given page. If the user says reddit message the transcripts will come down the wire something like this:

  • red
  • reddit
  • read it
  • read it mess
  • reddit mess
  • reddit message

Can you see the problem? Our "reddit" command will execute even though we only want "reddit" message to.

If you don't want the first "reddit" command to match, return false when there is a partial match for the dynamic reddit command for transcripts that start with "reddit".

ILocalizedCommand

See also ICommand and IPluginTranslation.

Member Type Description
name string The original name of the command to match this localized version with.
description string (optional)
match string | string[] |IDynamicMatch The way localized version of command match can be completely different from the base English version.
delay number | number[] (optional) Delays for a localized version of a command can be completely different from the base English version.
nice INiceCommand (optional) See INiceCommand.

INiceCommand

Type: string | ((transcript: string, ...matchOutput: any) => string)

Sometimes we want to adjust the transcript as it is shown on the live text. For example if the user says go to are meal time videos we would want to show that as go to r/mealtimevideos.

Returns the complete "live text" that should be shown. rawInput is the transcript (eg. "go to are meal time videos") matchOutput is an array returned from the match command if IDynamicMatchis used.

Last updated: 12/5/2018, 4:37:16 AM