Bala Chandar
Bala Chandar

Reputation: 47

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

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

Upvotes: 3

Views: 226

Answers (1)

Prisoner
Prisoner

Reputation: 50701

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.

Upvotes: 2

Related Questions