How to exit conversation in DialogFlow Fullfilment for an Action

1.9k views Asked by At

I have an action which is a simple word game and upon completing the game should exit the conversation. I want the action to support Google Assistant and speaker based devices ( mobile phone etc) so i am handling the intent in a general fashion.

const {WebhookClient} = require('dialogflow-fulfillment');
...
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  ...
  function answerIntent(agent) {
     if (gameShouldEnd) {
       agent.end("Your score is 3/5. Cheers! GoodBye!");
     }
  }
  ...
}

This results in log error MalformedResponse: 'final_response' must be set

I tried the conv api too and that results in the same error.

const {WebhookClient} = require('dialogflow-fulfillment');
...
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  ...
  function answerIntent(agent) {
    if (gameShouldEnd) {
      let conv = agent.conv();
      conv.tell("Your score is 3/5. Cheers! GoodBye!");
      agent.add(conv);
    }
  }
  ...
}

Please suggest how to close the Mic when the game ends and still sends a response.

3

There are 3 answers

0
SanthoshN On BEST ANSWER

Seems there is an issue with version 0.5.0 of the dialogflow-fullfillment package according to the issue logged https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/149

I tried updating to 0.6.0 which has breaking changes which solved the current question i posted but created context related problems.

1
quent On

Do you have tried the close method:

  conv.close("Your score is 3/5. Cheers! GoodBye!");
1
Gustavo Luna On

please check if the lifespam of your intent is 1. After that you can use the command bellow:

agent.end("bye");