首页 文章

如何在Dialogflow / Api.ai中管理5秒响应超时限制?

提问于
浏览
1

我正在使用Dialogflow创建一个代理/机器人,它响应不同类型的用户查询,其中包含“我需要从HR获取地址证明的信件”等操作项 . 这需要机器人从公司的数据库中获取一些信息,并通过在人力资源提供的模板化字母文件中填充检索到的信息来生成文档/字母 . 执行此操作的逻辑已经写在python文件中 . 使用Webhooks完成数据库集成 .

问题是,解释用户请求,打开数据库和检索所需信息的完整过程需要5秒以上,这恰好是Dialogflow代理的响应超时限制 . 我对此做了一些研究,发现我们不能增加这个限制,但我们可以通过异步调用保持会话存活 . 我无法找到提供答案的正确资源 .

所以,我的问题是 -

我们可以在对话框流中进行异步调用吗?

如果是,那么我们如何通过json将异步数据发送到Dailogflow代理?

有没有其他方法可以解决这个5秒响应超时限制?

提前致谢!

2 回答

  • 6

    我刚检查了Actions on Google documentationFulfillment documentation页面,确实有5秒的超时限制 .

    这可能不是最好的解决方案,可能不适合您的情况,但考虑到给定严格的5秒窗口(我们希望确保动态对话,而不会让用户等待太长时间)

    您以异步方式使用第一个意图开始计算,然后返回给用户并告诉他们在几秒钟内请求结果,同时计算完成时 . 它将保存在用户的私有空间中,此时用户将触发第二个意图,该意图将请求同时预先计算的结果,因此您可以获取并返回它们 .

  • 2

    您可以通过设置多个后续事件将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);
    

    要了解有关自定义活动的更多信息,请访问此页:https://dialogflow.com/docs/events/custom-events

相关问题