问题
I am using Dialogflow to create an agent / bot which responds to different types of user queries with action items like "I need to get a letter from the HR for address proof". This needs the bot to fetch some information from the company's database and generate a document / letter by populating that retrieved information in a templated letter file provided by the Human Resource. The logic to do this action is already written in a python file. The database integration is done using Webhooks.
The problem is that this complete process of interpreting the user's request, opening the database and retrieving the required information takes more than 5 seconds, which happens to be the response timeout limit for Dialogflow agents. I have done some research on this and found out that we cannot increase this limit but we can keep the session alive through asynchronous calls. I am not able to find the right resource which provides the answer.
So, my questions are-
Can we make asynchronous calls in dialogflow?
If yes, then how do we send asynchronous data through json to Dailogflow agent?
Is there any other way to tackle this 5 seconds response timeout limit?
Thanks in advance!
回答1:
I have just checked the Actions on Google documentation and the Fulfillment documentation pages, and indeed there is a 5-second timeout limit.
This may not be the nicest of the solutions and may not fit your case, but considering the given the strict 5-second window (we want to ensure a dynamic conversation without risking the user waiting for too long)
You start the computation with your first intent asynchronously and go back to the user and tell them to request the results in a few seconds, in the meantime when the computation is completed. It will be saved in a private space for the user, at which point the user will trigger a second intent that will request the results that in the meantime will have been pre-computed, so you can just fetch and return them.
回答2:
You can extend the 5-second Intent limit up to 15 seconds by setting up multiple follow up events. Currently, you can only set up 3 follow-up events one after another (which can extend the timeout up to 15 seconds).
Here's an example of how you can do it in the fulfillment center:
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);
To learn more about custom events please visit this page: https://dialogflow.com/docs/events/custom-events
来源:https://stackoverflow.com/questions/51840301/how-to-manage-the-5-seconds-response-timeout-limit-in-dialogflow-api-ai