【问题标题】:Quick Replies in Webchat- Bot Framework (Nodejs)Webchat 中的快速回复- Bot Framework (Nodejs)
【发布时间】:2017-11-22 14:29:46
【问题描述】:

Messenger 为机器人提供快速回复按钮,如图所示here

但是,我有兴趣在 Microsoft Bot Framework 聊天界面上获得相同的信息。我想出了一个 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()

【问题讨论】:

    标签: c# node.js botframework node-modules facebook-chatbot


    【解决方案1】:

    有一个sample in the botbuilder repo 证明了这一点。下面是一个sn-p:

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

    【讨论】:

    • 非常感谢。按钮可以是圆形的吗?
    • 另外,如何在单击选项之一时将消息发送到 LUIS?
    • 在下一个瀑布步骤中,您可以通过回调调用LuisRecognizer.regognize(utterace, modelUrl)。要获取 imBack 的内容,您可能需要先调用 results.response,如果 imBack 内容不存在,请检查响应对象的其余部分。
    • 我没有完全理解。你能帮我写一段与此相关的示例代码吗?
    • 我在控制台中看到以下内容,正在打印结果 .BotBuilder:prompt-choice - Prompt.returning([object Object]) .BotBuilder:prompt-choice - Session.endDialogWithResult() / - Session.endDialogWithResult() Session.sendBatch() 发送 0 条消息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多