Api.ai Webhook call failed. Error: 500 Internal Server Error

Api.ai Webhook call failed. Error: 500 Internal Server Error

我正在尝试使用 PHP 将用户输入存储在 MYSQL 数据库中,以便我想从 api.ai(Dialogflow) 中的代理获取 JSON 数据。我启用了 Webhook fulfillment 并在 webhook 选项卡中放置了 public api URL。

但是我被这个错误困住了 "Webhook call failed. Error: 500 Internal Server Error"

我想存储用户输入并通过 webhook 从 PHP 代码发送自定义消息。我在不同的地方寻找这个解决方案,但找不到。任何帮助,将不胜感激。

提前致谢!

错误:500 内部服务器错误表示您的代码有误。这是您可以用来修复代码的示例代码:

<?php
header("Content-Type: application/json");
ob_start();
$requestBody = file_get_contents('php://input'); 
$json = json_decode($requestBody, true);

$text = $json['result']['resolvedQuery'];
$response = json_encode(array(
        "source" => "webhook",
        "speech" => $text,
        "displayText" => $text,
        "contextOut" => array()
    ));

ob_end_clean();
echo $response;
?>

希望对您有所帮助!