Search code examples
nlpdialogflow-esagent

Using DialogFlow detectintent doesn't work properly


i using DialogFlow v2 (and trying with v2Beta1), using the SDK in python, with the problem that the detectIntent method doesn't recognize the parameters in the query input.

So, looking for a solution, i recreated the problem using simple cUrl calls.

The next is the cUrl to create an EntityType:

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
"https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent/entityTypes?languageCode=es" \
--data "{
    'displayName': 'customer',
    'kind': 'KIND_MAP',
    'autoExpansionMode': 'AUTO_EXPANSION_MODE_DEFAULT',
    'entities': [
        {
            'value': 'one',
            'synonyms': [
                'one', 'uno'
            ]
        },
        {
            'value': 'two',
            'synonyms': [
                'two', 'dos'
            ]
        }
    ],
    'enableFuzzyExtraction': true
}"

That works fine and the EntityType is created.

Now, the create intent:

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
"https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent/intents" \
--data "{
    'displayName': 'ExampleIntent',
    'priority': 500000,
    'mlDisabled': false,
    'trainingPhrases': [
        {
            'type': 'EXAMPLE',
            'parts': [
                {
                    'text': 'start '
                },
                {
                    'text': 'one',
                    'alias': 'customer',
                    'entityType': '@customer',
                    'userDefined': true
                }
            ]
        },
        {
            'type': 'EXAMPLE',
            'parts': [
                {
                    'text': 'begin '
                },
                {
                    'text': 'one',
                    'alias': 'customer',
                    'entityType': '@customer',
                    'userDefined': true
                }
            ]
        },
        {
            'type': 'EXAMPLE',
            'parts': [
                {
                    'text': 'do '
                },
                {
                    'text': 'one',
                    'alias': 'customer',
                    'entityType': '@customer',
                    'userDefined': true
                }
            ]
        }
    ],
    'action': 'start',
    'messages': [
        {
            'text': {
                'text': [
                    'Hi'
                ]
            }
        }
    ],
}"

Also works fine.

And now, i try to detect the intent:

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    "https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent/sessions/0:detectIntent" \
    --data "{
        'queryInput': {
            'text': {
                'text': 'do one',
                'languageCode': 'es'
            }
        }
    }"

The response is without the parameter:

{
"responseId": "de68c5f5-6aa9-4716-ac22-626a22fc5d43-b81332aa",
"queryResult": {
    "queryText": "do one",
    "action": "start",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Hi",
    "fulfillmentMessages": [
    {
        "text": {
        "text": [
            "Hi"
        ]
        }
    }
    ],
    "intent": {
    "name": "projects/myproject_id/agent/intents/20ab36d6-e8c8-40d6-87dc-78a61e2de600",
    "displayName": "ExampleIntent"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "es"
}
}

I tried to train:

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    "https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent:train"

And the result is the same.

But, if i go to the web console, enter to the intent and click the save button... the detectIntent start to works.

{
"responseId": "45c919dc-677d-4ae4-8572-588955cd5414-b81332aa",
"queryResult": {
    "queryText": "do one",
    "action": "start",
    "parameters": {
    "customer": [
        "one"
    ]
    },
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Hi",
    "fulfillmentMessages": [
    {
        "text": {
        "text": [
            "Hi"
        ]
        }
    }
    ],
    "intent": {
    "name": "projects/myproject_id/agent/intents/20ab36d6-e8c8-40d6-87dc-78a61e2de600",
    "displayName": "ExampleIntent"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "es"
}
}

What am i missing?

Thanks to any clue how to make this work.


Solution

  • Well... after a few research, i found the problem, i was missing the parameters parameter in the createIntent:

    curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    "https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent/intents" \
    --data "{
        'displayName': 'ExampleIntent',
        'priority': 500000,
        'mlDisabled': false,
        'parameters': [
            {
                'displayName': 'customer',
                'entityTypeDisplayName': '@customer',
                'value': '$customer'
            }
        ],
        'trainingPhrases': [
            {