我正在为产品构建聊天机器人。我有很长的产品清单(每个产品只显示名称的卡片)。我希望用户从列表中选择工作正常但我的问题是在用户点击产品卡时保存数据。我没有看到数据,有什么想法吗?
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});
答案 0 :(得分:0)
您可以使用' session.message.text'从响应中获取消息文本。
bot.dialog('selectedProduct',
(session)=>{
// I'm trying to save the data
var selectedIphone = session.message.text;
}
).triggerAction({matches: /iPhone/g});
要获得更通用的解决方案,请查看此处所示的中间件功能:
https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/capability-middlewareLogging/app.js