Google actions builder - how to read from webhook request and avoid empty response

212 views Asked by At

When I call webhook using PHP, I get this message while testing. Sorry, I didn't get any response Attached my webhook request json and and php code

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 );
}

also webhook response json while testing

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

enter image description here

Webhook request json

enter image description here

1

There are 1 answers

1
Prisoner On BEST ANSWER

Although it shows up in the test console, the "requestJson" attribute isn't part of the body that is sent to you. The body will just include the object underneath that attribute.

So the line to get $customerName should probably be more like

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

The specific reason you're getting the error about not getting a response is because there aren't any attributes set in the "simpleResponse" attribute of the response. I'm assuming that is because $customer_name ends up not getting set, so either php or the Assistant are removing null attribute values.