3

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

  • What does `var_dump($requestBody);` show? Please update your post accordingly so we can see the raw data coming in – hppycoder Apr 06 '21 at 13:45
  • @hppycoder could you please provide an example how i would send back that JSON object. That would be very helpful. Thank you – Bala Chandar Apr 06 '21 at 14:11

1 Answers1

2

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.

Prisoner
  • 49,922
  • 7
  • 53
  • 105