【发布时间】:2021-07-26 10:14:11
【问题描述】:
我正在尝试使用 add.agent 从 uiFx 函数中获取更新后的消息变量。但是,both await 函数和 add.agent 一起存在问题。
var message = "hi"; //test purpose
async function GetCertain_info(agent) {
console.log("1" + message);
await uiFx(); *//this works fine in the console.log, and it updates the message*
console.log("2" + message);
agent.add("Here are the information on " + message);*//this works when the await uiFx() is removed and the message variable is returned as its initial value "hi"*
}
async function uiFx() {
var {
ui
} = require('./uia.js');
return new Promise(function(resolve, reject) {
ui().then((msg) => {
console.log("Destination Message : " + msg)
message = msg;
resolve(message);
}).catch((msg) => {
console.log(msg)
message = msg;
reject(message);
})
});
}
似乎是什么问题以及如何解决?
感谢您的帮助
【问题讨论】:
标签: javascript node.js async-await dialogflow-es-fulfillment