gpt4 book ai didi

node.js - 如何在 Dialogflow NodeJS 客户端中设置自定义平台

转载 作者:搜寻专家 更新时间:2023-11-01 00:19:53 24 4
gpt4 key购买 nike

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

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

我可以使用 dialogflow-nodejs-client-v2sessions.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 中设置平台或源以获得所需的响应?

最佳答案

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

关于node.js - 如何在 Dialogflow NodeJS 客户端中设置自定义平台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51096251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com