简体   繁体   English

如何使用英雄卡从卡按钮获取响应值

[英]How can i get the response value from card buttons using hero card

I'm building a chat bot for products. 我正在为产品构建聊天机器人。 I have a long list of products (each product display as card with the name only). 我的产品清单很长(每个产品都显示为带有名称的卡)。 I want the user to choose from the list which works fine but my issue is saving the data when the user is clicking on the product card. 我希望用户从工作正常的列表中进行选择,但是我的问题是当用户单击产品卡时保存数据。 I don't see the data, any idea? 我看不到数据,知道吗?

var inMemoryStorage = new builder.MemoryBotStorage();

var bot = new builder.UniversalBot(connector, function (session) {
    session.replaceDialog('chooseProduct');

}).set('storage', inMemoryStorage);


bot.dialog("chooseProduct",

(session)  => {
    var card = new builder.HeroCard(session)
    .title('Hey there!')
    .subtitle("What would you like to buy?")
        .buttons([
            builder.CardAction.imBack(session, "iPhone6-16GB", "iPhone6"),
            builder.CardAction.imBack(session, "iPhone6-32GB", "iPhone6"),
            builder.CardAction.imBack(session, "iPhone6-64GB", "iPhone6"),
            builder.CardAction.imBack(session, "iPhone6-128GB", "iPhone6"),
            builder.CardAction.imBack(session, "iPhone7-16GB", "iPhone6"),
            builder.CardAction.imBack(session, "iPhone7-32GB", "iPhone6"),
            builder.CardAction.imBack(session, "iPhone7-64GB", "iPhone6"),
            builder.CardAction.imBack(session, "iPhone7-128GB", "iPhone6"),

        ]);
    var msg = new builder.Message(session)
        .addAttachment(card)
        .inputHint(builder.InputHint.acceptingInput);
    session.send(msg).endDialog();
}

).triggerAction({matches: /Help|Hi|hi|Hey|menu|Menu/g});

bot.dialog('selectedProduct, 
    (session,results)=>{
        // I'm trying to save the data
        var selectedIphone = results.response.entity // Sadly this does not store it, but this is what I'm trying to get
    }    
).triggerAction({matches: /iPhone/g});

You can just get the message text from the response with 'session.message.text'. 您可以使用“ session.message.text”从响应中获取消息文本。

bot.dialog('selectedProduct', 
     (session)=>{
        // I'm trying to save the data
        var selectedIphone = session.message.text;
    }    
).triggerAction({matches: /iPhone/g});

For a more universal solution, have a look at the middleware capabilities illustrated here: 有关更通用的解决方案,请查看此处说明的中间件功能:

https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/capability-middlewareLogging/app.js https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/capability-middlewareLogging/app.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM