gpt4 book ai didi

node.js - 通过在 Microsoft Bot Framework 中循环文件动态创建卡片

转载 作者:搜寻专家 更新时间:2023-11-01 00:28:59 24 4
gpt4 key购买 nike

我一直在试验 Microsoftbot.dialog('showShirts',

function (session) {
var msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.carousel)
msg.attachments([
new builder.HeroCard(session)
.title("Classic White T-Shirt")
.subtitle("100% Soft and Luxurious Cotton")
.text("Price is $25 and carried in sizes (S, M, L, and XL)")
.images([builder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/whiteshirt.png')])
.buttons([
builder.CardAction.imBack(session, "buy classic white t-shirt", "Buy")
]),
new builder.HeroCard(session)
.title("Classic Gray T-Shirt")
.subtitle("100% Soft and Luxurious Cotton")
.text("Price is $25 and carried in sizes (S, M, L, and XL)")
.images([builder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/grayshirt.png')])
.buttons([
builder.CardAction.imBack(session, "buy classic gray t-shirt", "Buy")
])
]);
session.send(msg).endDialog();
}).triggerAction({ matches: /^(show|list)/i }); bot framework in node js,
i saw this sample code in the documentation

我的问题不是手动输入 new builder.HeroCard()... 我如何创建一个循环来从 json 数组填充它?

我试过了

var obj = require("./dummy_json");
msg.attachments([
obj.shirts.forEach(function(data){
new builder.HeroCard(session)
.title(data.title)
.subtitle(data.subtitle)
.text(data.text)
.images([builder.CardImage.create(session, data.image_path)])
.buttons([
builder.CardAction.imBack(session, data.title, "Buy")
])
},this)
]);

最佳答案

问题是您正在执行循环,但似乎您没有向数组添加任何内容。

尝试这样的事情:

var attachments = [];
var obj = require("./dummy_json");

obj.shirts.forEach(function(data) {
var card = new builder.HeroCard(session)
.title(data.title)
.subtitle(data.subtitle)
.text(data.text)
.images([builder.CardImage.create(session, data.image_path)])
.buttons([
builder.CardAction.imBack(session, data.title, "Buy")
])

attachments.push(card);
},this)

msg.attachments(attachments);

关于node.js - 通过在 Microsoft Bot Framework 中循环文件动态创建卡片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45289623/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com