paladin-t / bot

Possibly the minimal rule based chatbot implementation in plain JavaScript.

Home Page:https://paladin-t.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bot

Possibly the minimal rule based chatbot implementation in plain JavaScript.

Demo

Usage

Pattern configuration

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

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

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

About

Possibly the minimal rule based chatbot implementation in plain JavaScript.

https://paladin-t.github.io/

License:GNU General Public License v3.0


Languages

Language:JavaScript 75.3%Language:HTML 20.4%Language:CSS 4.3%