Atchoum
Atchoum

Reputation: 733

How do you terminate a conversation based on user input evaluation through a webhook (api v2)

Let's say my bot has an ongoing conversation with the user and my webhook asks "Are you done?" and the user responds "Yes". How do I close the conversation through the webhook? I suspect it is through followupEventInput but I could not get anything to work.

I am not using a nodeJS library. Coding in C#.

Here is what I tried: I respond with an output context and an event: the event is associated with "End conversation" under the Google Assistant at the bottom of the intent window.

 {  
  "fulfillmentText": "OK. The note was recorded.",
  "fulfillmentMessages": [
  {
  "text": {
    "text": [
      "OK. The note was recorded."
    ]
  }
}
],
  "outputContexts": [
{
  "lifespanCount": 2,
  "name": "projects/xxx/agent/sessions/1512399774430/contexts/note-end"
}
],
"followupEventInput": {
"name": "end-event",
"languageCode": "en"
  }
}

With the above code, the user never hears "OK. The note was recorded.", the session ends abruptly with Google Home saying "The app is not responding anymore" (or something similar). Works but not acceptable.

If I don't put the followupEvent, the user hears "OK. The note was recorded." but the conversation doesn't end... then I need to rely on the user to close it using another intent, which is what I want to avoid as it would be redundant.

Upvotes: 1

Views: 1043

Answers (2)

mattcarrollcode
mattcarrollcode

Reputation: 3469

You have two options to end a Google Assistant conversation with Dialogflow:

  1. Response defined in Dialogflow

Go to the intent defined in Dialogflow and scroll down and click on Google Assistant and check the box labeled End conversation enter image description here NOTE: this will only work with responses defined in Dialogflow console, not responses created by fulfillment.

  1. Response defined in webhook

Respond to Dialogflow's webhook request with a response of the form:

{
  "fulfillmentMessages": [
    {
      {
        "platform": "ACTIONS_ON_GOOGLE",
        "paylaod":{
          {
            "expectUserResponse": false,
            ...
          }
        }
      }
    }
  ],
  ...
}

Using either of these methods your app will say whatever is specified in the console (for #1) or webhook (for #2) and end the conversation with the user. Fill in values in the response section of the Dialogflow intent (for #1) or the payload object (for #2) to send a response to the user as you end the conversation.

Sources

Dialogflow Webhook Response v2 docs:https://dialogflow.com/docs/reference/api-v2/rest/v2beta1/WebhookResponse

Action on Google webhook response docs: https://developers.google.com/actions/reference/rest/Shared.Types/AppResponse#FIELDS.expect_user_response

Upvotes: 1

Atchoum
Atchoum

Reputation: 733

OK. After further investigation, it seems that:

  • the text of the fulfillment is never sent to the user but it needs to be set to something (" " works), otherwise the user will be told that the app is not responding and that s/he has to try again later.
  • The context and the event are correct and necessary. The only way (I found) to get the user to hear "OK. The note was recorded." is to include this message as a text response of the intent associated with the event. When set this way, the app closes in an acceptable manner.

Upvotes: 0

Related Questions