pablomarti
pablomarti

Reputation: 2107

Dialogflow is not detecting the intent with context

I am connecting to Dialogflow REST API v2beta1 to the method: projects.agent.sessions.detectIntent. In the first request I send a text and the response is returning the expected result which contains outputContexts; when I made the 2nd request I send the context and it should find the intent which is linked to that context, but instead of that it is returning the Default Fallback Intent.

What may be the problem on the 2nd request?

Here are the URL and requests with their respective responses, and below I added the screenshots of the intents expected to match.

URL https://dialogflow.googleapis.com/v2beta1/projects/project-name/agent/sessions/12343:detectIntent

1st request

{
    "queryInput":{
        "text":{
            "text":"play a video about love",
            "languageCode":"en"
        }
    }
}

1st response

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

2nd request (where the problem should be)

{
    "queryParams":{
        "contexts":[
            {
                "name":"projects/project-name/agent/sessions/12342/contexts/play-video"
            }
        ]
    },
    "queryInput":{
        "text":{
            "text":"that video matters a lot for me",
            "languageCode":"en"
        }
    }
}

2nd response

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

Screenshots of the intents expected to match

1st intent enter image description here

2nd intent enter image description here

Useful documentation

Upvotes: 2

Views: 2718

Answers (1)

Prisoner
Prisoner

Reputation: 50701

It looks like your second request has an incomplete context. Although you're specifying the name, you're not including the lifespanCount parameter. Since you're not providing a parameter, it defaults to 0, which means that it has timed out.

You should send back exactly what you received from the outputContext attribute in the previous reply.

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

Upvotes: 3

Related Questions