Skip to content

Repository files navigation

Wit.ai PHP sdk

Scrutinizer Code QualityCode CoverageBuild 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';
useTgallice\Wit\Client;
$client = newClient('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';
useTgallice\Wit\Client;
useTgallice\Wit\MessageApi;
$client = newClient('app_token');
$api = newMessageApi($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.

namespaceCustom;
useTgallice\Wit\Model\Step\Action;
useTgallice\Wit\Model\Step\Message;
class MyActionMapping extends ActionMapping
{
/** * @inheritdoc */publicfunctionaction($sessionId, Context$context, Action$step)
{
returncall_user_func_array(array($this, $step->getAction()), array($sessionId, $context));
}
/** * @inheritdoc */publicfunctionsay($sessionId, Context$context, Message$step)
{
echo$step->getMessage();
}
....
}

And using it in the Conversation class.

require_once__DIR__.'/vendor/autoload.php';
useTgallice\Wit\Client;
useTgallice\Wit\ConverseApi;
useTgallice\Wit\Conversation;
useCustom\MyActionMapping;
$client = newClient('app_token');
$api = newConverseApi($client);
$actionMapping = newMyActionMapping();
$conversation = newConversation($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.

About

Wit.ai php sdk

Resources

Stars

67 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages