Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Terminate session button

Hi,

I use Google Dialogflow CX
I want to create a terminate session button.

How can I do it?

Thanks

0 1 133
1 REPLY 1

Hi @oozturkplus,

Welcome to Google Cloud Community!

To  create a "Terminate" button (or a button that ends the conversation) in Dialogflow CX, the process involves a combination of setting up a route, a transition, and potentially a custom payload for the button itself.

Here's a step-by-step guide:

1. Conceptual Understanding

  • Termination Intent: You'll need an intent that signals the user wants to end the conversation. This could be something like "Terminate Conversation," "End," "Goodbye," or any phrase indicating they want to stop.
  • Route: You'll create a Route on the desired page that is triggered by the Termination Intent. This Route will direct the conversation to an "end session" state.
  • Button (Optional): While not strictly required, a button makes the user experience much better. You'll embed a button in your response that, when clicked, will trigger the termination intent.
  • Transition to End: The route triggered by the intent needs a transition to the End Session flow start node.

2. Implementation Steps in Dialogflow CX Console

A. Create the Termination Intent:

  1. Go to your Agent in the Dialogflow CX console.
  2. Navigate to the "Intents" section.
  3. Create a new intent (e.g., "TerminateConversationIntent").
  4. Add training phrases that users might use to end the conversation (e.g., "End this conversation," "Stop," "Goodbye," "I'm done here").
  5. Save the intent.

B. Add the Button to the Desired Page Response:

  1. Go to the Page on which you want the button to appear.
  2. In the "Entry fulfillment" or other fulfillment, add a response.
  3. Select the "Custom Payload" tab.
  4. Add the following JSON (or similar) within the custom payload:
    {
      "payload": {
        "richContent": [
          [
            {
              "type": "button",
              "text": "Terminate Conversation",
              "event": {
                "name": "terminateConversation"
              }
            }
          ]
        ]
      }
    }
         
  • "text": The text that will appear on the button (e.g. "Terminate Conversation", "End Session").
  • "event.name": This is the crucial part, you should set it to something unique (e.g. terminateConversation). This will be used to route the user to the right flow. You could alternatively use the intent itself, but I recommend this method for future scalability, as you might use the same intent for other things.

     5. Save the Page.

C. Add a Route on the Page:

  1. Go to the Page where you added the button.
  2. Add a new Route.
  3. Condition: Change the condition to event.name == "terminateConversation". This will route the conversation to this transition only if the terminate button is clicked.
  4. Target Page or Transition: Select the 'end session' flow start node
  5. Save the Route.

D. (Alternative to C): Add a Route on the Page directly using the intent

  1. Go to the Page where you added the button.
  2. Add a new Route.
  3. Condition: Change the condition to intent == "TerminateConversationIntent". This will route the conversation to this transition only if the terminate intent is detected.
  4. Target Page or Transition: Select the 'end session' flow start node
  5. Save the Route.

3. Explanation

  • Button Payload: The JSON payload creates a button with the specified text. When the user clicks the button, Dialogflow CX will emit the terminateConversation event.
  • Route Matching: The page route with the condition event.name == "terminateConversation" triggers when the button is clicked (or intent == "TerminateConversationIntent" if you chose the alternative routing).
  • Transition to End: The chosen transition to the flow start node with the 'x' will end the conversation with the user.

4. Testing:

  1. Test your changes using the simulator.
  2. Navigate to the page containing your button.
  3. Click the button. The conversation should now end.
  4. If you did not add a button, but instead just the intent, try typing "End this conversation" etc.

Here are some important considerations:

  • Different Integrations: The specific structure of the JSON payload might slightly vary depending on the platform where your agent will be deployed (e.g., Google Assistant, website, etc.). Refer to the Dialogflow documentation for more details on the rich content format.
  • User Experience: Consider providing a final goodbye message or other relevant information to the user when the conversation ends. This can be done either before or after moving to the "end session" flow start node.
  • Multiple Termination Points: You might need to add similar routes and button logic on multiple pages, depending on the scope of your agent.
  • Handling "No Match" Scenarios: Think about what happens if the user uses a different phrase to try and end the conversation. Ensure you have a fallback intent and route that can handle these situations gracefully. You could try matching "Goodbye" or similar phrases to the TerminateConversationIntent.

You may want to check this sample for reference.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.