# #javascript #dialogflow-es
Вопрос:
Я создал API, который принимает пользовательский ввод и обрабатывает его. Однако процесс занимает более 5 секунд (ограничение на диалоговый поток).
Как я могу продолжать другие процессы до тех пор, пока этот определенный процесс не будет завершен?
Или можно ли вернуть пользователю какие-либо сообщения, такие как «Пожалуйста, подождите немного…», чтобы он мог перезапустить время.
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);
})
});
}
Ценю вашу помощь
Ответ №1:
- Да, можно вернуть пользователю любые сообщения, такие как «Пожалуйста, подождите немного…», настроив последующее событие.
- Вы можете продлить ограничение на 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);