0.2.0 • Published 6 years ago

@rowanmanning/knit v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Knit

Knit is an abstraction on top of Botkit which I've pretty much just built for one bot for myself. You're free to use, but it might not get the best level of support and it has only been tested with Slack

NPM version Node.js version support Build status MIT licensed

const bot = new Bot({
	name: 'ExampleBot',
	slackToken: 'xxxx-xxx-xxxx'
});

bot.use(new Bot.Listener.Ambient({
	name: 'example listener',
	trigger: /i'?m hungry/i,
	handler: new Bot.Responder.Message({
		message: `Hello hungry, I'm ${bot.name}`
	})
}));

bot.connect();

Table of Contents

Requirements

Knit requires the following to run:

Usage

This usage guide covers the basics of using Knit. The full API documentation is available here.

Install Knit with npm:

npm install @rowanmanning/knit

Include Knit in your code:

const Bot = require('@rowanmanning/knit');

Create and run a bot:

const bot = new Bot({
	name: 'ExampleBot',
	slackToken: 'xxxx-xxx-xxxx'
});

bot.connect();

Create a listener which responds with a canned message:

// Register a bot listener which listens for a trigger phrase
// and then responds with a standard response
bot.use(new Bot.Listener.Ambient({

	// The name of the listener, used in logging mostly
	name: 'hunger listener',

	// The trigger phrase to listen for. This can be a string,
	// regular expression, or an array of triggers
	trigger: /i'?m hungry/i,

	// The handler can be either a bot responder, or a function.
	// Here, we're using a standard message responder
	handler: new Bot.Responder.Message({
		message: `Hello hungry, I'm ${bot.name}`
	})

}));

API Documentation

You can find the full API Documentation here.

Examples

There are several examples in the example directory. You can run these providing a SLACK_TOKEN environment variable to see them in action.

Contributing

To contribute to Knit, clone this repo locally and commit your code on a separate branch. Please write unit tests for your code, and run the linter before opening a pull-request:

make test    # run all tests
make verify  # run all linters

License

Knit is licensed under the MIT license. Copyright © 2017, Rowan Manning

0.2.0

6 years ago

0.1.0

6 years ago