2017 © Pedro Peláez
 

library api-ai-php

Dialogflow php sdk

image

iboldurev/api-ai-php

Dialogflow php sdk

  • Sunday, April 8, 2018
  • by iboldurev
  • Repository
  • 14 Watchers
  • 140 Stars
  • 14,708 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 60 Forks
  • 9 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

DialogFlow PHP sdk

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

This is an unofficial php sdk for [Dialogflow][1] and it's still in progress..., (*2)

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

Install:

Via composer:, (*3)

$ composer require iboldurev/dialogflow

Usage:

Using the low level Client:, (*4)

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

use DialogFlow\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 DialogFlow\Client;
use DialogFlow\Model\Query;
use DialogFlow\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();
}

Usage

Using the low level asynchronous api:, (*6)

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

use DialogFlow\Client;
use DialogFlow\Model\Query;
use DialogFlow\Method\QueryApi;
use GuzzleHttp\HandlerStack;
use React\EventLoop\Factory;
use WyriHaximus\React\GuzzlePsr7\HttpClientAdapter;

$loop = Factory::create();
$reactGuzzle = new \GuzzleHttp\Client([
    'base_uri' => Client::API_BASE_URI . Client::DEFAULT_API_ENDPOINT,
    'timeout' => Client::DEFAULT_TIMEOUT,
    'connect_timeout' => Client::DEFAULT_TIMEOUT,
    'handler' => HandlerStack::create(new HttpClientAdapter($loop))
]);

$client = new Client('bc0a6d712bba4b3c8063a9c7ff0fa4ea', new DialogFlow\HttpClient\GuzzleHttpClient($reactGuzzle));
$queryApi = new QueryApi($client);

$queryApi->extractMeaningAsync('Hello', [
    'sessionId' => '123456789',
    'lang' => 'en'
])->then(
    function ($meaning) {
        $response = new Query($meaning);
    },
    function ($error) {
        echo $error;
    }
);

$loop->run();

Dialog

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

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

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

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

use DialogFlow\Client;
use DialogFlow\Method\QueryApi;
use DialogFlow\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();
}

The Versions

08/04 2018

dev-develop

dev-develop

Dialogflow php sdk

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

bot natural language api.ai api.ai sdk dialogflow dialogflow sdk

01/12 2017

dev-master

9999999-dev

Dialogflow php sdk

  Sources   Download

MIT

The Requires

 

bot api.ai api.ai sdk dialogflow dialogflow sdk

27/10 2017

0.3.0

0.3.0.0

Dialogflow php sdk

  Sources   Download

MIT

The Requires

 

bot api.ai dialogflow dialogflow sdk

27/10 2017

0.3.0.x-dev

0.3.0.9999999-dev

Dialogflow php sdk

  Sources   Download

MIT

The Requires

 

bot api.ai dialogflow dialogflow 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