如何在Dialogflow NodeJS客户端中设置自定义平台 [英] How to set a custom platform in Dialogflow NodeJS Client
问题描述
我已经使用 dialogflow-fulfillment 创建了一个Webhook,以正确地返回不同的数据,具体取决于在平台上,包括我为另一项服务创建的自定义项。我已经测试过Webhook,并且知道如果将 originalDetectIntentRequest.source
更改为自定义有效负载中使用的平台,它将可以正常工作。
I have created a webhook using dialogflow-fulfillment to correctly return different data depending on the platform, including a custom one I created for another service. I've tested my webhook and know that if I change the originalDetectIntentRequest.source
to the platform used in my custom payload it works.
{
"payload": {
"jokes-api": {
"success": true,
"text": "These are some jokes",
}
},
"outputContexts": []
}
我能够使用 dialogflow-nodejs-client-v2 的 sessions.detectIntent
可以获取响应,但是全功能返回平台设置为 PLATFORM_UNSPECIFIED
,而不是我想要的自定义有效负载。
I am able to use dialogflow-nodejs-client-v2's sessions.detectIntent
to get a response, but the fullfilment comes back with the platform set as PLATFORM_UNSPECIFIED
, and not the custom payloads I want.
[{
"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
对象,但没有源组。
Looking at the logs for my webhook, I can see that the originalDetectIntentRequest
object is present, but source is not set.
{
"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"
}
我该如何
推荐答案
sessions.detectIntent
API具有 queryParams
参数,该参数具有名为 payload
的字段。这就是原始有效载荷的来源。平台的名称进入该结构的 source
字段。因此,您的 detectIntent
调用应如下所示:
sessions.detectIntent
API has queryParams
parameter which has a field called payload
. That's where the "original payload" goes. The name of the platform goes into the source
field of that structure. So your detectIntent
call should look something like this:
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
字段中返回。
I was able to simulate Slack integration call by using 'slack' as a platform name. I was also able to return a custom payload for a custom platform name. The payload is returned in queryResult.webhookPayload
field.
这篇关于如何在Dialogflow NodeJS客户端中设置自定义平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!