简体   繁体   English

Dialogflow Messenger CX 拦截并将 queryParams 添加到 responseBody

[英]Dialogflow Messenger CX intercept and add queryParams to responseBody

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.我想拦截来自 dialogflow messenger CX 的请求并通过 queryParams 将参数添加到 responseBody,我已阅读文档但不清楚如何使用 javascript 事件添加新参数。 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.我知道有一个名为df-request-sent的事件,但文档没有说明如何在事件中发送新参数。 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我正在使用下一个文档: 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.我曾尝试更改 event.detail 的值,但没有成功。

Anybody know how to do it?有人知道怎么做吗?

Thanks for your help.谢谢你的帮助。

Unfortunately, adding parameters on the queryParams of the Dialogflow Messenger event's df-request-sent isn't possible.不幸的是,无法在 Dialogflow Messenger 事件的 df-request-sent 的 queryParams 上添加参数。 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.请注意,当向 Dialogflow API 发出请求时会发生此事件,我们无法编辑事件结构,因为这取决于 Dialogflow Messenger 的 detectIntent 请求。

As a workaround, you can use custom integration.作为解决方法,您可以使用自定义集成。 You can utilize Dialogflow CX's Client Libraries , REST API , orRPC API to create your own implementation/integration.您可以利用 Dialogflow CX 的客户端库REST APIRPC API创建您自己的实现/集成。 Then, you can add parameters in your detectIntent request.然后,您可以在detectIntent请求中添加参数。

Here is a sample of detectIntent request body:以下是 detectIntent 请求正文的示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM