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

https://github.com/paladin-t/bot

Possibly the minimal rule based chatbot implementation in plain JavaScript.
https://github.com/paladin-t/bot

bot chatbot javascript

Last synced: 12 months ago
JSON representation

Possibly the minimal rule based chatbot implementation in plain JavaScript.

Awesome Lists containing this project

README

          

# Bot

Possibly the minimal rule based chatbot implementation in plain JavaScript.

[Demo](https://paladin-t.github.io/)

## Usage

### Pattern configuration

```js
function setUserName (bot, matched) {
bot.setUserName(matched[matched.length - 1]);
bot.post('Call me Toby.');
}

var patterns = [
{
request: [ 'greetings' ],
response: [ 'Hi.', 'Hello.' ],
callback: function (bot) {
if (!bot.getUserName()) {
bot.setNextFailureHandler({
response: [ 'Nice to meet you {USER_NAME}.' ],
callback: setUserName
});
bot.post('What\'s your name?');
}
}
},
{
request: [ 'hi' ],
alias: [ 'greetings' ]
},
{
request: [ 'hello' ],
alias: [ 'greetings' ]
},

{
request: [ 'what', 'your', 'name' ],
response: [ 'Call me Toby.', 'I\'m Toby.' ]
},

{
request: [ 'my', 'name' ],
response: [ 'Nice to meet you {USER_NAME}.' ],
callback: setUserName
},
{
request: [ 'call', 'me' ],
alias: [ 'my', 'name' ]
}
];
```

### Chat

```js
var bot = new Bot.Bot();
patterns.forEach(function (pattern) {
bot.learn(pattern);
});

bot.think('Hi!', function (rsp) {
console.log(rsp);
});
```