将身份验证和QNAMAKER添加到机器人
我正在尝试使用BOT Framework SDK构建一个机器人。
目的: -
- 对用户进行身份验证。
- AFTE身份验证与QNAMAKER知识库进行通信。
- 签名用户如果他输入注销,
我正在使用bot身份验证模板,来自 https://github.com/microsoft/botbuilder-samples/tree/main/main/samples/javascript_nodejs/18.bot-authentication 。我试图在WaterFlowDialog中添加Qnamaker服务。
我面临两个问题: -
- 每一个Qnamaker回复,我都会收到消息“您现在已登录”。
- 机器人遇到错误。
源代码
maindialog.js
const {
ConfirmPrompt,
DialogSet,
DialogTurnStatus,
OAuthPrompt,
WaterfallDialog,
} = require("botbuilder-dialogs");
const { LogoutDialog } = require("./logoutDialog");
const { QnAMakerDialog } = require("botbuilder-ai");
const CONFIRM_PROMPT = "ConfirmPrompt";
const MAIN_DIALOG = "MainDialog";
const MAIN_WATERFALL_DIALOG = "MainWaterfallDialog";
const OAUTH_PROMPT = "OAuthPrompt";
const QNAMAKER_BASE_DIALOG = "qnamaker-base-dialog";
const createQnAMakerDialog = (
knowledgeBaseId,
endpointKey,
endpointHostName,
defaultAnswer
) => {
let noAnswerActivity;
if (typeof defaultAnswer === "string") {
noAnswerActivity = MessageFactory.text(defaultAnswer);
}
const qnaMakerDialog = new QnAMakerDialog(
knowledgeBaseId,
endpointKey,
endpointHostName,
noAnswerActivity
);
qnaMakerDialog.id = QNAMAKER_BASE_DIALOG;
return qnaMakerDialog;
};
class MainDialog extends LogoutDialog {
constructor(knowledgeBaseId, endpointKey, endpointHostName, defaultAnswer) {
super(MAIN_DIALOG, process.env.connectionName);
this.addDialog(
new OAuthPrompt(OAUTH_PROMPT, {
connectionName: process.env.connectionName,
text: "Please Sign In",
title: "Sign In",
timeout: 300000,
})
);
this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
this.addDialog(
new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
this.promptStep.bind(this),
this.loginStep.bind(this),
this.qnaMaker.bind(this),
])
);
this.addDialog(
createQnAMakerDialog(
knowledgeBaseId,
endpointKey,
endpointHostName,
defaultAnswer
)
);
this.initialDialogId = MAIN_WATERFALL_DIALOG;
}
/**
* The run method handles the incoming activity (in the form of a DialogContext) and passes it through the dialog system.
* If no dialog is active, it will start the default dialog.
* @param {*} dialogContext
*/
async run(context, accessor) {
const dialogSet = new DialogSet(accessor);
dialogSet.add(this);
const dialogContext = await dialogSet.createContext(context);
const results = await dialogContext.continueDialog();
if (results.status === DialogTurnStatus.empty) {
await dialogContext.beginDialog(this.id);
}
}
async qnaMaker(stepContext) {
await stepContext.beginDialog(QNAMAKER_BASE_DIALOG);
}
async promptStep(stepContext) {
return await stepContext.beginDialog(OAUTH_PROMPT);
}
async loginStep(stepContext) {
// Get the token from the previous step. Note that we could also have gotten the
// token directly from the prompt itself. There is an example of this in the next method.
const tokenResponse = stepContext.result;
if (tokenResponse) {
await stepContext.context.sendActivity("You are now logged in");
return await stepContext.next();
}
await stepContext.context.sendActivity(
"Login was not successful please try again."
);
return await stepContext.endDialog();
}
}
module.exports.MainDialog = MainDialog;
bot ScreenShot github
github link:https://github.com/chandelsumeet/authBot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用上述代码块替换
loginstep()
并进行检查。Replace the
loginStep()
with above code block and check it.