What is the best practice to handle fulfillment using PHP & google/cloud-dialogflow library

Viewed 484

I'm able to receive requests on Dialogflow Intent fulfillment event on my server [Laravel Framework - PHP]

However, I am unable to handle the webhook request using the official Google Dialogflow Library for PHP.

I am not sure if I understand it right, but according to google dialogflow docs, when an intent is fulfilled, I should use the WebhookRequest class to receive the request and WebhookRespone class to prepare my response (add context, message text, etc) and send it back to the server.

My problem is, I do not know how to initialise the WebhookRequest, and I don't know how to render the WebhookRespone and convert it to JSON.

Expected code regarding WebhookRequest:

$params = $request->all();//All Json From webhook request in one array.
$webhookRequest = new WebhookRequest($params);
$sessionName = $webhookRequest->getSession();
$queryResult = $webhookRequest->getQueryResult();

Expected code regarding WebhookResponse

$webhookResponse = new WebhookResponse();
$webhookResponse->setFulfillmentText("Hello World");
return response()->json($webhookResponse->toJson());//Laravel Way to send back response

I am aware of the eristemena/dialogflow-fulfillment-webhook-php library, but it is not an official Google API, and I'm not sure if it is the best practice because the library is not maintained by Google.

0 Answers
Related