【问题标题】:Dialogflow/Google Actions fulfillment (using Google App Engine & Storage) returning error 4: DEADLINE EXCEEDED, despite being simpleDialogflow/Google Actions 实现(使用 Google App Engine 和存储)返回错误 4:DEADLINE EXCEEDED,尽管很简单
【发布时间】:2021-01-12 18:34:16
【问题描述】:

假设我想创建一个简单的操作,为用户提供来自代码列表(.csv 文件中的字符串)的随机代码。我目前设置的是在 Google App Engine 上运行的 Dialogflow 代理,我使用 Google Storage 存储了“codes.csv”文件。

我成功读取文件的代码(我让它记录第一个代码作为检查),但是,当返回对 Dialogflow 的响应时,我收到“Webhook 调用失败。错误:DEADLINE_EXCEEDED。”

我了解对 Dialogflow/Google Actions 的响应不能超过 10 秒才能完成,但从我从日志中收集的信息来看,它已在 3 秒内读取了相对较小的 code.csv。我不明白是什么导致了卡顿...

在 Google App Engine 上运行的代码:

const express = require('express');
const bodyParser = require('body-parser');
const csv = require('csv-parser');

const { WebhookClient } = require('dialogflow-fulfillment');
const {dialogflow} = require('actions-on-google');
const app = dialogflow({debug: true});

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket('<bucket name>');
const file = bucket.file('codes.csv');

let codes = [];

file.createReadStream()
    .pipe(csv())
    .on('error', function(err) {
        console.log('woops');
    })
    .on('data', function(response) {
        codes.push(response);
    })
    .on('end', function() {
        console.log('read csv');
        console.log(codes[0]['code']); // checks whether 'codes' actually contains the codes
    });

function randomCode() {
    return codes[Math.floor(Math.random()*codes.length)]['code'];
}

app.intent('Default Welcome Intent', (conv) => {
    console.log(codes[1]['code']);
    conv.ask('Hey, here is your random code: ' + randomCode());
    console.log(codes[2]['code']);
});  // neither of the two console.log are reached here

const expressApp = express().use(bodyParser.json());
expressApp.post('/', app);
expressApp.listen(4444);

【问题讨论】:

  • 我假设这段代码在 App Engine 中运行。那么,该应用程序在端口4444 中运行吗?我问这个是因为 App Engine 期望应用程序侦听端口 8080。此外,这似乎有点令人困惑,您能否添加更多详细信息或编辑问题以使其更清楚?
  • @YeriPelona,我不知道 App Engine 需要应用程序在端口 8080 上进行侦听,哎呀 ????我改变了它,现在一切正常,谢谢!至于问题本身,Dialogflow/Google Actions 没有从我的 Webhook 获得响应(由于端口错误)并导致 DEADLINE_EXCEEDED 错误。这让我觉得我的代码有问题,导致处理时间过长(Dialogflow 有 10 秒的 Webhook 响应截止日期)。

标签: node.js google-app-engine google-cloud-storage actions-on-google dialogflow-es-fulfillment


【解决方案1】:

让我的应用监听端口 4444,但 App Engine 需要监听端口 8080

【讨论】:

    猜你喜欢
    • 2020-02-07
    • 1970-01-01
    • 1970-01-01
    • 2018-11-03
    • 2020-12-09
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多