首页 > 解决方案 > Dialogflow 添加动态文本不适用于 Promise 和异步功能

问题描述

我正在尝试使用add.agentuiFx函数中获取更新的消息变量。但是,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);
    })
  });
}

似乎是什么问题以及如何解决?

感谢你的帮助

标签: javascriptnode.jsasync-awaitdialogflow-es-fulfillment

解决方案


我发现问题是 uiFx() 需要超过 5 秒才能完成任务(对话框流限制 - 5 秒)。此代码工作正常,但它需要等待超过限制数量才能正确执行。


推荐阅读