Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

node.js - Dialogflow/Google Actions fulfillment (using Google App Engine & Storage) returning error 4: DEADLINE EXCEEDED, despite being simple

So let's say I want to create a simple Action that provides the user with a random code from a list of codes (strings in a .csv file). What I currently have set up is a Dialogflow agent with fulfillment running on Google App Engine and I stored the 'codes.csv' file using Google Storage.

The code I have succefully reads the file (I have it log the first code as a check), however, when it comes to returning a response to Dialogflow, I get a "Webhook call failed. Error: DEADLINE_EXCEEDED."

I understand that responses to Dialogflow/Google Actions can't take longer than 10 seconds to complete, but from what I gathered from the logs is that it has read the relatively small codes.csv within 3 seconds. I don't understand what causes the holdup...

The code running on 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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Had my app listen to port 4444, but App Engine needs to listen to port 8080


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...