Giter Club home page Giter Club logo

chat-js's Introduction

ChatJS: Simple Chatbot for Front-end Applications

ChatJS is a simple JavaScript module that you can generate front-end chat bot feature easy. Using specific search patterns, ChatJS is able to identify user input questions and reply with answers, confusion.

Create a ChatBot

First of all create a chatbot using ChatJS class.

const bot = new ChatJS()

Add Replies

You can add each reply to chatbot. These replies will be analized and return the best that related to the question. addReply() method should contain two inputs such as reply text and filtering data object. Filtering data object should have a keylist and queries. ChatJS always gives more priority to the queries and less priority to keylist. According to those matches, points will be calculated. All of these queries and keylist items should only contain lowercase basic letters. Do not include any symbols or numbers.

bot.addReply('My name is Mr. ChatBot.', {
    keylist : ['your', 'name', 'who', 'you'],
    queries : [
        'what is your name',
        'your name',
        'who are you',
        'may i know your name'
    ]
})

Add Confusions

If chatbot is not able to find a suitable reply, It will select a random confusion that you provide earlier.

bot.addConfusion('Sorry, I didn\'t get that.')
bot.addConfusion('Can you explain more? I didn\'t understood.')

Add Repetitions

When user ask the same question more than once, chatbot will reply to the question, including a repetition reminder. Use {!} sign where you expect the common reply.

bot.addRepetition('As I told you before, {!}')
bot.addRepetition('I think I told you that already.')
bot.addRepetition('{!} Didn\'t I tell you that already?')

Ask Questions

You can use the askQuestion() method to get the possible reply.

const output = bot.askQuestion('What is your name?')

You will receive output including your own question, possible reply and reply type.

{
    "question": "What is your name?",
    "reply": "As I told you before, My name is Mr. ChatBot.",
    "type": "repetition"
}

Check Validation

You can check the question before asking, whether question is valid using isValid() method.

if(bot.isValid(text)) {
    const output = bot.askQuestion(text)
} else {
    // not valid
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.