0
votes

I have a simple chatbot which takes the user's name and replies asking how it can help them. It works fine in the emulator and webchat but when I tried that as an android app via DirectLine I'm getting an additional prompt which is just empty. So I put some code to log the bot's conversation and I found that the bot is sending a message "undefined" along with the prompt I programmed it to send.

My Code sample

bot.dialog('/', new builder.IntentDialog()
    .matchesAny([/hi/i], [
        function (session) {
            session.send('Hi, I am a chatbot.');
            session.beginDialog('/step2')
        },
        bot.dialog('/step2', [
            function (session) {
                builder.Prompts.text(session, 'What is your name?');
            },
            function (session, args, next) {
                session.send('Hello, ' + args.response + '. How may I help you today?');
                name = args.response;
                session.endConversation();
            }
        ])
    ]));

When I put in some middleware logging, I got the following output:

USER: Hi

BOT: Hi, I am a chatbot.

BOT: What is your name?

USER: Bob

BOT: Hello, Bob. How may I help you today?

BOT: undefined

Even my node console shows that 2 messages are sent at the end instead of just one

ChatConnector: message received.
UniversalBot("*") routing "Anish" from "emulator"
Library("BotBuilder").findRoutes() explanation:
        ActiveDialog(0.5)
..BotBuilder:prompt-text - Prompt.returning(Anish)
..BotBuilder:prompt-text - Session.endDialogWithResult()
./step2 - waterfall() step 2 of 2
./step2 - Session.send()
./step2 - Session.endConversation()
Session.sendBatch() sending 2 message(s)

Why is that undefined message being sent? How can I stop it?

1
What happens in you remove the Session.endConversation()? - Ezequiel Jadib
@EzequielJadib wow, that worked. Why is Session.endconversation() causing this? - Anish
But if I don't use session.endconversation(), the bot is going in loop and asking me what my name is when I reply to "how may I help you" - Anish
Actually, you can send the message in the endConversation method (one of the accepted parameters is the text); however then you will see the same behavior, once you reply it will start the conversation with the same question - Ezequiel Jadib

1 Answers

0
votes

Try removing the following line

 session.send('Hello, ' + args.response + '. How may I help you today?');

And replace the Session.endConversation() call with:

Session.endConversation('Hello, ' + args.response + '. How may I help you today?');

Alternatively, you can just remove the Session.endConversation() call as I mentioned in the comments

You can also check the End of Conversation documentation topic.