Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Latest commit

 

History

History
131 lines (81 loc) · 4.87 KB

index.md

File metadata and controls

131 lines (81 loc) · 4.87 KB

Botkit: Building Blocks for Building Bots

npm version badge Dependency status badge MIT License Badge


Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.

Install Botkit

Remix on Glitch

Want to dive right in? Remix one of our starter kits on Glitch. You'll start with a fully functioning app that you can edit and run from the browser!

Remix on Glitch

Command Line Interface

The best way to get started locally with Botkit is by installing our command line tool, and using it to create a new Botkit project. This will install and configure a starter kit for you!

npm install -g yo generator-botkit
yo botkit

Start from Scratch

You can also add Botkit into an existing Node application.

First, add it to your project:

npm install --save botkit

Then, add Botkit to your application code:

let { Botkit } = require('botkit');

const controller = new Botkit(MY_CONFIGURATION);

controller.hears('hello','direct_message', function(bot, message) {
    bot.reply(message,'Hello yourself!');
});

Build Your Bot

Botkit is a programming library, along with a suite of supporting tools and plugins, that provides bot builders a platform independent, language-like interface for building a chatbot or messaging app for any platform. It handles all the nitty gritty technical details, allowing you to focus on building COOL FEATURES for your bot.

The toolkit is designed to provide meaningful building blocks for creating conversational user interfaces - with functions like hears(), ask(), and reply() that do what they say they do.

Hearing Messages

Most bots do their thing by listening for keywords, phrases or patterns in messages from users. Botkit has a special event handler called hears() that makes it easy to configure your bot to listen for this type of trigger.

// listen for a message containing the word "hello", and send a reply
controller.hears('hello','message',async(bot, message) => {
    // do something!
    await bot.reply(message, 'Hello human')
});

Read more about hearing things »

Responding to Events

Bots can respond to non-verbal events as well, like when a new user joins a channel, a file gets uploaded, or a button gets clicked. These events are handled using an event handling pattern that should look familiar to most developers. Most events in Botkit can be replied to like normal messages.

// wait for a new user to join a channel, then say hi
controller.on('channel_join', async(bot, message) => {
    await bot.reply(message,'Welcome to the channel!');
});

See a full list of events and more information about handling them »

Conversation Management

Botkit has a flexible system for handling scripted dialog and transactional conversations involving questions, branching logic, and other dynamic behaviors.

Read about Conversations »

Extend Botkit with Middleware

In addition to taking direct action in response to a certain message or type of event, Botkit can also take passive action on messages as they move through the application using middlewares. Middleware functions work by changing messages, adding new fields, firing alternate events, and modifying or overriding the behavior of Botkit's core features.

Middleware can be used to adjust how Botkit receives, processes, and sends messages. Here is a list of available middleware endpoints.

// Log every message received
controller.middleware.receive.use(function(bot, message, next) {

    // log it
    console.log('RECEIVED: ', message);

    // modify the message
    message.logged = true;

    // continue processing the message
    next();

});

// Log every message sent
controller.middleware.send.use(function(bot, message, next) {

    // log it
    console.log('SENT: ', message);

    // modify the message
    message.logged = true;

    // continue processing the message
    next();

});

What's Next?