2017 © Pedro Peláez
 

library api-ai-webhook-php

API AI Webhook interface for PHP

image

20steps/api-ai-webhook-php

API AI Webhook interface for PHP

  • Wednesday, August 16, 2017
  • by helmuthva
  • Repository
  • 5 Watchers
  • 3 Stars
  • 60 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

API AI Webhook PHP Library

This library provides a convient interface for developing Webhooks for API AI and Google Assistant., (*1)

Info

Work in progress., (*2)

Capabilities: - Basic serialization/deserialization - Basic support for rich responses for Google Assistant, (*3)

Usage

Install via composer: composer require 20steps/api-ai-webhook-php., (*4)

Requests

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
}

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., (*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;

The Versions

16/08 2017

dev-master

9999999-dev

API AI Webhook interface for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

api php ai google home google actions