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



我已经创建了一个接受用户输入并对其进行处理的API。然而,该过程需要超过5秒(dialogflow limit)。

我怎样才能继续其他进程直到这个进程完成?

或者是否可以向用户返回类似"请稍等……"之类的信息?所以它可以重新开始计时。

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

感谢您的帮助

  • 是的,可以向用户返回诸如"请稍等"之类的消息。
  • 您可以通过设置多个后续事件将5秒意图限制扩展到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);

最新更新