javascript - Botframework SDK v.4 - 瀑布对话框中的提示步骤导致无法再调用存储中的对象
问题描述
目前,我正在尝试使用 Bot 框架的 SDK v4 开发聊天机器人,但遇到以下问题: 基于 Microsoft 的 BasicBot 模板,我尝试构建自己的瀑布对话。在瀑布对话框的 promptUserForAttachmentStep 函数中,应要求用户使用 AttachmentPrompt 上传图像。由于此提示,不再可能在以下步骤中使用状态访问器从内存中访问 UserProfile 对象。我得到的只是一个空对象。
不管是什么提示。在提示步骤内,对象仍然可以被调用。但不是在那之后。但是,只要我删除提示,就可以在下一步中调用它。
不幸的是,我不太明白为什么会这样。这在模板中不是问题。
我会很高兴得到帮助
许多问候
import { StatePropertyAccessor } from 'botbuilder';
import { ComponentDialog, PromptValidatorContext, WaterfallDialog, WaterfallStepContext, AttachmentPrompt, TextPrompt } from 'botbuilder-dialogs';
import { FaceAPI } from './API_Files/faceAPI_conn';
import { SQLConntector } from './API_Files/mysql_conn';
import { UserProfile } from './userProfile';
const FACE_DIALOG = 'faceDialog';
const LOGIN_DIALOG = 'loginDialog'
const ATTACH_PROMPT = 'attachPrompt';
const SECRET_PROMPT = 'secretPrompt;'
export class authentDialog extends ComponentDialog {
private userProfileAccessor: StatePropertyAccessor<UserProfile>;
private faceAPI;
private sqlConnector: SQLConntector;
constructor (dialogId: string, userStateAccessor: StatePropertyAccessor<UserProfile>) {
super(dialogId);
// TODO: Daten auslagern
this.faceAPI = new FaceAPI (
"https://northeurope.api.cognitive.microsoft.com/face/v1.0/",
""
);
this.sqlConnector = new SQLConntector (
"",
"",
"",
""
);
this.addDialog(new WaterfallDialog<UserProfile>(FACE_DIALOG, [
this.initializeUserStateStep.bind(this),
this.promptUserForAttachmentStep.bind(this),
this.identificateFaceId.bind(this),
this.detectPersonId.bind(this)
]));
this.addDialog(new AttachmentPrompt(ATTACH_PROMPT));
this.addDialog(new TextPrompt(SECRET_PROMPT));
this.addDialog(new WaterfallDialog<UserProfile> (LOGIN_DIALOG, [
this.getEmployeeName.bind(this)
]));
this.userProfileAccessor = userStateAccessor;
}
private async initializeUserStateStep (step: WaterfallStepContext<UserProfile>) {
const userProfile = await this.userProfileAccessor.get(step.context);
if (userProfile === undefined) {
await this.userProfileAccessor.set(step.context, new UserProfile());
}
return await step.next();
}
private async promptUserForAttachmentStep (step: WaterfallStepContext<UserProfile>) {
// This writes the userProfile object
console.log(await this.userProfileAccessor.get(step.context));
return await step.prompt(ATTACH_PROMPT,'Bitte lade zur Autorisierung ein Foto deines Gesichts hoch.');
}
private async identificateFaceId (step: WaterfallStepContext<UserProfile>) {
// This is now an empty object
console.log(await this.userProfileAccessor.get(step.context));
if (!step.result[0].contentUrl) {
await step.context.sendActivities([
{type: 'typing'},
{type: 'delay', value: 2000},
{type: 'message', text: 'Ich benötige ein Foto :)' }
])
return await step.replaceDialog(FACE_DIALOG);
} else {
const faceID = await this.faceAPI.getDetectedFaceId(step.result[0].contentUrl);
if (!faceID) {
await step.context.sendActivities([
{type: 'typing'},
{type: 'delay', value: 2000},
{type: 'message', text: 'Ich konnte kein Gesicht erkennen :(.' },
{type: 'typing'},
{type: 'delay', value: 2000},
{type: 'message', text: 'Bitte versuche es nochmal.' }
]);
return await step.replaceDialog(FACE_DIALOG);
} else {
return await step.next(faceID);
}
}
}
}
解决方案
推荐阅读
- opencl - 如何使用 boost::compute::atan2?
- javascript - jsGrid - 单击提交按钮时获取新数据
- firebase - firebase.firestore.GeoPoint(long, lat) 不是构造函数
- c++ - 替换 C++17 中已删除的 bind1st
- python - 使用完全相同的 API 调用时,Google App Engine 实例的行为会有所不同
- python - 我拿了一个 Java 类并试图将其转换为 python 我做错了什么?
- php - Mediawiki 移动现有图像目录
- kubernetes - 从 S3 上的 kops 配置创建 kubernetes go-client 配置
- macos-sierra - 以编程方式切换暗模式 macOS Mojave
- javascript - Amcharts在小屏幕上未定义的值