javascript - Dialogflow 添加动态文本不适用于 Promise 和异步功能
问题描述
我正在尝试使用add.agent从uiFx函数中获取更新的消息变量。但是,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);
})
});
}
似乎是什么问题以及如何解决?
感谢你的帮助
解决方案
我发现问题是 uiFx() 需要超过 5 秒才能完成任务(对话框流限制 - 5 秒)。此代码工作正常,但它需要等待超过限制数量才能正确执行。
推荐阅读
- angular - Angular Spring Boot 无法正确地将变量传递给端点
- karate - 空手道加特林:将 uriPatterns 列表添加到 karateProtocol()
- python - 将存在插件交换绑定到另一个交换不会产生任何消息
- python - 如何从列表列表中选择元素的滑动窗口?
- java - 如何使用 CrudRepository 将修改后的数据追加到数据库中,而不是替换 SpringBoot 中的数据
- python - 将嵌套的 mongoDB 文档转换为平面 pandas DataFrame(对象数组中的对象数组)
- jenkins - Jenkins - 与 copyArtifacts、NotSerializableException WorkflowJob 共享库
- ruby-on-rails - 无法生成 OpenSSL::PKey 对象
- git - git rebase squash 搞乱了分支历史
- django - Weblate 设置用于密码重置的 SES 电子邮件