【发布时间】:2019-08-27 17:55:16
【问题描述】:
我正在尝试将一个属性(位于对象数组的第一个位置内)传递给另一个模块,以便以后可以使用该值。我尝试将它作为模块(args)传递,但它一直在读取默认值 0。有没有办法做到这一点?
我尝试实现一些React.context,但 Bot 框架 Emulator 拒绝它。
/////////////////Module that ll acquire the value/////////////////////////////
getCard(bot, builder, params) {
let configValues = { ...params[0] }
bot.dialog(`${configValues.path}`, function (session) {
var msg = new builder.Message(session);
const cardItem = (obj) => {
return (new builder.HeroCard(session)
.title(`${obj.title}`)
.text(`R$ ${obj.price}`)
.images([builder.CardImage.create(session, `${obj.img}`)])
.buttons([
builder.CardAction.imBack(session, `${obj.price} Item adicionado!`, 'add to cart')
// !onClick event must add the current obj.price to
// the configValues.total(Ex: configValues.total += obj.price)!
])
)
}
msg.attachmentLayout(builder.AttachmentLayout.carousel)
msg.attachments(
eval(params.map(obj => cardItem(obj)))
);
//!in here before end the dialog is where i want to update
// the configValues.total so i can show it in the -> Checkout module
session.send(msg).endDialog()
}).triggerAction({ matches: configValues.regex });
}
}
//////////////CheckOut.Module///////////////////////////////
{...}
let configValues = { ...params[0] }
let state = {
nome: "",
endereco: "",
pagamento: "",
total: configValues.total // this is the value to be read
}
bot.dialog('/intent', [
{...},
(session, results) => {
state.pagamento = results.response
session.send(
JSON.stringify(state) // here is the place to be printed
)
{...}
]
).triggerAction({ matches: /^(finalizar|checar|encerrar|confirmar pedido|terminar)/i })
【问题讨论】:
-
你能解释一下发生了什么吗?默认值在哪里设置?错误发生在哪里?模拟器给出了什么错误?
-
您可以共享的代码越多越好。我真的看不出您的 CheckOut 模块是如何被调用的,或者大部分代码是如何相互作用的。
-
我已经用一种完全不同的策略解决了部分问题,现在这个值确实在传递,但在其他方面我必须根据触发的匹配创建另一个 bot.dialog()一个 postBack() ,其中将存储由 bot.dialog() 上的 results.response 捕获的给定值并将其推送到价格数组中,然后我从单个 cardBox 计算总数,但新问题是汇总所有被点击的 CardBox [GitHub] (github.com/VyTorBrB/botTalk)
标签: javascript node.js azure botframework bots