bot-kit

0.0.2 • Public • Published

NPM Version

bot-kit

Easy-to-use chat bot framework for node.js with built-in NLP.

Introduction

Use bot-kit to build AI chatbots in a matter of minutes.
bot-kit provides a customizable, intelligent chatbot for use in your applications. The framework allows you to do the following with minimal knowledge of NLP principles:

  1. easily train an AI to understand user messages
  2. instruct your AI to execute actions (functions) based on those messages

Tutorial

  1. Install and include bot-kit in console: npm install bot-kit --save
    in app code:
const botKit = require('bot-kit');
  1. Understand the Intent object and create your intents. Simple explanation: an Intent is a key-value pair that represents a message and an action to take when we receive it. The label field is the message-classification and the action field is a function that the bot will execute when a user message maps to that label. Another way to think about it is label == capability and action === code for that capability. It is important to keep the labels consistent. This means if you have a intent with the label "greeting", then don't have another intent with the label "hello", unless they should have different corresponding actions.
let myIntents = [
    { 'greeting': userId => sendMessage(userId, 'Hello there!') },
    { 'weather': userId => getForecast(new Date()).then(forecast => sendMessage(userId, forcast)) }
];
  1. Create a new instance of the Bot object, which acts as an interface to your bot's brains. The constructor takes in an array of intents. This tutorial uses the example of a chatbot that gives weather reports.
let weatherBot = new botKit.Bot(myIntents);
  1. Before we can train the bot's AI, it needs some data so that it can learn. All you need to provide is some sample data and expected output. It is suggested that about 60-80% of this data should be used for training and the other portion should be used for testing. Also, more data will produce a smarter AI, obviously.
let trainingData = [
    {'What\'s the weather like today?': 'weather'},
    {'Tell me today\'s forecast': 'weather'},
    {'Hi': 'greeting'},
    ...
];
 
let testData = [
    {'What\'s the temperature outside?': 'weather'},
    {'Why, hello there!': 'greeting'},
    ...
];
  1. Train the bot to extract intent labels from user messages. Use the learning data we just created, and (optionally) choose a confidence metric for your test data (defaults to 0.6). This method will Error if the training results is below the confidence threshold. test success rate. Without explaining NLP intricacies, the underlying code uses a technique called classification. Read more about it on natural's github repo.
weatherBot.trainBot(trainingData, testData [,confidence]);
  1. Now you can use your bot to extract intents from user messages.
onMessageReceived(webhook, (message) => {
    return weatherBot.determineMessageIntent(message.text).action(message.senderid);
});

Contributing

If you would like to contribute, please follow these steps:

  1. Open an issue of git.
  2. Fork the code and make your contribution.
  3. Test the code using npm test
  4. Submit a pull request on the master branch.

Thanks for sharing your enthusiasm for chatbots and AI! I'm looking forward to seeing what you all create :D

Future/Road Map

Right now, bot-kit is in initial development, but there are plenty of features on its roadmap. Future features include slots/prompts to further engage a user, dynamic learning, more AI features and support for Amazon Lex (whenever they add me to their beta program -_-). I also plan on integrating a facebook messenger bot app as an optional feature in the next release.

Package Sidebar

Install

npm i bot-kit

Weekly Downloads

2

Version

0.0.2

License

MIT

Last publish

Collaborators

  • elevin