google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

com.google.apps.framework.request.BadRequestException: Path '' does not match template

Open demon-ru opened this issue 7 years ago • 6 comments

"message": "com.google.apps.framework.request.BadRequestException: [ResourceName error] Path 'registered' does not match template 'projects/{project_id=}/locations/{location_id=}/agent/environments/{environment_id=}/users/{user_id=}/sessions/{session_id=}/contexts/{context_id=}'.",

json: {"contexts":[{"name":"context_name"}]}

The same: https://github.com/googleapis/nodejs-dialogflow/issues/387

Environment details

  • OS: Ubuntu 18
  • PHP version: 7.2.19
  • Package name and version: google/cloud-dialogflow 0.10.0

Steps to reproduce

  1. call detectIntent with optional parameters of list of contexts

Code example

# example
    $parameters = new \Google\Protobuf\Internal\RepeatedField(\Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Dialogflow\V2\Context::class);
    $parameters[] = (new Context())
    	->setName("context_name");
    $response = $sessionsClient->detectIntent($session, $queryInput, [
	'queryParams'=>(new QueryParameters())->setContexts($parameters)
	]);

demon-ru avatar Sep 26 '19 18:09 demon-ru

Is there a workaround? V1 shutdown time is very soon :(

demon-ru avatar Oct 04 '19 16:10 demon-ru

Hi @demon-ru,

Try the following:

use Google\Cloud\Dialogflow\V2\Context;
use Google\Cloud\Dialogflow\V2\ContextsClient;
use Google\Cloud\Dialogflow\V2\QueryInput;
use Google\Cloud\Dialogflow\V2\QueryParameters;
use Google\Cloud\Dialogflow\V2\SessionsClient;
use Google\Cloud\Dialogflow\V2\TextInput;

$projectId = '[PROJECT_ID]';
$sessionId = uniqid();
$contextId = uniqid();
$client = new SessionsClient;
$sessionName = SessionsClient::sessionName($projectId, $sessionId);
$contextName = ContextsClient::contextName($projectId, $sessionId, $contextId);

$query = new QueryInput([
    'text' => new TextInput([
        'text' => 'hello',
        'language_code' => 'en-US'
    ])
]);
$res = $client->detectIntent($sessionName, $query, [
    'queryParams' => new QueryParameters([
        'contexts' => [
            new Context([
                'name' => $contextName
            ])
        ]
    ])
]);

print_r(json_decode($res->serializeToJsonString()));

Using the ContextsClient::contextName() formatting method, I am able to successfully complete the request. Perhaps your context name was incorrectly formatted; When I first tested I was encountering the error you reported.

It does appear that the error message is incorrect, as the template in the error does not match the error in the documentation. You may wish to submit a report so the API team can look into that!

jdpedrie avatar Oct 04 '19 21:10 jdpedrie

Thanks. You are right. After formatting the context name, the error no longer appears. But the request is executed as if the context is not used. Returns The "Default Fallback Intent". I am sure that the name of the context is correct, written in small letters. I will be very grateful for your help. There are almost no php examples on the web. very few examples in JS.

demon-ru avatar Oct 10 '19 19:10 demon-ru

Couldn't find a way to see what intent detection sends to the server. There are no logging or debugging settings. I enabled "Log Interactions with Google Cloud" in DialogFlow and saw request and response packets. But no parameters with context name are visible in the request packet. Only the playload itself with the request text.

demon-ru avatar Oct 11 '19 06:10 demon-ru

Oh, it works! $context->setLifespanCount(1); Added a line and the answer was correct. And it is necessary to set the value "1". Neither" 0 "nor" 2 " is liked by the query.

https://cloud.google.com/dialogflow/docs/reference/rest/v2/projects.agent.sessions.contexts#Context lifespanCount | numberOptional. The number of conversational query requests after which the context expires. If set to 0 (the default) the context expires immediately. Contexts expire automatically after 20 minutes if there are no matching queries.

This is very strange and wrong behavior.

demon-ru avatar Oct 11 '19 06:10 demon-ru

Glad you’re able to make progress. I’d encourage you to report things you think may be service bugs in the issue tracker I shared previously.

Please re-open or start a new issue if you have further trouble!

jdpedrie avatar Oct 11 '19 12:10 jdpedrie