How to manage the 5 seconds response timeout limit in Dialogflow / Api.ai?

前端 未结 3 1072
误落风尘
误落风尘 2020-12-10 13:44

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 proo

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 14:12

    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

提交回复
热议问题