php - Google 操作生成器 - 如何从 webhook 请求中读取并避免空响应

标签 php webhooks actions-on-google google-assistant actionbuilder

当我使用 PHP 调用 webhook 时,我在测试时收到此消息。抱歉,我没有收到任何回复 附上我的 webhook 请求 json 和 和php代码

if($method == 'POST')
{
 $requestBody = file_get_contents('php://input');
 $json = json_decode($requestBody, true, 512, JSON_BIGINT_AS_STRING);
 $customer_name=$json["requestJson"]["intent"]["params"]["customer_name"]["resolved"];
 $response = array ('prompt' => array ('firstSimple' => array ( 'speech' => $customer_name, 'text' => 
 $customer_name)));
 echo json_encode( $response );
}

测试时也有 webhook 响应 json

{
"responseJson": {
"prompt": {
  "firstSimple": {}
}
 }
} 

enter image description here

Webhook 请求 json

enter image description here

最佳答案

虽然它显示在测试控制台中,但“requestJson”属性并不是发送给您的正文的一部分。正文将只包含该属性下的对象。

所以获取 $customerName 的行应该更像

 $customer_name=$json["intent"]["params"]["customer_name"]["resolved"];

您收到有关未收到响应的错误的具体原因是因为没有在响应的“simpleResponse”属性中设置任何属性。我假设这是因为 $customer_name 最终没有设置,所以 php 或助手正在删除空属性值。

关于php - Google 操作生成器 - 如何从 webhook 请求中读取并避免空响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66969811/

相关文章:

stripe-payments - 在什么情况下会发送 stripe 的 transfer.failed webhook?

sdk - 上传谷歌操作时,gactions CLI 在 Windows 上崩溃

java - 如何使用 Spring Boot 和 Java 库在 google 上创建操作

php - AJAX改变页面内容

javascript - Bootstrap Pagination 正在删除 href,使链接无法点击

http - 什么是 Webhook,我为什么要关心它?

http - 使用 Zapier Webhook 触发器访问请求 header

php - 内连接,选择 SUM 和Where

php - 使用 Telegram 的 API 创建群组

actions-on-google - Actions on Google - Mac 操作无法运行