Быстрые ответы в Webchat- Bot Framework (Nodejs)

голоса
1

Коммуникатор обеспечивает быстрые кнопки ответа для бот , как показано здесь

Тем не менее, я был заинтересован, чтобы получить то же самое на Microsoft Bot Framework Chat интерфейс. Я понял, метод C # для выполнения той же, которая, как показано ниже:

  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 }
    }
};

Как я могу осуществить то же самое в Nodejs?

Обновленный код:

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 не работает. Я вижу ниже в командной строке.

.BotBuilder:prompt-choice - Prompt.returning([object Object])
.BotBuilder:prompt-choice - Session.endDialogWithResult()
/ - Session.endDialogWithResult()
Задан 22/11/2017 в 14:29
источник пользователем
На других языках...                            


1 ответов

голоса
1

Существует образец в botbuilder репо , который демонстрирует это. Ниже приведен фрагмент кода:

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
        })
    },

]);
Ответил 22/11/2017 в 17:07
источник пользователем

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more