2017 © Pedro Peláez
 

library api-ai-php

API.ai php sdk

image

ogrethegreat/api-ai-php

API.ai php sdk

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 63 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Api.ai PHP sdk

![version][packagist-version] Downloads, (*1)

This is an unofficial php sdk for Api.ai and it's still in progress..., (*2)

Api.ai: Build brand-unique, natural language interactions for bots, applications and devices.

Install:

Via composer:, (*3)

$ composer require iboldurev/api-ai-php

Usage:

Using the low level Client:, (*4)

require_once __DIR__.'/vendor/autoload.php';

use ApiAi\Client;

try {
    $client = new Client('access_token');

    $query = $client->get('query', [
        'query' => 'Hello',
    ]);

    $response = json_decode((string) $query->getBody(), true);
} catch (\Exception $error) {
    echo $error->getMessage();
}

Usage:

Using the low level Query:, (*5)

require_once __DIR__.'/vendor/autoload.php';

use ApiAi\Client;
use ApiAi\Model\Query;
use ApiAi\Method\QueryApi;

try {
    $client = new Client('access_token');
    $queryApi = new QueryApi($client);

    $meaning = $queryApi->extractMeaning('Hello', [
        'sessionId' => '1234567890',
        'lang' => 'en',
    ]);
    $response = new Query($meaning);
} catch (\Exception $error) {
    echo $error->getMessage();
}

Dialog

The Dialog class provides an easy way to use the query api and execute automatically the chaining steps :, (*6)

First, you need to create an ActionMapping class to customize the actions behavior., (*7)

namespace Custom;

class MyActionMapping extends ActionMapping
{
    /**
     * @inheritdoc
     */
    public function action($sessionId, $action, $parameters, $contexts)
    {
        return call_user_func_array(array($this, $action), array($sessionId, $parameters, $contexts));
    }

    /**
     * @inheritdoc
     */
    public function speech($sessionId, $speech, $contexts)
    {
        echo $speech;
    }

    /**
     * @inheritdoc
     */
    public function error($sessionId, $error)
    {
        echo $error;
    }
}

And using it in the Dialog class., (*8)

require_once __DIR__.'/vendor/autoload.php';

use ApiAi\Client;
use ApiAi\Method\QueryApi;
use ApiAi\Dialog;
use Custom\MyActionMapping;

try {
    $client = new Client('access_token');
    $queryApi = new QueryApi($client);
    $actionMapping = new MyActionMapping();
    $dialog = new Dialog($queryApi, $actionMapping);

    // Start dialog ..
    $dialog->create('1234567890', 'Привет', 'ru');

} catch (\Exception $error) {
    echo $error->getMessage();
}

Some examples are describe in the [iboldurev/api-ai-php-example][2] repository., (*9)

The Versions

23/03 2017

dev-master

9999999-dev

API.ai php sdk

  Sources   Download

MIT

The Requires

 

bot api.ai api.ai sdk

22/03 2017

dev-develop

dev-develop

Unofficial api.ai PHP SDK.

  Sources   Download

MIT

The Requires

 

The Development Requires

bot natural language api.ai api.ai sdk

20/08 2016

0.2.5

0.2.5.0

API.ai php sdk

  Sources   Download

MIT

The Requires

 

bot api.ai api.ai sdk