【问题标题】:Webhook call failed. Error: DEADLINE_EXCEEDEDWebhook 调用失败。错误:DEADLINE_EXCEEDED
【发布时间】:2020-01-27 10:45:40
【问题描述】:

我在内联编辑器中编写了 webhook 函数。 我间歇性地收到超出期限的错误。 所有因超过期限而失败的 webhook 都有 webhook_latency_ms : 4992ms 在 Dialogflow 文档 (https://cloud.google.com/dialogflow/docs/fulfillment-how) 中提到默认超时为 5 秒,因此我的 webhook 不应抛出此错误,因为它在 5 秒内。

webhook 有一个非常简单的代码,不会超过 20-30 毫秒。 大多数时候,同一个函数有 webhook_latency_ms: 小于 50ms。 哪些因素会导致延迟增加?

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function testHandler(agent) { 
    let pendingHabits = agent.getContext('pendinghabits').parameters.habits; 
    let message = "Ok, let me know when you complete these habits:"; 
    for (let i = 0; i < pendingHabits.length; i++) { 
        message = message + "\n" + pendingHabits[i]; 
    } 
    let payload = { 
        type: 'message', 
        isPositive: false, 
        messages: [{ type: 0, text: message }] 
    }; 
    agent.add(new Payload(agent.UNSPECIFIED, payload)); 
}})

【问题讨论】:

  • 你能用代码更新吗
  • 此外,firebase 日志显示函数执行耗时 1911 毫秒,完成状态码为:200,webhook 延迟为 4992 毫秒。这很混乱。
  • 请更新有问题的不可读

标签: dialogflow-es


【解决方案1】:

您缺少处理程序调用,因为我可以看到您提供的代码,

const functions = require('firebase-functions');
const {WebhookClient, Card, Suggestion} = require('dialogflow-fulfillment');

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, res) => {
  const agent = new WebhookClient({ req, res });

  function intentHandler(agent) {
    agent.add('This message is from Dialogflow\'s Cloud Functions for Firebase editor!');
    agent.add(new Card({
        title: 'Title: this is a card title',
        imageUrl: 'https://developers.google.com/actions/assistant.png',
        text: 'This is the body text of a card.  You can even use line\n  breaks and emoji! ?',
        buttonText: 'This is a button',
        buttonUrl: 'https://assistant.google.com/'
      })
    );
    agent.add(new Suggestion('Quick Reply'));
    agent.add(new Suggestion('Suggestion'));
  }

  agent.handleRequest(intentHandler);
});

【讨论】:

    猜你喜欢
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 2019-10-25
    • 2020-05-27
    • 2021-01-07
    • 1970-01-01
    相关资源
    最近更新 更多