dev-master
9999999-devAPI AI Webhook interface for PHP
MIT
The Requires
- php >=7.0
The Development Requires
api php ai google home google actions
API AI Webhook interface for PHP
This library provides a convient interface for developing Webhooks for API AI and Google Assistant., (*1)
Work in progress., (*2)
Capabilities: - Basic serialization/deserialization - Basic support for rich responses for Google Assistant, (*3)
Install via composer: composer require 20steps/api-ai-webhook-php
., (*4)
When API AI triggers your webhook, a HTTP request will be sent to the URL you specified for your app., (*5)
You can get the JSON
body of the request like so:, (*6)
$rawData = $request->getContent(); // This is how you would retrieve this with Laravel or Symfony 2. $request = new \APIAI\Request\Request($rawData); $request = $request->fromData();
The library expect raw request data, not parsed JSON as it needs to validate the request signature., (*7)
You can determine the type of the request with instanceof
, e.g.:, (*8)
if ($apiaiRequest instanceof IntentRequest) { // Handle intent here }
You can build an APIAI response with the Response
class. You can optionally set a display text or add basic cards for Google Assistant., (*9)
Here's a few examples., (*10)
$response = new \APIAI\Response\Response('my-assistant'); $response->respond('Cooool. I\'ll lower the temperature a bit for you!') ->withDisplayText('Temperature decreased by 2 degrees') ->withCard('My card title','My formatted text')
To output the response, simply use the ->render()
function, e.g. in Laravel you would create the response like so:, (*11)
return response()->json($response->render());
In vanilla PHP:, (*12)
header('Content-Type: application/json'); echo json_encode($response->render()); exit;
API AI Webhook interface for PHP
MIT
api php ai google home google actions