Tuesday 30 May 2017

How to make MS Bot Framework on Node.js wait for the user's next message?

I am trying to write my first bot using Node.js and MS Bot Framework. From the examples provided by Microsoft, I can't figure out how to achieve this scenario:

  1. Bot sends a message to the user.
  2. Bot waits for the user's answer.
  3. Bot runs another function to process this answer.

The examples have this code:

        if (!item.size) {
            // Prompt for size
            builder.Prompts.choice(session, "What size would you like?", "Small|Medium|Large|Extra Large");
        } else {
            //Skip to next waterfall step
            next();
        }

The first method (builder.Prompts.choice()) achieves what I want, but I don't want to use the ugly built-in prompts. I'd rather just do it manually (send message to user, offer options, wait for response).

The second method (next()) just skips to the next step without waiting for the user's input.

I have a dialog created like this:

bot.dialog('name', [function 1() {}, function 2() {}]);

So I just want to find a way so that function 1 outputs a message and waits for the user input, then moves on to function 2.



via K48

No comments:

Post a Comment