codingPerson
codingPerson

Reputation: 109

Why app.intent throws error (malformed response) in actions-on-google

I am adding a basic card to my action, and, when testing in simulator, the error Malformed response, final_response must be set

Here is the webhook:

app.intent('Selected subjects', (conv, {Subject}) => {
subject = conv.arguments.get('OPTION') || Subject;
if (!conv.screen) {
conv.close(subjectCard[Subject].text);
} else {
conv.close(`Maybe this would help`, new BasicCard(subjectCard[Subject]));
}
});

Upvotes: 0

Views: 308

Answers (2)

codingPerson
codingPerson

Reputation: 109

For anyone who occurs a problem in this, with firebase, go to Functions, then Health. This will depict the exact line and code which is an error. For example, in this one, the word "subject" is not marked as a var, thus resulting in an error. I would recommend using firebase, as the Firebase console would depict errors that are not shown on the terminal/ cmd/ command line etc.

Upvotes: 2

Aza T
Aza T

Reputation: 589

There are a couple of problems. First, you must do either conv.close or conv.ask in your intent handler. In your code, it looks like your function does neither when conv.screen is true. To fix it, change the else-clause to:

else {
  conv.close(new BasicCard(...));
}

The second problem was that you didn't instantiate BasicCard, which is fixed in my snippet above.

This is a very common error, and I'd recommend reading Debugging Common Actions on Google Errors for tips and tricks on how to debug.

Upvotes: 1

Related Questions