RegExpRecognizer class

Intent recognizer plugin that detects a users intent using a regular expression. Multiple expressions can be passed in to support recognizing across multiple languages.

Extends

Constructors

RegExpRecognizer(string, RegExp | IRegExpMap)

Constructs a new instance of the recognizer.

Methods

onEnabled((context: IRecognizeContext, callback: (err: Error, enabled: boolean) => void) => void)

Registers a function to conditionally enable/disable the recognizer. Multiple handlers can be registered and the new handler will be executed before any other handlers.

onFilter((context: IRecognizeContext, result: IIntentRecognizerResult, callback: (err: Error, result: IIntentRecognizerResult) => void) => void)

Registers a function to filter the output from the recognizer. Multiple handlers can be registered and the new handler will be executed after any other handlers.

onRecognize(IRecognizeContext, (err: Error, result: IIntentRecognizerResult) => void)

Implements the actual recognition logic.

recognize(IRecognizeContext, (err: Error, result: IIntentRecognizerResult) => void)

Attempts to match a users text utterance to an intent.

Constructor Details

RegExpRecognizer(string, RegExp | IRegExpMap)

Constructs a new instance of the recognizer.

new RegExpRecognizer(intent: string, expressions: RegExp | IRegExpMap)

Parameters

intent
string

The name of the intent to return when the expression is matched.

expressions
RegExp | IRegExpMap

Either an individual expression used for all utterances or a map of per/locale expressions conditionally used depending on the locale of the utterance.

Method Details

onEnabled((context: IRecognizeContext, callback: (err: Error, enabled: boolean) => void) => void)

Registers a function to conditionally enable/disable the recognizer. Multiple handlers can be registered and the new handler will be executed before any other handlers.

function onEnabled(handler: (context: IRecognizeContext, callback: (err: Error, enabled: boolean) => void) => void)

Parameters

handler
(context: IRecognizeContext, callback: (err: Error, enabled: boolean) => void) => void

Function called for every message. You should call callback(null, true) for every message that should be recognized.

Returns

onFilter((context: IRecognizeContext, result: IIntentRecognizerResult, callback: (err: Error, result: IIntentRecognizerResult) => void) => void)

Registers a function to filter the output from the recognizer. Multiple handlers can be registered and the new handler will be executed after any other handlers.

function onFilter(handler: (context: IRecognizeContext, result: IIntentRecognizerResult, callback: (err: Error, result: IIntentRecognizerResult) => void) => void)

Parameters

handler
(context: IRecognizeContext, result: IIntentRecognizerResult, callback: (err: Error, result: IIntentRecognizerResult) => void) => void

Function called for every message that results in an intent with a score greater then 0.0. You should call callback(null, { score: 0.0, intent: null }) to block an intent from being returned.

Returns

onRecognize(IRecognizeContext, (err: Error, result: IIntentRecognizerResult) => void)

Implements the actual recognition logic.

function onRecognize(context: IRecognizeContext, callback: (err: Error, result: IIntentRecognizerResult) => void)

Parameters

callback
(err: Error, result: IIntentRecognizerResult) => void

recognize(IRecognizeContext, (err: Error, result: IIntentRecognizerResult) => void)

Attempts to match a users text utterance to an intent.

function recognize(context: IRecognizeContext, callback: (err: Error, result: IIntentRecognizerResult) => void)

Parameters

context
IRecognizeContext

Contextual information for a received message that's being recognized.

callback
(err: Error, result: IIntentRecognizerResult) => void

Function to invoke with the results of the recognition operation.