1

Messenger provides quick reply buttons for the bots as shown here

However, I was interested to get the same on Microsoft Bot Framework Chat Interface. I figured out a C# method for doing the same which is as below:

  var reply = activity.CreateReply("Hi, do you want to hear a joke?");
   reply.Type = ActivityTypes.Message;
reply.TextFormat = TextFormatTypes.Plain;

reply.SuggestedActions = new SuggestedActions()
{
    Actions = new List<CardAction>()
    {
        new CardAction(){ Title = "Yes", Type=ActionTypes.ImBack, Value="Yes" },
        new CardAction(){ Title = "No", Type=ActionTypes.ImBack, Value="No" },
        new CardAction(){ Title = "I don't know", Type=ActionTypes.ImBack, Value="IDontKnow" }
    }
};

How can I implement the same in Nodejs?

Updated code:

getMyID(session, args){var msg = new builder.Message(session)
            .text("Let me know the date and time you are comfortable with..")
            .suggestedActions(
                builder.SuggestedActions.create(
                    session,[
                        builder.CardAction.imBack(session, "green", "green"),
                        builder.CardAction.imBack(session, "blue", "blue"),
                        builder.CardAction.imBack(session, "red", "red")
                    ]
                )
            );
        builder.Prompts.choice(session, msg, ["green", "blue", "red"]), function(session, results) {
          console.log(results);
        session.send('I like ' +  results + ' too!');
    }}

How to take response from the choices and send message to user from inside this function (the current callback function is not being triggered)? 

Console.log is not working. I am seeing the below in command prompt.

.BotBuilder:prompt-choice - Prompt.returning([object Object])
.BotBuilder:prompt-choice - Session.endDialogWithResult()
/ - Session.endDialogWithResult()
CTD
  • 43
  • 1
  • 5

1 Answers1

0

There is a sample in the botbuilder repo That demonstrates this. Below is a snippet:

var restify = require('restify');
var builder = require('../../core/');

// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
   console.log('%s listening to %s', server.name, server.url); 
});

// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());

bot.use(builder.Middleware.dialogVersion({ version: 1.0, resetCommand: /^reset/i }));

bot.dialog('/', [
    function (session) {

        var msg = new builder.Message(session)
            .text("Hi! What is your favorite color?")
            .suggestedActions(
                builder.SuggestedActions.create(
                    session,[
                        builder.CardAction.imBack(session, "green", "green"),
                        builder.CardAction.imBack(session, "blue", "blue"),
                        builder.CardAction.imBack(session, "red", "red")
                    ]
                )
            );
        builder.Prompts.choice(session, msg, ["green", "blue", "red"]);
    },
    function(session, results) {
        builder.LuisRecognizer.recognize(results.response.entity,"Model URL", function(error, intents, entities){
                //your code here
        })
    },

]);
D4RKCIDE
  • 3,439
  • 1
  • 18
  • 34
  • Thanks a ton. Can the buttons be round? – CTD Nov 22 '17 at 17:40
  • Also, how to send the message to LUIS on clicking one of the options? – CTD Nov 22 '17 at 17:43
  • in the next waterfall step you could call `LuisRecognizer.regognize(utterace, modelUrl)` with a callback. to get the contents of the imBack you might want to call `results.response` first, and if the imBack contents is not there check the rest of the response object. – D4RKCIDE Nov 22 '17 at 18:07
  • I did not understand it completely. Can you help me with a sample piece of code related to this? – CTD Nov 22 '17 at 18:09
  • I am seeing the following in my console, results are getting printed .BotBuilder:prompt-choice - Prompt.returning([object Object]) .BotBuilder:prompt-choice - Session.endDialogWithResult() / - Session.endDialogWithResult() Session.sendBatch() sending 0 message(s) – CTD Nov 22 '17 at 18:13
  • I've added code to help you send the value to LUIS, that should help – D4RKCIDE Nov 22 '17 at 18:46
  • Thanks a ton. I have updated my last problem. I have to just take these results and say a confirmation Statement. The code already has a callback but it is not working. – CTD Nov 23 '17 at 18:04