Dialogflow Messenger CX intercept and add queryParams to responseBody

Viewed 382

I want to intercept the request from dialogflow messenger CX and add parameters to responseBody by queryParams, I have read the documentation but it is not clear about how to add the new parameters using javascript event. I understand that there is a event called df-request-sent but the documentation doesn't show about how to send the new parameters in the event. I have searched similar question but i didn't find information.

I am using the next documentation: https://cloud.google.com/dialogflow/cx/docs/concept/integration/dialogflow-messenger#df-request-sent

The code is:

         const dfMessenger = document.querySelector('df-messenger')
         dfMessenger.addEventListener('df-request-sent', function (event) {
             console.log(event)
             // how to send the new parameters?
         })

I have tried changing the value of event.detail but it didn't work.

Anybody know how to do it?

Thanks for your help.

1 Answers

Unfortunately, adding parameters on the queryParams of the Dialogflow Messenger event’s df-request-sent isn’t possible. Please note that this event occurs when a request is made to the Dialogflow API, and we cannot edit the event structure as this is dependent on Dialogflow Messenger’s detectIntent request.

As a workaround, you can use custom integration. You can utilize Dialogflow CX’s Client Libraries, REST API, or RPC API to create your own implementation/integration. Then, you can add parameters in your detectIntent request.

Here is a sample of detectIntent request body:

{
  "queryInput": {
     "text": {
        "text": "Hi"
     },
     "languageCode": "en"
  },
  "queryParams": {
     "timeZone": "America/Los_Angeles",
     "parameters": {
         //set your parameters here
     }
  }
}
Related