【发布时间】:2019-04-23 17:01:48
【问题描述】:
我正在为 Node js 使用 botBuilder SDK 4.3。
我在对话框的构造函数中创建了一个 conversationState 属性。 在某些对话框步骤中,我为该属性设置了一个值。
在另一个步骤中,我尝试在像 So 这样的 setTimeOut 中获取该属性的值。
// Imports ...
class Reservation extends ComponentDialog {
constructor(id, conversationState, userState, dialogProps) {
super(id);
this.id = id;
this.conversationState = conversationState;
this.userState = userState;
this.initialDialogId = CONFIGS.MAIN_DIALOG_ID;
this.reservationNotifProp = conversationState.createProperty(
"reservationNotif"
);
...
this.addDialog(
new WaterfallDialog(this.initialDialogId, [
this.askCheckIn.bind(this),
this.askCheckout.bind(this)
this.askNights.bind(this),
this.validateDates.bind(this),
.....
]
);
}
async askCheckIn (step) { ... }
async askCheckout (step) { ... }
async askNights (step) {
// ...
this.reservationNotifProp.set(step.context, false);
await this.conversationState.saveChanges(step.context);
const ref = this;
setTimeout(async () => {
const notif = await this.reservationNotifProp.get(step.context);
if (notif) {
console.log("Send Notif ...");
}
}, 50000);
}
async validateDates(step) {
// ...
this.reservationNotifProp.set(step.context, true);
await this.conversationState.saveChanges(step.context);
}
}
超时结束后,我收到此错误,notif 是 undefined:
(node:47504) UnhandledPromiseRejectionWarning: TypeError: Cannot perform 'get' on a proxy that has been revoked
at ConversationState.load (c:\Users\Montacer\Desktop\qt-bot\node_modules\botbuilder\node_modules\botbuilder-core\src\botState.ts:84:48)
at BotStatePropertyAccessor.get (c:\Users\Montacer\Desktop\qt-bot\node_modules\botbuilder\node_modules\botbuilder-core\src\botStatePropertyAccessor.ts:97:43)
at Timeout.setTimeout [as _onTimeout] (c:\Users\Montacer\Desktop\qt-bot\dialogs\reservation.js:366:63)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
warning.js:18
(node:47504) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
warning.js:18
(node:47504) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
有什么解决办法吗?
【问题讨论】:
-
回调通常不适用于 BotFramework。如果用户在 50000 毫秒内没有响应,您是否尝试发送通知?
标签: javascript azure botframework