PHP webhook未在Google上的操作中出现
履行响应在Dialogflow环境的诊断信息中可见。但当我在谷歌上测试它时,它并没有出现。有人知道如何让它工作吗?以下是我的webhook代码:PHP webhook未在Google上的操作中出现,php,dialogflow-es,actions-on-google,Php,Dialogflow Es,Actions On Google,履行响应在Dialogflow环境的诊断信息中可见。但当我在谷歌上测试它时,它并没有出现。有人知道如何让它工作吗?以下是我的webhook代码: <?php $method = $_SERVER['REQUEST_METHOD']; if($method == 'POST'){ $requestBody = file_get_contents('php://input'); $json = json_decode($requestBody);
<?php
$method = $_SERVER['REQUEST_METHOD'];
if($method == 'POST'){
$requestBody = file_get_contents('php://input');
$json = json_decode($requestBody);
$text = $json->queryResult->queryText;
$date = (!empty($json->queryResult->parameters->date)) ? $json->queryResult->parameters->date : '';
$environment = (!empty($json->queryResult->parameters->environment)) ? $json->queryResult->parameters->environment : '';
$intent = (!empty($json->queryResult->intent->displayName)) ? $json->queryResult->intent->displayName : '';
$responseText = prepareResponse($intent, $text, $date, $environment);
$response = new \stdClass();
$response->speech = $responseText;
$response->displayText = $responseText;
$response->source = "webhook";
header("Content-type:application/json");
echo json_encode($response);
}
else
{
echo "Method not allowed";
}
function prepareResponse($intent, $text, $date, $environment)
{
return "You said: " . $text . " | I found Intent: " . $intent . " | with parameters: date=" . $date . " environment=" . $environment;
}
?>
对Google上的操作的响应应位于
有效负载
属性下的对象中,该属性包含一个带有
我还没有测试过它,这可能不是构建它的最佳方式,但类似于以下的东西应该可以工作:
$response->payload = array(
"google" => array(
"expectUserResponse" => TRUE,
"richResponse" => array(
"items" => array(
array(
"simpleResponse" => array(
"textToSpeech" => $responseText
)
)
)
)
)
);
伟大的如果答案有帮助,接受和/或投票总是很感激的。