【问题标题】:Dialogflow adding dynamic text is not working with promise and async functionDialogflow 添加动态文本不适用于 Promise 和异步功能
【发布时间】:2021-07-26 10:14:11
【问题描述】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 2019-01-02
      • 1970-01-01
      • 2017-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多