【问题标题】:Implementation question to call external API with reply more then 5 sec调用外部 API 并回复超过 5 秒的实现问题
【发布时间】:2021-12-10 09:30:14
【问题描述】:

我使用带有语音识别功能的 Dialogflow 聊天机器人。我的目标是通过 Dialogflow 管理外部设备。外部设备可以在 30 秒到 30 分钟的时间范围内改变状态。

聊天机器人必须通过履行来考虑设备状态。根据文档,可以通过请求-响应方法来做到这一点,时间是 5 秒。在理想情况下,我假设通过套接字进行双向通信,但在 Dialogflow 中是不可能的。您能否告诉我解决方案或指出其他支持该功能的语音聊天引擎?我读到 Dialogflow CX 最多支持 30 分钟的会话,但这不是等待时间。

【问题讨论】:

    标签: dialogflow-es dialogflow-es-fulfillment dialogflow-cx


    【解决方案1】:

    您可以通过设置多个后续事件将 5 秒的 Intent 限制延长至 15 秒。目前,您只能设置一个接一个的3个后续事件。您可以将超时时间延长至 15 秒。

    在这里,您可以查看有关custom events 的更多文档。

    以下是如何在履行中心执行此操作的示例:

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

    在这里,您可以查看有关 Webhook serviceFulfillment 的更多文档。

    【讨论】:

    • 非常感谢您的回复!我已经知道这个技巧,但我的想法是将时间延长到 30 分钟。使用#Dialogflow 的端到端解决方案可能是不可能的。
    • 也许这些会对你有所帮助。恢复上一个会话状态。 cloud.google.com/dialogflow/cx/docs/concept/…
    • 感谢您提供的信息。我以前看过它,但没有详细注意它是如何工作的。现在重读 2-3 遍,希望对我有所帮助。
    猜你喜欢
    • 2019-06-23
    • 2019-11-20
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多