2

I'm trying to use add.agent to take the updated message variable from the uiFx function. However, there is an issue with both the await function and the add.agent together.

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);
    })
  });
}

What seems to be the problem and how to fix it?

Appreciate your help

Mounir
  • 41
  • 7

1 Answers1

0

I found out that the problem is uiFx() is taking more than 5 seconds to finish the task (dialogflow limit- 5 seconds). This code works fine but it needs to wait more than the limit amount to execute correctly.

Mounir
  • 41
  • 7