php - 无法在 dialogflow(api.ai) 中解析 webhook json 响应
问题描述
我收到以下错误
错误:无法解析 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);
}
?>
解决方案
推荐阅读
- r - 使用 here() 函数在根目录之上上一层
- haskell - 如何列出由 Haskell cabal 包安装的文件?
- r - 通过对 data.frame 中的另一列求和来创建月份列
- javascript - 将RequireJS与导出类一起使用时函数结果未定义
- php - 使用简单的 HTML DOM 或其他执行功能或单击外部页面?
- docker - Inkscape 尝试将 DXF 作为 SVG 打开
- python - 卷积神经网络内存使用
- c++ - 可以优化 lambda 按值捕获吗?
- pandas - pandas groupby:整体/总行?
- junit - 我如何对这段代码进行单元测试?