1

In Dialogflow, i use the free edition (V2) with the blaze plan from Firebase. I have an Intent that works on the word "test". When i enter "test" in the simulator, the chatbot gives an non response and leaves the chat. It is suppose to make an call to my API and retrieves information.

The weird part is, there is a console.log that prints out the body and that returns the JSON from the API. So that means the API call works fine, but there is still an error somewhere within the bot.

I found this question: Dialogflow v2 error “MalformedResponse 'final_response' must be set”

It looks alot like my problem, yet i cant seem to figure out what i should change to make mine work.

Thanks in advance for your time.

The Fulfullment:

function testcommand(agent) {
  callNPApi().then((output) => {
    agent.add(output);
  }).catch(() => {
    agent.add("That went wrong!");
  });
}

function callNPApi() {
  return new Promise((resolve, reject) => {
    request2(url, function (error, response2, body){
      //The substring is too ensure it doesnt crash for the character limit yet
      body = body.substring(1,10);
      console.log('Api errors: ' + JSON.stringify(error));
      console.log('Api body: ' + JSON.stringify(body));

      if (error) {
        reject();
      }
      resolve('api call returned: ');
    });
  });
}

The Response in the console:

{
  "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\":\"bca7bd81-58f1-40e7-a5d5-e36b60986b66\",\"timestamp\":\"2018-09-06T12:45:26.718Z\",\"lang\":\"nl\",\"result\":{},\"alternateResult\":{},\"status\":{\"code\":200,\"errorType\":\"success\"},\"sessionId\":\"ABwppHFav_2zx7FWHNQn7d0uw8B_I06cY91SKfn1eJnVNFa3q_Y6CrE_OAJPV-ajaZXl7o2ZHfdlVAZwXw\"}"
        }
      ]
    }
  }
}

The Error in the console:

MalformedResponse
'final_response' must be set.
Prisoner
  • 49,922
  • 7
  • 53
  • 105
Michael
  • 83
  • 1
  • 9
  • 1
    Is your api client async? SDK think everything is done and that response was not set. Try to return promise – Mistic92 Sep 06 '18 at 19:18

1 Answers1

2

Yup, this is the same problem.

The issue is that you're returning a Promise from callNPApi(), but your event handler (which I assume is testcommand()) isn't also returning a Promise. If you are doing async calls anywhere in your handler, you must use a Promise, and if you are using a Promise you must also return that Promise from the handler.

In your case, this should be a simple change. Simply add "return" to your handler. So it might look something like this

function testcommand(agent) {
  return callNPApi().then((output) => {
    agent.add(output);
  }).catch(() => {
    agent.add("That went wrong!");
  });
}
Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • Thank you for your time. I really appriciate it that you took the extra time to explain why it wasn't working with my code example! – Michael Sep 06 '18 at 15:10