Giter Site home page Giter Site logo

wit-php's Introduction

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.

wit-php's People

Contributors

hfinck avatar tgallice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wit-php's Issues

example Conversation

Seem to be getting various errors when trying to create a simple Conversation class. It would be good to get a fully fleshed out example that doesn't require symphony.

Context reference date

We should revise the implementation of the reference_date within the context. With the new wit.ai bot engine this field has no meaning anymore.

The current documentation suggests to either include a reference_time or timezone within the context to define the users time setting. See here

We also need means of manipulating these settings, because right now this information is created implicitly with the server's time zone (which might not be the user's time zone).

What do you think? I suggest after these additions we create a new release, since all changes required to comply with the current wit.ai platform version are in place then.

Get message back from converse

Hey,

I am building a chatbot PHP boilerplate for starting building chatbots. I want to support different bot platforms like wit.ai and api.ai too.

So what I have is on central place where I receive the user's message. From there I provide several ways to "produce" an answer. One of them is with wit.ai. Another one is with custom code or with api.ai. But I need for all of them to get the message back.

With your sdk I can use the converse method but I do not get the message back, because the message is automatically send to the say method I need to extend in my action wrapper. Is there a chance to get the message back from where I send the message. Something similar like:

$context = $conversation->converse('session_id', $message);
$context->getMessage(); // what I would need

Or is this something you do not want or need?

Error msg

How to display an error if the story is not known, for example: I do not understand you

Sunsetting Bot Engine, deprecating the Stories UI and /converse endpoint on February 1, 2018

I have a bot being used in production that uses wit-php.

I am sure you are aware that wit.ai is deprecating Bot Engine and the Stories UI
, and so they will stop serving requests to the associated /converse endpoint on February 1, 2018.

The recommended migration is to use /message and code on your side to manage the conversation and link to the answers that would be stored in your database.

Currently I am using wit-php as outlined in your README.md, and like in your wit-php-example Quickstart command , with calls like:

$context = $conversation->converse($sessionId, $message, $context);

So, almost all of the bot logic is implemented in my MyActionMapping class , that extends ActionMapping class.

I am a little bit lost at getting started in this migratrion to abandon converse, and just use /message

There is a migration tutorial that wit.ai put up but it is focused on migrating Node.js apps, using node-wit (the Node.js SDK for Wit.ai)

I expect there are allot of people that need to deal with this issue as this February 1, 2018 deadline is approaching.

Do you have any suggestions on where to start with migrating an app that is currently using wit-php's Conversation class?

Missing Tgallice\Wit\MessageApi;

Hi,

I installed the package through the composer. It's a very well written code, but you have missed to include MessageApi file when run through the composer. I have found these files in the repository so I am updating my code but for others it must auto install through composer.

Compatible error in ActionMapping::action()

I'm getting the following error when I tried to implement ActionMapping.

MyActionMapping::action() must be compatible with Tgallice\\Wit\\ActionMapping::action($sessionId, $actionName, Tgallice\\Wit\\Model\\Context $context, array $entities = Array)

I implemented the function as you mentioned in the example:

public function action($sessionId, Context $context, Action $step)

Also i tried

public function action($sessionId, $actionName, \Tgallice\Wit\Model\Context $context, $entities = array()

What could be wrong here? My php version is 5.6.27

Thanks,
Unnikrishnan B.

Reference date when creating Context

Is it necessary to include a reference date when creating a Context?
@tgallice I assume you had reasons to put it there, but I feel this might not be useful for everyone.
I also reached out to wit.ai if fields like this, which in my case are not used, can confuse the bot model, but I did not receive any answer yet.
I would be glad if you can explain why it's there and if we generally need it.

    public function __construct($data = [])
    {
        // Ensure the refenre_date field
        if (empty($data['reference_date'])) {
            $data['reference_date'] = new \DateTime();
        }

        if ($data['reference_date'] instanceof \DateTime) {
            $data['reference_date'] = $data['reference_date']->format(DATE_ISO8601);
        }

        $this->data = $data;
    }

Context is missing

Context is empty when it's been set in previous dialogue.
Dialogue like this:
1.user: Send an email to [email protected]
2.bot: What content do you want to send?
3.user: blah blah blah.
4.bot: email sent.

Email is been set in context at step 2, but it's missing at step 4 when controller received message. Please consider the dialogue is correctly set in Wit.ai

Installation Problem

[root@server download]# composer require tgallice/wit-php

[InvalidArgumentException]
Could not find package tgallice/wit-php at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] []...

[root@server download]# composer require tgallice/wit-php

[InvalidArgumentException]
Could not find package tgallice/wit-php at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] []...

[root@server download]#

Converse

Please complete example for converse

How use ActionMapping (methods merge, stop)

Composer outdated?

Hi, I tried to run composer require tgallice/wit-php but I think it gives me an outdated version, I looked and abstract class ActionMapping does not use the Step object. I noticed this by looking at the revision history. Or am I wrong and is the Step version the older one?

Get bot message

Hey,

thx for the php sdk. I have setup a story on wit.ai and now I'm trying to get the bot's answer back to the user.

$response = $this->witAIClient->get('/message', [
     'q' => $message,
 ]);

I do get back some informations but not the message the bot should response / answer.

{"msg_id":"e657f02a-0d1f-442c-93f5-3cf58238d4f9","_text":"lets play word game","entities":{"my_method":[{"confidence":1,"type":"value","value":"method-type"}]}}

Is this method not meant to get the message back as well?

Thx and greets
Christoph

Define Context as Immutable

I think the Context must be immutable to prevent side effects. This way we can track all context modifications and why not provide a history ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.