All Projects → ashubham → Bot Context

ashubham / Bot Context

Licence: mit
Easy, powerful, functional way to maintain conversational context in chat bots.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Bot Context

Botpress
🤖 Dev tools to reliably understand text and automate conversations. Built-in NLU. Connect & deploy on any messaging channel (Slack, MS Teams, website, Telegram, etc).
Stars: ✭ 9,486 (+21459.09%)
Mutual labels:  bots, chatbots, conversational-ui
Eddi
Scalable Open Source Chatbot Platform. Build multiple Chatbots with NLP, Behavior Rules, API Connector, Templating. Developed in Java, provided with Docker, orchestrated with Kubernetes or Openshift.
Stars: ✭ 171 (+288.64%)
Mutual labels:  ai, bots, conversational-ui
airy
💬 Open source conversational platform to power conversations with an open source Live Chat, Messengers like Facebook Messenger, WhatsApp and more - 💎 UI from Inbox to dashboards - 🤖 Integrations to Conversational AI / NLP tools and standard enterprise software - ⚡ APIs, WebSocket, Webhook - 🔧 Create any conversational experience
Stars: ✭ 299 (+579.55%)
Mutual labels:  bots, conversational-ui, chatbots
Botonic
Build chatbots and conversational experiences using React
Stars: ✭ 144 (+227.27%)
Mutual labels:  bots, chatbots, conversational-ui
Rivescript Js
A RiveScript interpreter for JavaScript. RiveScript is a scripting language for chatterbots.
Stars: ✭ 350 (+695.45%)
Mutual labels:  ai, bots, chatbots
Rivescript Python
A RiveScript interpreter for Python. RiveScript is a scripting language for chatterbots.
Stars: ✭ 142 (+222.73%)
Mutual labels:  ai, bots, chatbots
rivescript-go
A RiveScript interpreter for Go. RiveScript is a scripting language for chatterbots.
Stars: ✭ 56 (+27.27%)
Mutual labels:  bots, chatbots
MyBot
🧠 Create chatbots easily with Bot Framework! 🤖
Stars: ✭ 30 (-31.82%)
Mutual labels:  bots, chatbots
rivescript-java
A RiveScript interpreter for Java. RiveScript is a scripting language for chatterbots.
Stars: ✭ 60 (+36.36%)
Mutual labels:  bots, chatbots
Chat-Bot
Chatbot – is a computer program that simulates a natural human conversation. Users communicate with a chatbot via the chat interface or by voice, like how they would talk to a real person.
Stars: ✭ 26 (-40.91%)
Mutual labels:  bots, chatbots
intelligo.js.org
The official website for Intelligo chatbot framework.
Stars: ✭ 18 (-59.09%)
Mutual labels:  bots, chatbots
Facemoji
😆 A voice chatbot that can imitate your expression. OpenCV+Dlib+Live2D+Moments Recorder+Turing Robot+Iflytek IAT+Iflytek TTS
Stars: ✭ 320 (+627.27%)
Mutual labels:  ai, chatbots
rasa-docker-arm
Rasa Docker image for ARMv7. Runs on a Raspberry Pi.
Stars: ✭ 19 (-56.82%)
Mutual labels:  bots, chatbots
Maratona Bots
Maratona Bots é um curso de capacitação para desenvolvimento de Bots, utilizando APIs e outros serviços de Inteligência Artificial, feito pela comunidade em parceria com a Microsoft.
Stars: ✭ 198 (+350%)
Mutual labels:  ai, bots
Delbot
It understands your voice commands, searches news and knowledge sources, and summarizes and reads out content to you.
Stars: ✭ 191 (+334.09%)
Mutual labels:  ai, bots
intelligo-generator
🛠️ Chatbot generator for Intelligo Framework.
Stars: ✭ 31 (-29.55%)
Mutual labels:  bots, chatbots
Poshbot
Powershell-based bot framework
Stars: ✭ 410 (+831.82%)
Mutual labels:  bots, chatbots
Voice Overlay Ios
🗣 An overlay that gets your user’s voice permission and input as text in a customizable UI
Stars: ✭ 440 (+900%)
Mutual labels:  chatbots, conversational-ui
Ai Chatbot Framework
A python chatbot framework with Natural Language Understanding and Artificial Intelligence.
Stars: ✭ 1,564 (+3454.55%)
Mutual labels:  ai, chatbots
Botfront
Enterprise-grade open source GUI platform for Rasa teams
Stars: ✭ 582 (+1222.73%)
Mutual labels:  chatbots, conversational-ui

bot-context

Coverage Status npm version

A easy and powerful way to maintain conversational context in chat bots. Using function closures. Blog post

Core Concept

context stack

Here we introduce a reactive approach to maintaining the context of conversations.

- Whenever the bot sends a message, set(push) a context(callback) on the stack.
- Whenever the bot recieves a message, match the message in FIFO order to 
  the items on the stack. And call the callback.

The elegant trick here is that when a callback is pushed on the stack, it captures the closure state of the callback function being pushed.

So when we match the context stack on recieving a message, the closure variables and data are maintained, allowing time travel!

Usage

$ npm i bot-context

This is a very basic pizza delivery bot, to demonstrate the usage of bot-context.

// The message recieving module.
let context = require('bot-context');

function onMessageRecieved(message, userId) {
  let ctx = botContext.getOrCreate(userId);
  if(!ctx.isSet()) {
      init(userId); // initialize the actions.
  }

  ctx.match(message, function(err, match, contextCb) {
    if(!err) contextCb(userId, match);
  });
}

The set of actions to send the message:

function init(userId) {
  let ctx = botContext.getOrCreate(userId);
  ctx.set(
      /.*/,  // The base matcher to match anything.
      (match) => getPizzaType(userId));
}

function getPizzaType(userId) {
  let ctx = botContext.getOrCreate(userId);
  ctx.set(
    /(chicken|cheese|veggie)/, 
    (match) => getDeliveryAddress(userId, match)
  );
  sendMessage(userId, "What kind of pizza do you want ?");
}

function getDeliveryAddress(userId, pizzaType) {
  let address = userDataService.getAddress(userID);
  let ctx = botContext.getOrCreate(userId);

  if(address) {
    ctx.set(/(yes|no)/, (reponse) => {
        if(response === 'yes') {
            userDataService.clearAddress(userId);
            getDeliverAddress(userId, pizzaType);
        } else {
            end(userId, pizzaType, address);
        }
    });
    sendMessage(userId, 'Would you like to change your address ?'); 
    return;   
  }

  ctx.set(
    validateAddressUsingGoogleAPI, // Can use some async API method
    (address) => end(userId, pizzaType, address)
  ); // Note that pizzaType is now a closure variable.
  sendMessage(userId, `Please enter the delivery Address.`); 
}

function end(userId, pizzaType, address) {
  sendMessage(userId, `Thank you, a ${pizzaType} pizza, will be` +
    + `delivered to ${address} in 30 mins.`);
} 

Now, if a user after putting his address changes his mind to another pizza type, by just typing the type of the pizza.

Webhooks

WYSIWYG bot creators are the latest hot stuff. Almost all of them allow integration with external tools via http webhooks.

bot-context can easily be used with such bot tools. Please see the example, on how could you setup bot-context as a webservice.

API

var contextMap = require('bot-context');

returns an instance of the ContextMap, the following methods are available on it.

ContextMap extends Map

A map to hold contexts for all users/keys

getOrCreate(uKey: string): Context

Get Or Creates a context given the key.

Parameters

  • uKey unique key to identify a user. string

Returns Context

Context

A context uniqiue for each user. The following methods are available on the context.

set(matchRegex|matcherFn, contextCallback)

Set the current context.

Parameters

  • matchRegex|matchFn (RegExp | Function) Used to match the input
  • contextCallback Callback which is stored in the stack, it can hold references to closure vars.

matcherFn(inputText, callback)

Matcher method called when matching contexts. It is called with the following params.

Parameters

  • text string input text
  • callback(boolean) Function Callback resolving to truthy/falsy value.

contextCallback

Context callback set in the context stack.

### isSet(): boolean

Returns, is there any context set.

match(inputText: string, contextMatchedCallback)

Match an input text to the collection of currently set contexts.

Parameters

  • inputText string text
  • contextMatchedCallback The callback to be called if matched.

contextMatchedCallback

Callback called when a context is matched, with the following values.

Parameters

  • err (string | null) Error if any
  • match any the match returned from the matchFn or regex
  • contextCallback the callback which was previously set to the context stack.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].