Rob*_*non 2 node.js google-cloud-platform dialogflow-es
我已经创建了一个使用dialogflow-fillfillment的webhook,以根据平台正确返回不同的数据,包括我为其他服务创建的自定义数据。我已经测试过Webhook,并且知道如果将其更改为originalDetectIntentRequest.source自定义有效负载中使用的平台,它将可以正常工作。
{
    "payload": {
        "jokes-api": {
            "success": true,
            "text": "These are some jokes",
        }
    },
    "outputContexts": []
}
我能够使用dialogflow-的NodeJS客户端-V2的sessions.detectIntent得到响应,但fullfilment回来与平台设置为PLATFORM_UNSPECIFIED,而不是定制的有效载荷我想要的。
[{
    "responseId": "c56c462f-bb3b-434a-b318-3739f58e6f6d",
    "queryResult": {
        "fulfillmentMessages": [{
            "platform": "PLATFORM_UNSPECIFIED",
            "card": {
                "buttons": [],
                "title": "Jokes",
                "subtitle": "These are some jokes",
                "imageUri": ""
            },
            "message": "card"
        }],
        "queryText": "tell me a joke",
        /* ... */
        "intent": {
            "name": "projects/my-jokes/agent/intents/56887375-3047-4993-8e14-53b20dd02697",
            "displayName": "Jokes",
            /* ... */
        },
        "intentDetectionConfidence": 0.8999999761581421,
    }
}]
查看我的Webhook日志,可以看到存在该originalDetectIntentRequest对象,但未设置源。
{
  "responseId": "c56c462f-bb3b-434a-b318-3739f58e6f6d",
  "queryResult": {
    "queryText": "tell me a joke",
    "speechRecognitionConfidence": 0.9602501,
    /* ... */
    "intent": {
      "name": "projects/my-jokes/agent/intents/56887375-3047-4993-8e14-53b20dd02697",
      "displayName": "Jokes"
    },
    /* ... */
  },
  "originalDetectIntentRequest": {
    "payload": {
    }
  },
  "session": "projects/my-jokes/agent/sessions/12345"
}
如何在dialogflow-nodejs-client-v2中设置平台或源,以获得所需的响应?
小智 5
sessions.detectIntentAPI的queryParams参数具有一个名为的字段payload。这就是“原始有效载荷”的去向。平台的名称进入该source结构的领域。因此,您的detectIntent通话应如下所示:
sessionClient.detectIntent({
    session: sessionClient.sessionPath('<project_id>', '<session_id>'),
    queryInput: {
        text: {
            text: '<query>',
            languageCode: 'en-US'
        }
    },
    queryParams: {
        payload: {
            fields: {
                source: {
                    stringValue: '<platform>',
                    kind: 'stringValue'
                }
            }
        }
    }
})
通过使用“ slack”作为平台名称,我能够模拟Slack集成调用。我还能够为自定义平台名称返回自定义有效负载。有效负载在queryResult.webhookPayload字段中返回。
| 归档时间: | 
 | 
| 查看次数: | 1306 次 | 
| 最近记录: |