简体   繁体   English

如何捕捉对话结束事件?

[英]How to catch conversation ending event?

Using Microsoft BotBuilder, I want to catch event when user close or terminate a conversation with my bot. 我想使用Microsoft BotBuilder在用户关闭或终止与我的机器人的对话时捕获事件。 Here is the code of my bot: 这是我的机器人的代码:

const builder = require('botbuilder');
const connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

const inMemoryStorage = new builder.MemoryBotStorage();
const bot = new builder.UniversalBot(connector).set('storage', inMemoryStorage);
initialize(bot);

function initialize(bot) {
        bot.on('conversationUpdate', function(data) {

        });
    }

From the block of code above, I want to add an event that will handle ending conversation. 从上面的代码块中,我想添加一个将处理结束对话的事件。 Here is my example code: 这是我的示例代码:

function initialize(bot) {
        bot.on('conversationEnd', function(data) {
            var user = data.user,
                address = data.address,
                conversationId = data.address.conversation.id;
        });
    }

So, is there an event of conversationEnd like above code? 那么,是否有像上面的代码那样的sessionEnd事件? I want to know if botBuilder can handle an ending conversation? 我想知道botBuilder是否可以处理结束的对话?

There is no event like converstaionEnd . 没有像converstaionEnd这样的事件。 Think of it in this way. 以这种方式考虑它。 If you are chatting with someone, you can just opt to not reply anymore. 如果您正在与某人聊天,则可以选择不再回复。 To a human user, it will seem that conversation has ended, but bot will not have any clue. 对于人类用户来说,对话似乎已经结束,但是漫游器不会有任何线索。 It will keep on waiting. 它将继续等待。 Unless you provide the intelligence to bot, to wait for a certain amount of time before considering that conversation has ended. 除非您向漫游器提供情报,否则请等待一段时间,然后再考虑对话已结束。

That said there are some other things you can handle: 也就是说,您还可以处理其他一些事情:

  • You can handle conversationUpdate event. 您可以处理conversationUpdate事件。 This event is triggered when any member joins/leaves a converstaion. 任何成员加入/退出对话时都会触发此事件。 Example

  • You can use a certain keyword (like goodbye, exit , etc.) as conversation ending keyword, which can trigger endConversationAction Example 您可以使用某个关键字(例如再见,退出等)作为会话结束关键字,它可以触发endConversationAction 示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM