All Projects → iboldurev → Dialogflow

iboldurev / Dialogflow

Licence: mit
Unofficial php sdk for Dialogflow

Projects that are alternatives of or similar to Dialogflow

Mobx Rest
REST conventions for Mobx
Stars: ✭ 164 (-0.61%)
Mutual labels:  api, api-client
Pixiv Api Client
Promise based Pixiv API client for node.js and react native
Stars: ✭ 114 (-30.91%)
Mutual labels:  api, api-client
Rapidql
Query multiple APIs and DBs and join them in a single query
Stars: ✭ 91 (-44.85%)
Mutual labels:  api, api-client
Httpie Oauth
OAuth plugin for HTTPie
Stars: ✭ 78 (-52.73%)
Mutual labels:  api, api-client
Anyapi
AnyAPI is a library that helps you to write any API wrappers with ease and in pythonic way.
Stars: ✭ 126 (-23.64%)
Mutual labels:  api, api-client
Google Searchconsole
A wrapper for the Google Search Console API.
Stars: ✭ 83 (-49.7%)
Mutual labels:  api, api-client
Douyin Api
抖音API、抖音数据、抖音直播数据、抖音直播Api、抖音视频Api、抖音爬虫、抖音去水印、抖音视频下载、抖音视频解析、抖音直播监控、抖音数据采集
Stars: ✭ 112 (-32.12%)
Mutual labels:  api, api-client
Redux Api Call
One declarative API to create reducers, action creators and selectors for any API calls
Stars: ✭ 63 (-61.82%)
Mutual labels:  api, api-client
Tik4net
Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api.
Stars: ✭ 118 (-28.48%)
Mutual labels:  api, api-client
Sdk Js
Directus JS SDK — JavaScript Software Development Kit for Node and Browser
Stars: ✭ 117 (-29.09%)
Mutual labels:  api, api-client
Openvulnapi
Documentation and Tools for Cisco's PSIRT openVuln API
Stars: ✭ 73 (-55.76%)
Mutual labels:  api, api-client
Thehive4py
Python API Client for TheHive
Stars: ✭ 143 (-13.33%)
Mutual labels:  api, api-client
Igdb
Go client for the Internet Game Database API
Stars: ✭ 65 (-60.61%)
Mutual labels:  api, api-client
Amadeus Node
Node library for the Amadeus Self-Service travel APIs
Stars: ✭ 91 (-44.85%)
Mutual labels:  api, ai
Slacko
A neat interface for Slack
Stars: ✭ 64 (-61.21%)
Mutual labels:  api, api-client
Laqul
A complete starter kit that allows you create amazing apps that look native thanks to the Quasar Framework. Powered by an API developed in Laravel Framework using the easy GraphQL queries language. And ready to use the Google Firebase features.
Stars: ✭ 110 (-33.33%)
Mutual labels:  api, api-client
Api Php Client
PHP client of Akeneo PIM API
Stars: ✭ 56 (-66.06%)
Mutual labels:  api, api-client
Openapi Generator
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Stars: ✭ 10,634 (+6344.85%)
Mutual labels:  api, api-client
Coinbase Pro Node
Coinbase Pro API written in TypeScript and covered by tests.
Stars: ✭ 116 (-29.7%)
Mutual labels:  api, api-client
Laravel Api Explorer
API explorer for laravel applications
Stars: ✭ 138 (-16.36%)
Mutual labels:  api, api-client

DialogFlow PHP sdk

version Downloads

This is an unofficial php sdk for Dialogflow and it's still in progress...

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

Install:

Via composer:

$ composer require iboldurev/dialogflow

Usage:

Using the low level Client:

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:

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:

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 :

First, you need to create an ActionMapping class to customize the actions behavior.

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.

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();
}

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].