Skip to content

This library provides a convient interface for developing Webhooks for API AI (wip)

Notifications You must be signed in to change notification settings

20steps/api-ai-webhook-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API AI Webhook PHP Library

This library provides a convient interface for developing Webhooks for API AI and Google Assistant.

Info

Work in progress.

Capabilities:

  • Basic serialization/deserialization
  • Basic support for rich responses for Google Assistant

Usage

Install via composer: composer require 20steps/api-ai-webhook-php.

Requests

When API AI triggers your webhook, a HTTP request will be sent to the URL you specified for your app.

You can get the JSON body of the request like so:

$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.

You can determine the type of the request with instanceof, e.g.:

if ($apiaiRequest instanceof IntentRequest) {
	// Handle intent here
}

Response

You can build an APIAI response with the Response class. You can optionally set a display text or add basic cards for Google Assistant.

Here's a few examples.

$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:

return response()->json($response->render());

In vanilla PHP:

header('Content-Type: application/json');
echo json_encode($response->render());
exit;

About

This library provides a convient interface for developing Webhooks for API AI (wip)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages