MyGit

tgallice/wit-php

Fork: 17 Star: 67 (更新于 1970-01-01 00:00:00)

license: MIT

Language: PHP .

Wit.ai php sdk

最后发布版本: 0.3.1 ( 2016-08-10 22:39:43)

GitHub网址

Wit.ai PHP sdk

Scrutinizer Code Quality Code Coverage Build Status

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

Wit.ai: Easily create text or voice based bots that humans can chat with on their preferred messaging platform.

## Install:

Via composer:

$ composer require tgallice/wit-php

Usage:

Using the low level Client:


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

use Tgallice\Wit\Client;

$client = new Client('app_token');

$response = $client->get('/message', [
    'q' => 'Hello I live in London',
]);

// Get the decoded body
$intent = json_decode((string) $response->getBody(), true);

You can used the Message api class to extract meaning of a sentence:


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

use Tgallice\Wit\Client;
use Tgallice\Wit\MessageApi;

$client = new Client('app_token');
$api = new MessageApi($client);

$meaning = $api->extractMeaning('Hello I live in London');

Conversation

The Conversation class provides an easy way to use the converse api and execute automatically the chaining steps :

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


namespace Custom;

use Tgallice\Wit\Model\Step\Action;
use Tgallice\Wit\Model\Step\Message;

class MyActionMapping extends ActionMapping
{
    /**
     * @inheritdoc
     */
    public function action($sessionId, Context $context, Action $step)
    {
        return call_user_func_array(array($this, $step->getAction()), array($sessionId, $context));
    }

    /**
     * @inheritdoc
     */
    public function say($sessionId, Context $context, Message $step)
    {
        echo $step->getMessage();
    }

     ....
}

And using it in the Conversation class.


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

use Tgallice\Wit\Client;
use Tgallice\Wit\ConverseApi;
use Tgallice\Wit\Conversation;
use Custom\MyActionMapping;

$client = new Client('app_token');
$api = new ConverseApi($client);
$actionMapping = new MyActionMapping();
$conversation = new Conversation($api, $actionMapping);

$context = $conversation->converse('session_id', 'Hello I live in London');

Conversation::converse() return the last available Context.

Some examples are describe in the tgallice/php-wit-example repository.

最近版本更新:(数据更新于 1970-01-01 00:00:00)

2016-08-10 22:39:43 0.3.1

2016-08-10 21:47:43 0.3.0

2016-06-25 17:56:59 0.2.0

2016-06-03 00:35:22 0.1.0

tgallice/wit-php同语言 PHP最近更新仓库

2024-09-18 20:45:32 coollabsio/coolify

2024-09-17 03:04:08 caseyamcl/guzzle_retry_middleware

2024-09-16 23:17:15 cakephp/migrations

2024-09-14 10:53:46 cakephp/cakephp

2024-09-06 16:28:08 spatie/holidays

2024-09-06 02:33:26 CakeDC/users