【问题标题】:How to set a custom platform in Dialogflow NodeJS Client如何在 Dialogflow NodeJS 客户端中设置自定义平台
【发布时间】:2018-12-08 07:48:08
【问题描述】:

我使用 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 对象存在,但未设置源。

{
  "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-es


    【解决方案1】:

    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 字段中返回。

    【讨论】:

    • 谢谢!请注意,您还可以使用 structjson 来编写有效负载,如下所述:stackoverflow.com/questions/47583996/…
    • 我想在响应中获取 outputAudio JSON,我应该指定哪个来源?
    猜你喜欢
    • 2020-12-31
    • 2019-11-12
    • 2015-07-11
    • 2018-06-14
    • 2015-09-26
    • 2017-05-19
    • 2014-02-06
    • 1970-01-01
    • 2021-02-09
    相关资源
    最近更新 更多