Search code examples
dialogflow-esdialogflow-cx

Is there any way to resume a chat in dialogflow cx?


I'm trying to build a chatbot with DialogFlow CX. We have an existing chatbot built on DF ES where with the help of contexts we have implemented a resume chat feature, which enables our end users to come back to the chat anytime and continue from where they left off. So currently we are building out the exact same bot in CX and we are facing challenges in recreating the resume chat flow.

So any help regarding how to to do this will be really helpful.

Thanks in advance


Solution

  • Dialogflow CX conversation (session) can be described and visualized as a state machine, configured to collect information or parameters from the end-user. This information is relevant to the conversation state on that page. Please be noted that for each conversational turn, the current page will either stay the same or transition to another page. This also applies for resuming or continuing the current state of the conversation.

    Here are possible ways to continue/resume a conversation by passing previously collected customer data from a previous conversation into a new conversation:

    1. You can create a custom implementation using a webhook wherein a function will store the parameter and forms you collected and use that to continue the chat from where the user left off during a conversation flow or a session. In the webhookResponse you can set the fulfillment_response, target_page fields and session_info field to update and send back the stored parameters you collected from the previous conversation.

      Here’s an example of how to pass the session parameter, target page and fulfillment response from your webhook response:

      {
         sessionInfo: {
             parameters: {
                 param1: {
                   value: "sample1"
                 }
             }
         },
        targetPage: projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/flows/<Flow ID>/pages/<Page ID>,
        fulfillment_response: { 
             messages: [{ 
               text: [“This is where you left”],
             }] 
         } 
      }
      
    2. You can use APIs or Client Libraries to set the queryParams.parameters and queryParams.currentPage in the detectIntent method.

      Here’s a sample reference using REST API to set the QueryParameters of the detectIntent method request body:

       {
          queryParams: {
              parameters: {
                    param1: {
                      value: "sample1"
                    },
          currentPage: projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/flows/<Flow ID>/pages/<Page ID>,
              }
           }
      
       }