如何在Dialogflow NodeJS Client中设置自定义平台

问题描述 投票:2回答:1

我使用dialogflow-fulfillment创建了一个webhook,以根据平台正确返回不同的数据,包括我为其他服务创建的自定义数据。我已经测试了我的webhook,并且知道如果我将originalDetectIntentRequest.source更改为我的自定义有效负载中使用的平台,它可以工作。

{
    "payload": {
        "jokes-api": {
            "success": true,
            "text": "These are some jokes",
        }
    },
    "outputContexts": []
}

我可以使用dialogflow-nodejs-client-v2sessions.detectIntent来获得响应,但是整个版本的平台设置为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对象存在,但未设置source。

{
  "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中设置平台或源以获得所需的响应?

node.js google-cloud-platform dialogflow
1个回答
5
投票

sessions.detectIntent API有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字段中返回。

© www.soinside.com 2019 - 2024. All rights reserved.