endOfConversation 不是函数

endOfConversation not a function

我的机器人现在正在使用本地内存,目标是对话结束时。我想从本地内存中删除有关该用户的所有内容。所以我尝试了这个 onEndOfConversation.

显然这个错误显示说 onEndOfConversation 不是一个函数。

这是我的代码:

const { CardFactory } = require('botbuilder');
const { DialogBot } = require('./dialogBot');
const WelcomeCard = require('./resources/welcomeCard.json');

class DialogAndWelcomeBot extends DialogBot {
    constructor(conversationState, userState, dialog) {
        super(conversationState, userState, dialog);

        this.onMembersAdded(async (context, next) => {
            const membersAdded = context.activity.membersAdded;
            for (let cnt = 0; cnt < membersAdded.length; cnt++) {
                if (membersAdded[cnt].id !== context.activity.recipient.id) {
                    //const welcomeCard = CardFactory.adaptiveCard(WelcomeCard);
                    //await context.sendActivity({ attachments: [welcomeCard] });
                    await dialog.run(context, conversationState.createProperty('DialogState'));
                }
            }

            // By calling next() you ensure that the next BotHandler is run.
            await next();
        });

        
        this.onEndOfConversation(async (context, next) => {
            console.log("END!");
            await conversationState.delete(context);
            await userState.delete(context);
        });
    }
}

module.exports.DialogAndWelcomeBot = DialogAndWelcomeBot;

那么我应该怎么做呢?如果无法识别 onEndOfConversation,我可以采取哪些替代方法来在对话结束后从内存中清除用户和对话。

当机器人也与技能相结合时,endOfConversation activity 处理程序在内部使用。当用户结束对话时,机器人会向技能发送此 activity 类型,通知它与用户的对话已结束。

您可以通过不同的方式来解决这个问题。我使用的方法是 component dialogs. Modeled after the cancelAndHelpDialog 设计,当用户键入“取消”或“退出”时,用户将被带到一个收集反馈的退出对话框等。

作为退出过程的一部分,您可以在对话框中调用 conversationState.delete(),然后调用 cancelAllDialogs(true)

希望得到帮助!