我正在尝试构建一个机器人。因此,在一个Node.js文件中,使用ActivityHandler
时出现以下错误-
TypeError: Class extends value undefined is not a constructor or null
这是我正在使用的代码-
const { ActivityHandler } = require('botbuilder');
const { LuisRecognizer, QnAMaker } = require('botbuilder-ai');
class DispatchBot extends ActivityHandler {
constructor(logger) {
super();
if (!logger) {
logger = console;
logger.log('[DispatchBot]: logger not passed in, defaulting to console');
}
const dispatchRecognizer = new LuisRecognizer({
applicationId: process.env.LuisAppId,
endpointKey: process.env.LuisAPIKey,
endpoint: `https://${ process.env.LuisAPIHostName }.api.cognitive.microsoft.com`
}, {
includeAllIntents: true,
includeInstanceData: true
}, true);
const qnaMaker = new QnAMaker({
knowledgeBaseId: process.env.QnAKnowledgebaseId,
endpointKey: process.env.QnAAuthKey,
host: process.env.QnAEndpointHostName
});
this.logger = logger;
this.dispatchRecognizer = dispatchRecognizer;
this.qnaMaker = qnaMaker;
this.onMessage(async (context, next) => {
this.logger.log('Processing Message Activity.');
const recognizerResult = await dispatchRecognizer.recognize(context);
const intent = LuisRecognizer.topIntent(recognizerResult);
await this.dispatchToTopIntentAsync(context, intent, recognizerResult);
await next();
});
this.onMembersAdded(async (context, next) => {
const welcomeText = 'Type a greeting or a question about the weather to get started.';
const membersAdded = context.activity.membersAdded;
for (let member of membersAdded) {
if (member.id !== context.activity.recipient.id) {
await context.sendActivity(`Welcome to Dispatch bot ${ member.name }. ${ welcomeText }`);
}
}
await next();
});
}
async dispatchToTopIntentAsync(context, intent, recognizerResult) {
switch (intent) {
case 'l_luis':
await this.processLuis(context, recognizerResult.luisResult);
break;
case 'q_sample-qna':
await this.processSampleQnA(context);
break;
default:
this.logger.log(`Dispatch unrecognized intent: ${ intent }.`);
await context.sendActivity(`Dispatch unrecognized intent: ${ intent }.`);
break;
}
}
}
module.exports.DispatchBot = DispatchBot;
错误-
class DispatchBot extends ActivityHandler {
^
TypeError: Class extends value undefined is not a constructor or null
那么如何避免这种问题呢?
答案 0 :(得分:0)
仅卸载botbuilder
软件包并重新安装即可解决我的问题。