Dialogflow V2 API - 如何传递上下文 and/or 有效负载
Dialogflow V2 API - How to pass context and/or payload
我正在尝试将上下文和有效负载发送到 Dialogflow V2 API。我能够成功发送一个 queryString 并从我的代理那里得到回复。但是,我需要通过此查询传递上下文和有效负载参数,而且我似乎无法找到 PHP 的任何帮助。请在下面查看我的代码。
我已经使用了这个解决方案,但没有用
function detect_intent_texts($projectId, $text, $sessionId, $context, $queryParams, $languageCode = 'en-US') {
// new session
$test = array('credentials' => 'client-secret.json');
$sessionsClient = new SessionsClient($test);
$session = $sessionsClient->sessionName($projectId, $sessionId ?: uniqid());
//printf('Session path: %s' . PHP_EOL, $session);
// create text input
$textInput = new TextInput();
$textInput->setText($text);
$textInput->setLanguageCode($languageCode);
// create query input
$queryInput = new QueryInput();
$queryInput->setText($textInput);
$optionalsParams = ['queryParams' => $queryParams];
// get response and relevant info
$response = $sessionsClient->detectIntent($session, $queryInput, $optionalsParams); // Here I don't know how to send the context and payload
$responseId = $response->getResponseId();
$queryResult = $response->getQueryResult();
$queryText = $queryResult->getQueryText();
$intent = $queryResult->getIntent();
$displayName = $intent->getDisplayName();
$confidence = $queryResult->getIntentDetectionConfidence();
$fulfilmentText = $queryResult->getFulfillmentText();
$returnResponse = array(
'responseId' => $responseId,
'fulfillmentText' => $fulfilmentText
);
$sessionsClient->close();
return $returnResponse;
}
我找到了解决办法。据此link.
$contextkey = new Value();
$contextkey->setStringValue($name);
$resultData[‘name’] = $contextkey;
$contextkey = new Value();
$contextkey->setStringValue($mobile);
$resultData[‘mobile’] = $contextkey;
$contextStruct = new Struct();
$contextStruct->setFields($resultData);
$queryParam = new QueryParameters();
$queryParam->setPayload($contextStruct);
$optionalsParams = [‘queryParams’ => $queryParam];
我正在尝试将上下文和有效负载发送到 Dialogflow V2 API。我能够成功发送一个 queryString 并从我的代理那里得到回复。但是,我需要通过此查询传递上下文和有效负载参数,而且我似乎无法找到 PHP 的任何帮助。请在下面查看我的代码。
我已经使用了这个解决方案,但没有用
function detect_intent_texts($projectId, $text, $sessionId, $context, $queryParams, $languageCode = 'en-US') {
// new session
$test = array('credentials' => 'client-secret.json');
$sessionsClient = new SessionsClient($test);
$session = $sessionsClient->sessionName($projectId, $sessionId ?: uniqid());
//printf('Session path: %s' . PHP_EOL, $session);
// create text input
$textInput = new TextInput();
$textInput->setText($text);
$textInput->setLanguageCode($languageCode);
// create query input
$queryInput = new QueryInput();
$queryInput->setText($textInput);
$optionalsParams = ['queryParams' => $queryParams];
// get response and relevant info
$response = $sessionsClient->detectIntent($session, $queryInput, $optionalsParams); // Here I don't know how to send the context and payload
$responseId = $response->getResponseId();
$queryResult = $response->getQueryResult();
$queryText = $queryResult->getQueryText();
$intent = $queryResult->getIntent();
$displayName = $intent->getDisplayName();
$confidence = $queryResult->getIntentDetectionConfidence();
$fulfilmentText = $queryResult->getFulfillmentText();
$returnResponse = array(
'responseId' => $responseId,
'fulfillmentText' => $fulfilmentText
);
$sessionsClient->close();
return $returnResponse;
}
我找到了解决办法。据此link.
$contextkey = new Value();
$contextkey->setStringValue($name);
$resultData[‘name’] = $contextkey;
$contextkey = new Value();
$contextkey->setStringValue($mobile);
$resultData[‘mobile’] = $contextkey;
$contextStruct = new Struct();
$contextStruct->setFields($resultData);
$queryParam = new QueryParameters();
$queryParam->setPayload($contextStruct);
$optionalsParams = [‘queryParams’ => $queryParam];