Bot

Bot

Class representing a Slack bot.

Constructor

new Bot(options)

Create a Slack bot.
Source:
Parameters:
Name Type Description
options Object The bot options.
Name Type Attributes Default Description
name String The bot's name.
slackToken String The token to use when connecting to Slack.
includeBotkitLogs Boolean <optional>
false Whether to include Botkit logs in the output.
includeBotkitDebugLogs Boolean <optional>
false Whether to include Botkit debug logs in the output.
log Object <optional>
A logger which has `error` and `info` methods.
Examples

Create a Slack bot, passing in options

const bot = new Bot({
    name: 'ExampleBot',
    slackToken: process.env.SLACK_TOKEN
});

Start the bot

bot.connect()
    .then(() => {
        console.log('Bot started');
    })
    .catch((error) => {
        console.error(`Bot failed to start: ${error.message}`);
    });

Members

(static) Alias

Source:
See:

(static) defaults

The default options used when constructing a bot.
Source:

(static) Listener

Source:
See:

(static) Responder

Source:
See:

(static) Response

Source:
See:

Methods

connect() → {Promise}

Connect to Slack.
Source:
Returns:
Type:
Promise
A promise which resolves when a connection is made.

replyTo(incomingMessage) → {Response}

Respond to an incoming message. This method is a shortcut to creating a new Response object and setting the incoming message.
Source:
Parameters:
Name Type Description
incomingMessage Object The Slack message to respond to.
Returns:
Type:
Response
The created response.

use(extension) → {*}

Extend the bot's functionality.
Source:
Parameters:
Name Type Description
extension Alias | function | Listener | String The extension. If this is an Alias or Listener, it will be registered to the bot. If this is a function, it will be called with the bot as a first argument. If this is a string, it will be required as a module and run through this method again.
Throws:
Will throw if the extension type is invalid.
Type
TypeError
Returns:
Type:
*
The return value of the extension call.