无法在对话框流程中解析webhook json响应(api.ai)

时间:2018-05-10 13:11:32

标签: php chatbot dialogflow

我收到以下错误

  

错误:无法解析webhook JSON响应:找不到字段:消息中的语音google.cloud.dialogflow.v2.WebhookResponse

<?php 
$method = $_SERVER['REQUEST_METHOD'];
// Process only when method is POST
if($method == 'POST'){
    $requestBody = file_get_contents('php://input');
    $json = json_decode($requestBody);
    $text = $json->result->parameters->text;
    switch ($text) {
        case 'hi':
            $speech = "Hi, Nice to meet you";
            break;
        case 'bye':
            $speech = "Bye, good night";
            break;
        case 'anything':
            $speech = "Yes, you can type anything here.";
            break;

        default:
            $speech = "Sorry";
            break;
    }
    $response = new \stdClass();
    $response->speech = "$speech";
    $response->displayText = "$speech";
    $response->source = 'source-of-the-response';
    $response->return = "$speech";
    $response->fulfillmentText = "$speech";
    echo json_encode($response);
}
else
{
    $speech = "Ok";
    $response->speech = "$speech";
    echo json_encode($response);
}
?>

0 个答案:

没有答案