An open API service indexing awesome lists of open source software.

https://github.com/dldl/chatbot-platform

Chatbot platform allowing to connect any chat solution to any service provider.
https://github.com/dldl/chatbot-platform

chatbots php php-library

Last synced: 6 months ago
JSON representation

Chatbot platform allowing to connect any chat solution to any service provider.

Awesome Lists containing this project

README

          

# ChatbotPlatform

[![Build Status](https://travis-ci.org/dldl/chatbot-platform.svg?branch=master)](https://travis-ci.org/dldl/chatbot-platform)

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

ChatbotPlatform is a PHP library allowing to build a multiple chatbot platform with multiple
actions providers and multiple sources.

The current implementation allows basic Ajax interactions or Facebook Messenger discussions. It can be extended easily.

## Installation

Install the library using Composer:

```sh
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.

For a basic standalone usage, create an `index.php` file with the following code:

```php
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.

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

For `Facebook` usage, please refer to [Facebook developers](https://developers.facebook.com/docs/messenger-platform) documentation.
For `Ajax` support, you must send *POST* requests to your server with the following body:

```json
{
"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.

## Provided features

ChatbotPlatform can be easily extended. It provides by default some message handlers and action providers.

See `ChatbotPlatform/Handler` for available message handlers. See `ChatbotPlatform/Action` for available actions.

## Extensibility

You may add your own message handlers by implementing the `MessageHandlerInterface` and providing them to the `ChatbotPlatform`
instance.

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).