我正在将Dialogflow REST API v2beta1连接到方法projects.agent.sessions.detectIntent
。在第一个请求中,我发送了一条文本,并且响应返回了包含outputContexts
的预期结果;当我发出第二个请求时,我发送了上下文,它应该找到链接到该上下文的意图,但取而代之的是,它返回默认后备意图。
第二个请求可能是什么问题?
这里是URL和请求以及它们各自的响应,下面我添加了预期匹配的意图的屏幕截图。
URL https://dialogflow.googleapis.com/v2beta1/projects/project-name/agent/sessions/12343:detectIntent
第一个请求
{
"queryInput":{
"text":{
"text":"play a video about love",
"languageCode":"en"
}
}
}
第一反应
{
"responseId": "15a3b767-52fe-4fc2-8ffd-9d7bb9c6961a",
"queryResult": {
"queryText": "play a video about love",
"action": "video.play",
"parameters": {
"organization": "",
"tag": "Love",
"item": ""
},
"allRequiredParamsPresent": true,
"fulfillmentText": "Here is a video about Love!",
"fulfillmentMessages": [
{
"platform": "ACTIONS_ON_GOOGLE",
"simpleResponses": {
"simpleResponses": [
{
"textToSpeech": "Here is a video about Love!"
}
]
}
},
{
"text": {
"text": [
"Here is a video about Love!"
]
}
}
],
"outputContexts": [
{
"name": "projects/project-name/agent/sessions/12343/contexts/play-video",
"lifespanCount": 5,
"parameters": {
"tag": "Love",
"organization": "",
"tag.original": "love",
"item": "",
"organization.original": "",
"item.original": ""
}
}
],
"intent": {
"name": "projects/project-name/agent/intents/9e5d2bbc-81f3-4700-8740-01504b05443f",
"displayName": "video-play"
},
"intentDetectionConfidence": 1,
"languageCode": "en"
}
}
第二个请求(问题应该出在哪里)
{
"queryParams":{
"contexts":[
{
"name":"projects/project-name/agent/sessions/12342/contexts/play-video"
}
]
},
"queryInput":{
"text":{
"text":"that video matters a lot for me",
"languageCode":"en"
}
}
}
第二次回复
{
"responseId": "40d1f94f-4673-4644-aa53-99c854ff2596",
"queryResult": {
"queryText": "that video matters a lot for me",
"action": "input.unknown",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "Can you say that again?",
"fulfillmentMessages": [
{
"text": {
"text": [
"Sorry, what was that?"
]
}
}
],
"intent": {
"name": "projects/project-name/agent/intents/10c88e8d-f16a-4905-b829-f596d3b3c588",
"displayName": "Default Fallback Intent",
"isFallback": true
},
"intentDetectionConfidence": 1,
"languageCode": "en"
}
}
预期匹配的意图的屏幕截图
有用的文档
答案 0 :(得分:3)
您的第二个请求的上下文似乎不完整。尽管您指定了name
,但没有包括lifespanCount
参数。由于您未提供参数,因此默认值为0,这表示它已超时。
您应该准确地发回 在上次答复中从outputContext
属性收到的内容。
{
"queryParams":{
"contexts":[
{
"name": "projects/project-name/agent/sessions/12343/contexts/play-video",
"lifespanCount": 5,
"parameters": {
"tag": "Love",
"organization": "",
"tag.original": "love",
"item": "",
"organization.original": "",
"item.original": ""
}
}
]
},
"queryInput":{
"text":{
"text":"that video matters a lot for me",
"languageCode":"en"
}
}
}