Search code examples
dialogflow-cx

Dialogflow CX - How to clear parameter


https://i.sstatic.net/uq9Yv.png

https://i.sstatic.net/jaPaz.png

https://i.sstatic.net/SHIuS.png

How do I get 'number' parameter to clear and output the prompt 'say a number' when I say 'no'?


Solution

  • To clear parameters in a session for form filling, you have to set the parameter value in the session to null before transitioning back to a page with form filling.

    There are two ways on how to set parameter values to null in a session:

    1. Add the parameters that are needed to be cleared with a null value in the fulfillment parameter presets of an intent/condition route of a page.

      a. In your case, you can add the “number” parameter with null value in the fulfillment parameter presets of your “No” intent route of your “Confirm Number” page.

      enter image description here b. When the “No” intent route of the “Confirm Number” page is triggered, the “number” parameter will be cleared in the session and will be transitioned back to the “Insert Number” Page to ask again for the number. enter image description here

    2. Set the parameter values to null through fulfillment webhooks. Below is a sample code for reference:

       app.post("/clearnumber", async (request, response) => {
         let params = request.body.sessionInfo.parameters; //get the current parameters in the session
         let message = "\n\n number parameter has been cleared... ";
         console.log("request body:" + request.body);
         console.log(".....number........... :" + params.number);
         params.number = null; // setting the number parameter to null
         console.log("..after.resetting.number........... :" + params.number);
         request.body.sessionInfo.parameters = params; //add the parameter changes in the sessionInfo that will be sent back to the agent
         let fulfillmentResponse = {
           fulfillmentResponse: {
             messages: [{
               text: {
                 text: []
               }
             }]
           },
           sessionInfo: request.body.sessionInfo
      
         };         fulfillmentResponse.fulfillmentResponse.messages[0].text.text.push(message);
         response.json(fulfillmentResponse);
       });
      

      As you can see in the screenshot below, the results are the same as using parameter presets in the console. enter image description here