I have Luis working in my main bot.js file for top level intents. But i'd like to access Luis from other dialogs that are in their own files, called by bot.js:
bot.js:
const { InitialDialog } = require('./dialogs/initial');
const INITIAL_DIALOG = 'initialDialog';
const START_INTENT = 'Start';
then in the bot's class:
this.dialogs.add(
new InitialDialog(
INITIAL_DIALOG,
this.userProfileAccessor,
botConfig
)
);
and finally, if the "Start intent" is detected we start the dialog:
await dc.beginDialog(InitialDialog);
In dialogs/initial/index.js:
class Initial extends ComponentDialog {
constructor(dialogId, userProfileAccessor, botConfig) {
super(dialogId);
}
Here's where it gets problematic: when I try and call Luis:
// Perform a call to LUIS to retrieve results for the user's message.
const results: RecognizerResult = await this.luisRecognizer.recognize(turnContext);
// Since the LuisRecognizer was configured to include the raw results, get the `topScoringIntent` as specified by LUIS.
const topIntent = results.luisResult.topScoringIntent;
I'm getting an error:
[onTurnError]: TypeError: Cannot read property 'recognize' of undefined
Any idea what I'm doing wrong here?
The luisRecognizer needs to be created:
const luisApplication = {
applicationId: luisConfig.appId,
endpointKey: luisConfig.subscriptionKey || luisConfig.authoringKey,
endpoint: luisConfig.getEndpoint()
};
// Create configuration for LuisRecognizer's runtime behavior.
const luisPredictionOptions = {
includeAllIntents: true,
log: true,
staging: false
};
this.luisRecognizer = new LuisRecognizer(luisApplication, luisPredictionOptions , true);
A sample using LUIS can be found here: https://github.com/Microsoft/BotBuilder-Samples/blob/master/samples/javascript_nodejs/12.nlp-with-luis