0.4.6 • Published 5 years ago
@danroshko/slack-bot v0.4.6
Slack bot
Slack client library built on top of node-slack-sdk. Provides more high-level interface for building bots with request-reply flow.
Installation
npm i @danroshko/slack-bot
Usage
const token = process.env.SLACK_TOKEN
const Bot = require('slack-bot')
const channel = 'deployments'
const bot = new Bot(token, channel)
bot.on('ping', ctx => {
ctx.respond('pong')
})
bot.on(/^deploy \w+$/, async ctx => {
const { user, message } = ctx
ctx.assert(user.is_admin, 'Permission denied')
ctx.respond('Doing something...')
await doSomething(ctx.message.text)
ctx.respond('Done')
})
bot.onError(err => {
console.error(err)
})
Context
ctx.message
- message eventctx.user
- user objectctx.channel
- limited channel objectctx.respond
- function to send back a responsectx.assert
- sends back an error message if assertion failsctx.match
- match object