LocalizedRegExpRecognizer class

Version of the RegExpRecognizer that uses the frameworks localization system to retrieve a localized regular expression. The lookup key in the index.json file should be provided and upon receiving a message for a new locale, the recognizer will retrieve the localized expression and a new case insensitive RegExp will be created and used to recognize the intent. Libraries can use this feature to let a bot override their default matching expressions. just create instances of the recognizer using the namespace of your library and bot developers can customize your matching expressions by using a <namespace>.json file in their locale directory.

Extends

Constructors

LocalizedRegExpRecognizer(string, string, string)

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

LocalizedRegExpRecognizer(string, string, string)

Constructs a new instance of the recognizer.

new LocalizedRegExpRecognizer(intent: string, key: string, namespace?: string)

Parameters

intent

string

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

key

string

Key for the expression in the index.json or <namespace>.json file.

namespace

string

(Optional) library namespace to lookup key from. The expression should be a string in the <namespace>.json locale file.

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.