0

I wrote a little js file that returns departure of public transport. This is what I expect:

const dvb = require("dvbjs");

dvb.findStop("NUP").then((data) => {
    console.log( "Abfahrten für "+data[0].name+ " in " +data[0].city+":" );
    dvb.monitor(data[0].id, 0, 1).then((data) => {
        for (const bus of data){
            console.log(bus.mode.title +" "+ bus.line+" Richtung "+bus.direction+ " in "+bus.arrivalTimeRelative+ " Minuten.")
        }
    });
});

The output on my console looks like this:

Abfahrten für Nürnberger Platz in Dresden:
Straßenbahn 8 Richtung Hellerau in 3 Minuten.

This is fine. Now I changed it, so Google Assistant can read the outputs:

app.intent('Haltestellenabfrage', (conv, {haltestelle}) => {
    //conv.ask("Debug 1");
    dvb.findStop("NUP").then((data) => {
        //conv.ask("Debug 2");
        conv.ask( "Abfahrten für "+data[0].name+ " in " +data[0].city+":" );
        dvb.monitor(data[0].id, 0, 1).then((data) => {
            for (const bus of data){
                //conv.ask("Debug 3");
                conv.close(bus.mode.title +" "+ bus.line+" Richtung "+bus.direction+ " in "+bus.arrivalTimeRelative+ " Minuten.");
            }
        });
    });
    //conv.ask("Debug 3");
});

When I start my Action on Google in the simulator I get the following error and no response:

{
  "responseMetadata": {
    "status": {
      "code": 10,
      "message": "Failed to parse Dialogflow response into AppResponse because of empty speech response",
      "details": [
        {
          "@type": "type.googleapis.com/google.protobuf.Value",
          "value": "{\"id\":\"bad774a2-9e35-4ced-980f-d4e75d710727\",\"timestamp\":\"2019-03-13T11:50:56.405Z\",\"lang\":\"de\",\"result\":{},\"alternateResult\":{},\"status\":{\"code\":206,\"errorType\":\"partial_content\",\"errorDetails\":\"Webhook call failed. Error: 500 Internal Server Error\"},\"sessionId\":\"ABwppHHpg1lcJFHtSSM8Pmg4gWWkjgICLeZhBuwFb_UJTXuvVyVc5jE5QWLIpGYRCQOHAVmHTzunZw\"}"
        }
      ]
    }
  }
}

Whatever I do, the part in the .then() clause is never executed by Dialogflow. I'm an absolute beginner in javascript so I don't know what else to try.

1 Answers1

0

If your Intent Handler does any asynchronous functions, then it must return a Promise that will be fulfilled when those functions are complete so the Handler Dispatcher knows to wait for the Promise to complete.

You're using Promises, but not returning them.

Since you are, you can just return the Promise with a line such as

return dvb.findStop("NUP").then((data) => {
Prisoner
  • 49,922
  • 7
  • 53
  • 105