A simple slackbot using the slack events api
npm install @retsoksirhc/slackbot
npm install @retsoksirhc/slackbot
`
$3
index.js
`js
const SlackBot = require('@retsoksirhc/slackbot');
const MyOwnPlugin = require('./plugins/MyOwnPlugin.js');
const config = {
botUserOAuthToken: "provided by slack",
botSigningSecret: "provided by slack",
botAppToken: "provided by slack",
plugins: [
MyOwnPlugin
]
}
SlackBot.start(config).then((bot) => {
console.log('Bot started');
});
`
./plugins/MyOwnPlugin.js
`js
module.exports = {
init: async (bot) => {
this.bot = bot;
// Post a message to a channel, connect to a database, etc
},
handleMessage: (message) => {
const {trimmedText, fromUser, fromChannel} = message;
if (trimmedText === 'ping') {
this.bot.postMessage(fromChannel, <@${fromUser}> pong!);
}
}
}
``