如何解决Dialogflow/Google Actions 实现使用 Google App Engine 和存储返回错误 4:DEADLINE EXCEEDED,尽管很简单
假设我想创建一个简单的 Action,它从代码列表(.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);
解决方法
让我的应用侦听端口 4444
,但 App Engine 需要侦听端口 8080
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。