2017 © Pedro Peláez
 

library chatbot-platform

A Chatbot platform exchanger

image

dldl/chatbot-platform

A Chatbot platform exchanger

  • Monday, September 4, 2017
  • by quentinus95
  • Repository
  • 1 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ChatbotPlatform

Build Status, (*1)

This platform is not heavy tested and is a proof-of-concept. Any contributions are welcomed., (*2)

ChatbotPlatform is a PHP library allowing to build a multiple chatbot platform with multiple actions providers and multiple sources., (*3)

The current implementation allows basic Ajax interactions or Facebook Messenger discussions. It can be extended easily., (*4)

Installation

Install the library using Composer:, (*5)

composer require dldl/chatbot-platform

Basic usage

ChatbotPlatform may be used as a standalone project or integrated into existing applications using any framework or CMS., (*6)

For a basic standalone usage, create an index.php file with the following code:, (*7)

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Dotenv\Dotenv;
use dLdL\ChatbotPlatform\ChatbotPlatform;
use dLdL\ChatbotPlatform\Handler\FacebookMessageHandler;
use dLdL\ChatbotPlatform\Handler\AjaxMessageHandler;
use dLdL\ChatbotPlatform\Action\RepeatMessageAction;
use dLdL\ChatbotPlatform\Action\APIAIAction;

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

(new Dotenv())->load(__DIR__.'/.env'); // Requires a .env file at project root to load configuration (see an example on .env.dist file)

$request = Request::createFromGlobals();
$chatbotPlatform = new ChatbotPlatform([
    new FacebookMessageHandler(), // Enables discussion through Facebook messenger (configuration required in .env file)
    new AjaxMessageHandler(), // Enables discussion through basic HTTP requests
], [
    [new APIAIAction(), 10], // Enables API.AI support (configuration required in .env file)
    new RepeatMessageAction(), // Enables a bot repeating anything you said (useful for testing)
]);

$response = $chatbotPlatform->handleRequest($request);
$response->send();

As you can see, you may pass an action instance or an array with the action instance and the priority it should hold., (*8)

You can then start a server redirecting to this file, and send requests from Facebook or an Ajax script., (*9)

For Facebook usage, please refer to Facebook developers documentation. For Ajax support, you must send POST requests to your server with the following body:, (*10)

{
    "message": "Hello world!",
    "sender": "sender-id",
    "recipient": "recipient-id",
    "discussion_id": "12345"
}

Reply will be returned immediately. Asynchronous replies are also supported using tags. Enable the AsynchronousMessageAction and add to your body a tags: ['ASYNC_GET'] or tags: ['ASYNC_SAVE'] to get or save a message. Messages are removed from the SQLite database when read. This can be used with your own actions to append the required tag to the message when needed., (*11)

Provided features

ChatbotPlatform can be easily extended. It provides by default some message handlers and action providers., (*12)

See ChatbotPlatform/Handler for available message handlers. See ChatbotPlatform/Action for available actions., (*13)

Extensibility

You may add your own message handlers by implementing the MessageHandlerInterface and providing them to the ChatbotPlatform instance., (*14)

You should also add your own actions by implementing the MessageActionInterface to perform custom actions when a message is received (e.g. generating a reply or delegating the task to any external API)., (*15)

The Versions

04/09 2017

dev-master

9999999-dev

A Chatbot platform exchanger

  Sources   Download

MIT

The Requires

 

The Development Requires

by Quentin de Longraye