Git Product home page Git Product logo

toombot's Introduction

Toombot

This project provides a framework for building chatbots on slack, using Watson to enable advanced features.

to run, clone this repo, npm install, npm run build and npm start

you will need to set the SLACK_TOKEN environment variable, as well as environment variables for everything in config.js.

Intro

Toombot is currently comprised of 3 components - many actors called minions, a core scheduler that manages these minions, and a knowledge graph that retains a model of the world.

At a high level, a minion takes slack messages as input and outputs either responses to those messages in chat, or outputs an enrichment to the message. An enrichment is anything that could be useful in analyzing and acting on a message later. A few example enrichments: the results of alchemy language on the message text, the past 5 minutes of text, an array of all urls mentioned in the message, meta-data on those urls, etc. Other minions can then accept these enrichments as inputs. In this way, we build a powerful ecosystem of minions over time that make it easier and easier to build advanced features into your chatbot.

schema

A minion can require the outputs of other minons, and instead of being passed a regular slack message it will be passed the result of all those enrichments on the slack message. The core scheduler will make sure the minions are run in the right order, and will combine the outputs of the requirements to deliver the correct payload to your minion. It will also handle passing responses up the chain to be sent back to slack if desired.

Minions are implemented as generators that yield promises. This gives you an easy conversational interface and keeps the state of your interactions inside of a single function closure. For example:

function* onMessage(message : SlackMessage) : Iterator<Promise<MinonResponse>> {
	if(message.search(/hello/gi) == -1) {
		return Promise.resolve({
			text: "didnt say hello",
			send: true
		})
	}
	
	const response : SlackMessage = yield Promise.resolve({ text: "Hi, what is your name?", send: true });
	
	const name = response.text;
	
	return Promise.resolve({
		text: `Hello, ${name}`,
		send: true
	})
}

Here, you first see if the message said hello and if it doesnt you return "didn't say hello". Otherwise, you yield "hi what's your name" and assume that ther person will just respond with their name. You then use that information to say hello to them. Notice that the result of yield is a SlackMessage - this will wait until someone responds and then continue down the rest of your code. In addition, you can add a requirements field to your yielded result and get passed enriched messages. A good example is in minions/hello.ts. There is also a concept of context - since a minion can live for a long time, you generally want to respond to messages from the same channel. Maybe you want to respond to messages from the same channel and user - whatever it is, it's accomplished by supplying a contextMatch function in your yielded response which is given a SlackMessage as input and returns a boolean. If not supplied, it will automatically assume same channel.

There are several minions that take various inputs and write to a knowledge graph, powered by neo4j. Neo4j is always accessible to any of the minions, and as people talk over time a rich model of each of the participants in the slack emerges. Currently each message is logged, as well as all of the alchemy language features of that message, links that are shared, and metadata on those links from OG tags. Most interestingly, messages that are in the form "I think that ...." and "Barack Obama is ...." are logged, and start to give an idea about the mental models of other people in the slack.

Technical

A minion is a module with a {key: string, onMessage: fn, filter: fn, requirements: []}. The most important component of a minion is the onMessage generator function, which has to return promises.

The example to look at to get started with minions is minions/hello.ts. Important base type definitions are in types.d.ts.

Services used

  • Alchemy Language
  • Relationship Extraction
  • Tone Analyzer
  • Google Maps
  • WolframAlpha
  • Natural Language Classifier
  • Genius

toombot's People

Contributors

taimur38 avatar

Watchers

 avatar

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.