0

I try to work with dialogflow and webhook. Everythink works until I add a http request. I have the following error :

MalformedResponse 'final_response' must be set.

Here is my code :

function askMovie (response) {
  return new Promise((resolve, reject) => {
    // resolve("THIS ONE WORKS if I comment the http.get");

    http.get('http://www.omdbapi.com/?apikey=[MY_HIDDEN_API_KEY]&s=lego', res => {
       let raw = '';
       res.on('data', chunk => raw += chunk);
       res.on('end', () => {
          resolve("OK");
        });
       res.on('error', (error) => {
          reject(error);
       });

    });
  });
}

exports.dialogflowWebhook = functions.https.onRequest((request, response) => {
  askMovie(response).then((output) =>{
    response.json({ fulfillmentText: 'Request Success' });
  }).catch((error) => {
    response.json({ fulfillmentText: 'No movies' });
  })
});

I tried others samples but it's always the same error.

The response when it failed :

{
  "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\":\"fdcfc60e-8da3-42cc-84a8-a5de5f4accf8\",\"timestamp\":\"2018-05-03T13:46:26.646Z\",\"lang\":\"fr-fr\",\"result\":{},\"status\":{\"code\":206,\"errorType\":\"partial_content\",\"errorDetails\":\"Webhook call failed. Error: 500 Internal Server Error\"},\"sessionId\":\"1525354490725\"}"
        }
      ]
    }
  }
}

I use firebase functions for my webhook.

Alex R.
  • 861
  • 1
  • 13
  • 28
  • 1
    Make sure you're on the Firebase paid tier for outbound requests. See [here](https://stackoverflow.com/questions/43415759/use-firebase-cloud-function-to-send-post-request-to-non-google-server) – lukedavis May 04 '18 at 15:45
  • That's it lukedavis. First I had to remove the http:// and second I am on the spark plan. Thank you ! – Alex R. May 07 '18 at 07:44

1 Answers1

0

Your missing your "fulfillment.speech" Json element. Verify this on your server log. A default speech response is required.

"fulfillment": {
  "speech": "Nice to meet you, Sam!"
},

https://developers.google.com/actions/reference/v1/dialogflow-webhook