-1

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);
  • I assume this code is running in App Engine. So, the app is running in port `4444`? I ask this since App Engine expects the app to listen on port `8080`. In addition it seems kind of confusing, could you please add more details or edit the question to make it more clear? – Puteri Jan 20 '21 at 00:14
  • @YeriPelona, I did not know App Engine needs the app to be listening on port 8080, woops I changed that and now everything works, thanks! As for the question itself, Dialogflow/Google Actions was not getting a response from my Webhook (due to the wrong port) and resulted in a DEADLINE_EXCEEDED error. This made me think that something was wrong with my code, making it take too long (Dialogflow has a 10 sec deadline for Webhook responses). – Giorgie Goiati Jan 22 '21 at 14:17

1 Answers1

0

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