如何在等待超过时间限制的过程时使对话流继续进行?

How to make dialogflow going while waiting for a process that takes more than the time limit?

我创建了一个 API 来接受用户输入并对其进行处理。但是,该过程需要超过 5 秒(对话流限制)。

在这个特定过程完成之前,我如何才能继续其他过程?

或者是否可以 return 向用户发送任何消息,例如“请稍等...”,以便重新开始计时。

var message = "hi"; //test purpose
async function GetCertain_info(agent) {

  await uiFx(); 
  agent.add("Here are the information on " + message);
}

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

感谢您的帮助

  • 是的,可以通过设置 FollowupEvent.
  • 向用户 return 发送任何消息,例如“请稍等……”
  • 您可以通过设置多个后续事件将 5 秒的 Intent 限制延长至最多 15 秒。目前最多只能设置3个后续事件(最多可延长超时15秒)。

以下是您如何在履行中执行此操作的示例:

function function1(agent){
      //This function handles your intent fulfillment
      //you can initialize your db query here.
      //When data is found, store it in a separate table for quick search
      
      //get current date
      var currentTime = new Date().getTime(); 
      
      while (currentTime + 4500 >= new Date().getTime()) {
        /*waits for 4.5 seconds
          You can check every second if data is available in the database
          if not, call the next follow up event and do the 
          same while loop in the next follow-up event 
          (up to 3 follow up events)
        */
        
         /* 
         if(date.found){
            agent.add('your data here');//Returns response to user
         }
          */
        
      } 
      
      //add a follow-up event
      agent.setFollowupEvent('customEvent1'); 
      
      //add a default response (in case there's a problem with the follow-up event)
      agent.add("This is function1");
  }


  let intentMap = new Map();
  intentMap.set('Your intent name here', function1);;
  agent.handleRequest(intentMap);