Constructor
new Bot(options)
Create a Slack bot.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
The bot options.
|
Examples
const bot = new Bot({
name: 'ExampleBot',
slackToken: process.env.SLACK_TOKEN
});
bot.connect()
.then(() => {
console.log('Bot started');
})
.catch((error) => {
console.error(`Bot failed to start: ${error.message}`);
});
Members
Methods
connect() → {Promise}
Connect to Slack.
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.
Parameters:
Name | Type | Description |
---|---|---|
incomingMessage |
Object
|
The Slack message to respond to. |
use(extension) → {*}
Extend the bot's functionality.
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.