How to use Dialogflow CX API pass parameters to webhook?It seemed that detectIntent() set session queryParams does not work

Hen*_*Hao 3 dialogflow-es dialogflow-cx

According to the google dialogflow cx document: https://cloud.google.com/dialogflow/cx/docs/concept/parameter https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/QueryParameters

单击以显示参考 我知道我们可以使用 api 来设置会话参数。所以我想通过API方式将参数传递给webhook。

步骤1:前端,使用Detectintent() API,填写queryParams项。
步骤2:GoogleDialogflowCX服务器将设置参数作为会话参数。
第三步:Webhook接收google端的函数调用。我们可以从http请求中找到所有的session参数。

就我而言,我只能接收 DialogFlow Agent 中设置的变量,但没有收到通过 detectorintent() API 设置的任何参数。我想我一定做错了什么,谁能告诉我该怎么办?谢谢。

我的代码如下(Nodejs代码):

  const sessionPath = client.projectLocationAgentSessionPath(
    projectId,
    location,
    agentId,
    sessionId
  );
 
  var mapParameters = new Map([['Michael', 95], ['Bob', 75], ['Tracy', 85]]);
 
 const request = {
    session: sessionPath,
    
    "queryInput": {
      
      "text": {
        "text": query,
      },
      languageCode,
    },

    'queryParams': {
      'timeZone': 'America/Los_Angeles',
      'parameters': {
        "fields":mapParameters
      }
    },

 };
const [response] = await client.detectIntent(request);
Run Code Online (Sandbox Code Playgroud)

Hen*_*Hao 6

问题已经解决了。它需要被序列化/转换。

因此,对于文档中提到的参数类型,需要将其作为“struct”发送到DialogFlow。

根据您的协议或客户端库语言,这是由 (MapKey, MapValue) 对的集合组成的映射、关联数组、符号表、字典或 JSON 对象:

正确的结构如下:

{
  session: 'projects/xxxxx...........',
  queryInput: {
    text: { text: 'hello world!' },
    languageCode: 'en'
  },
  queryParams: {
    timeZone: 'America/Los_Angeles',
    parameters: {
      fields: {
        ID: { kind: 'numberValue', numberValue: 5 },
        Email: { kind: 'stringValue', stringValue: 'xxxxx@gmail.com' },
        Phone: { kind: 'stringValue', stringValue: '7789511xxx' },
        Domain: { kind: 'stringValue', stringValue: 'xxxxxx.com' }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)