As mentioned earlier, in order to interact with the Slack Real Time Messaging API, we'll be using a Node.js library (npm package) called slackbots
(
https://www.npmjs.com/package/slackbots
).
Before we write any code, let's have a look at the main functions offered by this module by looking at the following short example:
var Bot = require('slackbots'); var settings = { token: 'API TOKEN', name: 'quotebot' }; var bot = new Bot(settings); bot.on('start', function() { bot.postMessageToChannel('channel-name', 'Hi channel.'); bot.postMessageToUser('a-username', 'Hi user.'); bot.postMessageToGroup('a-private-group', 'Hi private group.'); });
Before you run this code, please substitute the strings channel-name
, a-username
and a-private-group
with your own values, taken from your Slack organization.
You'll also need to replace the API TOKEN
string with the quotebot token you were given when the bot was created. The code should now look...