user964409
user964409

Reputation: 121

How to catch conversation ending event?

Using Microsoft BotBuilder, I want to catch event when user close or terminate a conversation with my bot. 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? I want to know if botBuilder can handle an ending conversation?

Upvotes: 0

Views: 180

Answers (1)

Master Chief
Master Chief

Reputation: 2541

There is no event like 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. 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 endConversationActionExample

Upvotes: 1

Related Questions