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.
- Host: GitHub
- URL: https://github.com/paladin-t/bot
- Owner: paladin-t
- License: gpl-3.0
- Created: 2020-11-04T07:51:12.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-05T08:02:18.000Z (over 5 years ago)
- Last Synced: 2025-01-30T20:43:53.305Z (over 1 year ago)
- Topics: bot, chatbot, javascript
- Language: JavaScript
- Homepage: https://paladin-t.github.io/
- Size: 21.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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);
});
```