7

I'm trying to start working on Google Actions v2 API together with Dialgoflow v2 API.

I have the following example (so far in Dialogflow -> Fulfillment Webhook) taken from official Google Actions Migration Guide , but unfortunately I keep getting MalformedResponse 'final_response' must be set error.

'use strict';

const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');

const app = dialogflow();

app.intent('Default Welcome Intent', conv => {
  conv.ask('How are you?');
});

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

And response is:

{
  "responseMetadata": {
    "status": {
      "code": 13,
      "message": "Failed to parse Dialogflow response into AppResponse because of empty speech response",
      "details": [
        {
          "@type": "type.googleapis.com/google.protobuf.Value",
          "value": "{\"id\":\"542fe4a8-6017-429f-81c3-61ba568e3659\",\"timestamp\":\"2018-04-19T20:16:25.606Z\",\"lang\":\"en-us\",\"result\":{},\"status\":{\"code\":200,\"errorType\":\"success\"},\"sessionId\":\"1524168985362\"}"
        }
      ]
    }
  }
}

Please any idea why this can be happening?

Prisoner
  • 49,922
  • 7
  • 53
  • 105
miro
  • 809
  • 10
  • 25

1 Answers1

6

Change this line:

conv.ask('How are you?');

to this:

conv.close('How are you?');

the close method configures the required final_response field for you

mattcarrollcode
  • 3,429
  • 16
  • 16
  • 1
    thanks man, that did the trick! (have spent hours with this :) – miro Apr 19 '18 at 22:00
  • Glad I could help! I'm on the team that built the library, I'll work on making the documentation for this feature better, sorry you had troubling figuring this out. – mattcarrollcode Apr 19 '18 at 22:02
  • @matthewayne even if i use conv.close I still get the same error. I am using MediaObject though using same code [here](https://developers.google.com/actions/assistant/responses#media_responses) complete code that I am using is [here](https://gist.github.com/sherazlodhi/112e97cb881bfd38071fc386042c6ff1) – digi Apr 28 '18 at 19:23
  • @digi Are you initiating a close via exit? Exits must be a simple response: https://developers.google.com/actions/assistant/app-exits – mattcarrollcode Apr 30 '18 at 23:28
  • 1
    @matthewayne problem with the close is, that it forces the application to close. What should I use if I just want to 'ask' and keep the conversation going on? conv.ask() is resulting in MalformedResponse 'final_response' must be set – miro May 17 '18 at 11:48
  • @miro in the situation you describe the user has already indicated they wish to end the conversation with a "cancel" or similar command. In this case the Google Assistant is giving your action to say "goodbye" or another similar farewell message. Since the user has indicated they don't wish to speak with your action anymore you cannot continue the conversation forcefully so you must use conv.close(...) or set expectUserResponse to false to avoid an error. – mattcarrollcode May 21 '18 at 16:07
  • @miro most actions use this opportunity to say something similar to, "Goodbye! Say talk to if you want to try again" – mattcarrollcode May 21 '18 at 16:08
  • what gets added to the response? What does it look like? – Rich Elswick Jun 04 '18 at 13:59
  • @RichElswick it sets the expectUserResponse value in the JSON to false. Here is an example: https://github.com/dialogflow/fulfillment-webhook-json/blob/master/responses/v2/ActionsOnGoogle/EndConversation.json – mattcarrollcode Jun 06 '18 at 20:07
  • Thanks, that did it. – Rich Elswick Jun 20 '18 at 10:44