PHPackages                             fylhan/posibrain - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fylhan/posibrain

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fylhan/posibrain
================

A re-usable tchatbot PHP implementation to never be alone again. Hum, wait... What?

v0.2(11y ago)321LGPL-2.1+PHPPHP &gt;=5.3.0

Since Jul 4Pushed 10y ago2 watchersCompare

[ Source](https://github.com/Fylhan/posibrain)[ Packagist](https://packagist.org/packages/fylhan/posibrain)[ RSS](/packages/fylhan-posibrain/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (7)Versions (3)Used By (0)

Posibrain
=========

[](#posibrain)

A re-usable tchatbot PHP implementation to never be alone again. Hum, wait... What? Nothing very intelligent at the moment, a set of predefined sentences lead to an other set of predefined answers. But still, synonyms can be defined, data from the sentence can be used in the answer, and of course the same answer won't be use every time.

*Posibrain*'s name is inspired by Asimov's positronic robots. Yes, as expected, R. Sammy is very silly ;-)

[![Build Status](https://camo.githubusercontent.com/33b316e6f9f2d7b5a97a5e0556f4ec69b5eb8ec1f17aade225040bf42c4f6135/68747470733a2f2f7472617669732d63692e6f72672f46796c68616e2f706f7369627261696e2e737667)](https://travis-ci.org/Fylhan/posibrain)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/635ebb2e0cd0cf56eb110f5d46437df1874d295521f8a285566ceb97e8e4a8bc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f46796c68616e2f706f7369627261696e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Fylhan/posibrain/?branch=master)

Installation &amp; Usage
------------------------

[](#installation--usage)

Use Composer to download and install this library. To do so, create a folder and a file composer.json in it. Add this to the following file:

```
"require": {
    "fylhan/posibrain": "dev-master",
}

```

And install it using the command bellow:

```
> php composer.php install

```

You can also download it, and also download all dependencies and paste them into a "vendor" folder. No configuration is required because it is just an algorithm.

You can easily use it in your code:

```
require '../vendor/autoload.php';
use Posibrain\TchatBot;
// OR without Composer autoload: include_once('src/Posibrain/TchatBot.php');

header("Content-Type: text/html; charset=UTF-8");
$bot = new TchatBot();
$answer = $bot->generateAnswer('Bnmaster', 'Bonjour mon ami !', time());
echo @$answer[1].' : '.$answer[0].'';
// May display for example: 'R. Sammy: Salutations noble ami.'

```

Or even using command line:

```
Usage: php app/console submit "User message" ["User name"]
> php app/console submit "Bonjour mon ami"
R. Sammy: Salutations noble ami.

```

In command line you can also start an interactive tchat with the bot:

```
Usage: php app/console discuss ["User name"]
> php app/console discuss
What is your name? (Anonymous) Fylhan
You can start to discuss with the bot... Have a good tchat!

Fylhan: Salut !
R. Sammy: Tu vas bien ?

Fylhan: Oui je vais bien ! Comment fait-on cuire tu riz ?
R. Sammy: Moules à gaufres ! Demande à Wikipédia.

Fylhan: Aurevoir
R. Sammy: A bientôt ! Sale vilaine bête de tonnerre de Brest !

See you soon!

```

Or you can list available bots and positrons (i.e. plugins) :

```
> php app/console bots
[0] R. Sammy alias Sammy: made the 11th of July 2013 by Fylhan
[1] R. Sammy ISO: made the 30th of August 2013 by Fylhan
> php app/console positrons
[0] Haddock/HaddockPositron
[1] Instinct/InstinctPositron

```

Or the REST API

```
GET /api/bots
GET /api/positrons
GET /api/submit/bot-id/bot-lang?pseudo=Fylhan&msg=Qui est le président des Etats-Unis ?

```

How to test?
------------

[](#how-to-test)

Open the file [dynamic.php](https://github.com/Fylhan/posibrain/blob/master/example/dynamic.php) in a browser to open an interactive tchat with R. Sammy, the crazy stupid bot. At the moment, an old tchatbot version is also installed on the [Bnbox minitchat](http://la-bnbox.fr) (fr), you can try to speak with him in French by beginning your sentences by "@Hari": "@Hary Salut !".

For a static example, open the file [static.php](https://github.com/Fylhan/posibrain/blob/master/example/static.php) in a browser. A list of sentences, and their bot answer, will be displayed. Check the "logs" folder if you encounter some issues.

[![Posibrain discussion example](https://camo.githubusercontent.com/f2b05e27a769ab1b72e86c2a059f1c1cefe292b258c3d2a7944ae4b9a9713047/68747470733a2f2f7261772e6769746875622e636f6d2f46796c68616e2f706f7369627261696e2f6d61737465722f646f632f7463686174626f742d6578616d706c652e706e67)](https://camo.githubusercontent.com/f2b05e27a769ab1b72e86c2a059f1c1cefe292b258c3d2a7944ae4b9a9713047/68747470733a2f2f7261772e6769746875622e636f6d2f46796c68616e2f706f7369627261696e2f6d61737465722f646f632f7463686174626f742d6578616d706c652e706e67)

You can also run unit tests using PHPUnit by running the "phpunit" command.

How to use and modify?
----------------------

[](#how-to-use-and-modify)

This documentation will be enhanced from time to time.

### Create a new Positron

[](#create-a-new-positron)

A "Positron" is a plugin that will add intelligence and features to a bot. It is a PHP class extending [\\Posibrain\\Positron\\Positron](https://github.com/Fylhan/posibrain/blob/master/src/Posibrain/Positron/Positron.php). The file name and class name follow the pattern: src/Posibrain/Positron/XXX/XXXPositron.php. The class should be in the namespace \\Posibrain\\Positron\\XXX.

To check an example, please have a look to the [Haddock Positron](https://github.com/Fylhan/posibrain/tree/master/src/Posibrain/Positron/Haddock) which adds 'Captain Haddock like insults' in the bot's answers.

A Positron may override several methods in order to select when to launch this positron, or to help other positrons to do their job, or to perform a new feature by itself.

- isPositronTriggered(TchatMessage $request)
- isBotTriggered(TchatMessage $request, $currentValue = true)
- analyseRequest(TchatMessage $request, AnalysedRequest $currentAnalysedRequest = null)
- isPositronStillTriggered(AnalysedRequest $request)
- isBotStillTriggered(AnalysedRequest $request, $currentValue = true)
- loadMemory(AnalysedRequest $request, $currentMemory = null)
- transformLoadedMemory(AnalysedRequest $request, $memory, $currentMemory = null)
- generateSymbolicAnswer(AnalysedRequest $request, $memory, TchatMessage $currentAnswer = null)
- provideMeaning(AnalysedRequest $request, $memory, TchatMessage $answer, TchatMessage $currentAnswer = null)
- beautifyAnswer(AnalysedRequest $request, $memory, TchatMessage $answer, TchatMessage $currentAnswer = null)
- updateMemory(AnalysedRequest $request, $memory, TchatMessage $answer)

Work in progress
----------------

[](#work-in-progress)

A lot of things are in progress! I have created a first version of the bot algorithm, with a quick knowledge database. I am currently working on the package improvement (command line, API usability, brain selection, languages, plugin management). This is not the main goal of this project, but this is important to use it, and (eventually) contribute to it. Then... we will be able to increase this tchatbot intelligence :D

- \[████100%\] Add Composer support
- \[████100%\] Find a proper name -&gt; *Posibrain*. Inspired by the "Robots" books of Isaac Asimov and his positronic robots.
- \[████ 98%\] Provide a way to select between several brains. \[miss unit tests\]
- \[████ 98%\] Manage several languages: ok. Only one fr brain is available. \[miss unit tests\]
- \[██▒▒ 50%\] Manage several charsets, not only UTF-8. Knowledge loading/storing should be good (to be checked), but bot reply charset is not done yet.
- \[███▒ 75%\] Check and improve folder structure. Currently: src/Posibrain, app/brains
- \[███▒ 85%\] Add command line support: discussion mode, submit one sentance, list bots and positrons. More to come!
- \[███▒ 75%\] Add REST API: submit one sentance, list bots and positrons. More to come!
- \[██▒▒ 50%\] Plugin management (to modify a bot behaviour. E.g. search a link in a Shaarli...). A plugin is called a "Positron" and must be a class extending Posibrain\\Positron\\Positron and with a class name finished by "Positron".
- \[████100%\] Create an interactive tchat example
- \[█▒▒▒ 10%\] Add proper documentation
- \[████100%\] Add unit test engine: PHPUnit
- \[█▒▒▒ 10%\] Add more unit tests
- \[█▒▒▒ 10%\] Update the first brain's knowledge
- \[█▒▒▒ 10%\] Increase knowledge syntax possibilities (use Twig syntax instead if possible, add support for ${name, conceptorName, lang, birthday, userName} everywhere in responses or questions).
- \[▒▒▒▒ 0% \] Add discussion log that will be used by the bot to learn and be a little bit more intelligent
- \[▒▒▒▒ 0% \] Add more and more intelligence!

Licensing
---------

[](#licensing)

This piece of code is a free software under [LGPL v3](http://choosealicense.com/licenses/lgpl-v./). See [LICENSE file](https://github.com/Fylhan/tchatbot/blob/master/LICENSE) for more information. If this license is an issue for you, don't hesitate to contact me, I am very open on this :D

To summarize:

- Required
    - License and copyright notice
    - Disclose your modified Source if you re-distribute this software
- Permitted
    - Commercial Use
    - Modification
    - Distribution
    - Sub-licensing
    - Patent Grant
- Forbidden
    - Hold Liable

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Total

2

Last Release

4304d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/900695?v=4)[Fylhan](/maintainers/Fylhan)[@Fylhan](https://github.com/Fylhan)

---

Top Contributors

[![Fylhan](https://avatars.githubusercontent.com/u/900695?v=4)](https://github.com/Fylhan "Fylhan (34 commits)")[![oliviermaridat](https://avatars.githubusercontent.com/u/953989?v=4)](https://github.com/oliviermaridat "oliviermaridat (8 commits)")

---

Tags

iachatterbottchatbot

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fylhan-posibrain/health.svg)

```
[![Health](https://phpackages.com/badges/fylhan-posibrain/health.svg)](https://phpackages.com/packages/fylhan-posibrain)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
