Microsoft BotFramework - suggested maps

So I'm trying to use the suggested maps to give a more convenient button input for the WebChat bot, in case anyone has no other suggestions? You currently have a builder. Operation works.

but my problem is the following example:

var msg = new builder.Message(session)
    .text("Thank you for expressing interest in our premium golf shirt! What color of shirt would you like?")
    .suggestedActions(
        builder.SuggestedActions.create(
                session, [
                    builder.CardAction.imBack(session, "productId=1&color=green", "Green"),
                    builder.CardAction.imBack(session, "productId=1&color=blue", "Blue"),
                    builder.CardAction.imBack(session, "productId=1&color=red", "Red")
                ]
            ));
session.send(msg);

      

How can I get an answer? It automatically writes the value of users to chat (which I am trying to avoid) Tried using response.entity etc. but returns nothing.

The documentation says: "When the user removes one of the suggested actions, the bot will receive a message from the user that contains the value of the corresponding action."

Thank.

+3


source to share


1 answer


Several things for this.

First, it imBack

basically means an IM callback or instant message. He will send a reply to the conversation. You want postBack

one that will hide the answer, but keep in mind that some channels postBack

will show up imBack

, so you will need to do some investigation. For the emulator, the bot postBack

will hide the answer.

Second, if you watch the console when starting the bot, you will see that the bot will try to navigate to this value in the method imBack

. You will want to capture this through dialogue or intent. Here's a small, probably ineffective example:



intents.matches(/^suggest/i, [(session) => {
    var msg = new builder.Message(session)
        .text("Thank you for expressing interest in our premium golf shirt! What color of shirt would you like?")
        .suggestedActions(
            builder.SuggestedActions.create(
                    session, [
                        builder.CardAction.postBack(session, "productId=1&color=green", "Green"),
                        builder.CardAction.postBack(session, "productId=1&color=blue", "Blue"),
                        builder.CardAction.postBack(session, "productId=1&color=red", "Red")
                    ]
                ));
        session.send(msg);
}]);

intents.matches(/^productId/i, [
    (session, args, next) => {
        console.log(args);
    }
]);

      

In the example above, which uses intent dialogs, I can access the value from the array matched

that is in the arguments of the second method call intent.matches

.

There are other ways to do this, but this is a quick and dirty example.

+4


source







All Articles