Package Exports
- slack
- slack/methods/_exec-browser.js
- slack/methods/_exec.js
- slack/methods/chat.postMessage
- slack/methods/rtm.client-browser.js
- slack/methods/rtm.client.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (slack) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme

Slack Web and RTM API client. 🌱🙌💕
- Writ in es2015 JS, published as es5, tested for Node and the browser
- Web API is all pure functions (no stateful things like classes or using
new) - RTM API has a thin wrapper for
WebSocket(also tested for Node and the browser!) - Perfect symmetry (low level: method sigs match api docs method sigs are node style)
- Opt in (selectivly use the parts of the api surface you want w/o the entire payload)
- Well tested, CI and Apache2 licensed
install 🌟📦
npm i slackusage ✨🚀
slack is tested for Node and the browser.
var slack = require('slack')
// logs {args:{hello:'world'}}
slack.api.test({hello:'world'}, console.log)Usage with es2015 works well too; slack itself is written with Babel. Also nice, you can specify only the methods you need which can trim the payload if you are using slack in the browser.
// only import the one method (and its deps oc)
import test from 'slack/methods/api.test'
// logs {args:{hyper:'card'}}
test({hyper:'card'}, console.log)Starting an RTM session:
import slack from 'slack'
let bot = slack.rtm.client()
let token = process.env.SLACK_TOKEN
bot.hello(message=> {
console.log(`Got a message: ${message}`)
bot.close()
})
bot.listen({token})The entire RTM event API is supported.
test setup 🔒🔑👈
Clone this repo and create a file called .env in the root with the following:
SLACK_TOKEN=xxxx
SLACK_CLIENT_ID=xxxx
SLACK_CLIENT_SECRET=xxxxYou can get a SLACK_TOKEN for testing here. You need to register an app for a SLACK_CLIENT_ID and SLACK_CLIENT_SECRET.
testing 💚💚💚
👉 In Node:
npm test👉 Or the browser:
npm run btest👉 Or kick up a repl and poke around:
<img-src=https://s3-us-west-1.amazonaws.com/bugbot/slack-repl.png>
slack web api 🎉
If the method signature below is not syntax highlighted then it needs parameter validation and tests. See the channels.history for a good example of how to do this if you want to contibute. Of course all contributions are super appreciated! There are many ways this library can be improved. 🐝🚩
api.test(params (err, data)=>)auth.test(token (err, data)=>)channels.archive({token channel}, (err, data)=>)channels.create({token name}, (err, data)=>)channels.history({token channel}, (err, data)=>)channels.info({token, channel}, (err, data)=>)channels.invite({token, channel, user}, (err, data)=>)channels.join({token, name}, (err, data)=>)channels.kick({token, channel, user}, (err, data)=>)channels.leave({token, channel}, (err, data)=>)channels.list({token exclude_archived}, (err, data)=>)channels.mark({token, channel, ts}, (err, data)=>)- channels.rename
- channels.setPurpose
- channels.setTopic
- channels.unarchive
- chat.delete
chat.postMessage({token text, channel}, (err, data)=>)- chat.update
- emoji.list
- files.delete
- files.info
- files.list
- files.upload
- groups.archive
- groups.close
- groups.create
- groups.createChild
- groups.history
- groups.info
- groups.invite
- groups.kick
- groups.leave
- groups.list
- groups.mark
- groups.open
- groups.rename
- groups.setPurpose
- groups.setTopic
- groups.unarchive
- im.close
- im.history
- im.list
- im.mark
- im.open
mpim.close({token channel}, (err, data)=>)mpim.history({token channel}, (err, data)=>)mpim.list({token} (err, data)=>)mpim.mark({token channel, ts}, (err, data)=>)mpim.open({token users}, (err, data)=>)oauth.access({client_id client_secret, code}, (err, data)=>)pins.add({token channel}, (err, data)=>)pins.list({token channel}, (err, data)=>)pins.remove({token channel}, (err, data)=>)- reactions.add
- reactions.get
- reactions.list
- reactions.remove
rtm.start({token} (err, data)=>)- search.all
- search.files
- search.messages
stars.add({token} (err, data)=>)stars.list({token} (err, data)=>)stars.remove({token} (err, data)=>)- team.accessLogs
team.info(token (err, data)=>)- team.info
- usergroups.create
- usergroups.disable
- usergroups.enable
- usergroups.list
- usergroups.update
- usergroups.users.list
- usergroups.users.update
- users.getPresence
- users.info
users.list(token (err, data)=>)- users.setActive
- users.setPresence
slack rtm api
This is currently generated with ./scripts/rtm-events. The event name becomes a function for registering event handlers like so:
var slack = require('slack')
var bot = slack.rtm.client()
bot.hello(console.log)
bot.message(console.log)
bot.listen({token:process.env.SLACK_TOKEN})Try it out by running npm start:
slack.rtm.client() factory
slack.rtm.client() is a factory method that returns an thinly wrapped WebSocket instance with the following API:
var slack = require('slack')
var bot = slack.rtm.client()
var token = process.env.SLACK_TOKEN
// logs: ws, started, close, listen ... in addition to rmt event handler reg methods
console.log(Object.keys(bot))
// rtm.start payload
bot.started(function(payload) {
console.log('payload from rtm.start', paylod)
})
// respond to a user_typing message
bot.user_typing(function(msg) {
console.log('several people are coding', msg)
})
// start listening to the slack team associated to the token
bot.listen({token:token})rtm client api
bot.wsis aWebSocketinstance constructed fromslack/methods/rtm.startpayloadbot.started(payload=>)fires afterrtm.startpayload response is recieved and socket establishedbot.close()closes theWebSocketbot.listen({token})initiates theslack/methods/rtm.starthandshake and delegates all messages
rtm events
Each of these are methods on bot for registering handlers for the events of the same name.
hellomessageuser_typingchannel_markedchannel_createdchannel_joinedchannel_leftchannel_deletedchannel_renamechannel_archivechannel_unarchivechannel_history_changedim_createdim_openim_closeim_markedim_history_changedgroup_joinedgroup_leftgroup_opengroup_closegroup_archivegroup_unarchivegroup_renamegroup_markedgroup_history_changedfile_createdfile_sharedfile_unsharedfile_publicfile_privatefile_changefile_deletedfile_comment_addedfile_comment_editedfile_comment_deletedpin_addedpin_removedpresence_changemanual_presence_changepref_changeuser_changeteam_joinstar_addedstar_removedreaction_addedreaction_removedemoji_changedcommands_changedteam_plan_changeteam_pref_changeteam_renameteam_domain_changeemail_domain_changedbot_addedbot_changedaccounts_changedteam_migration_startedsubteam_createdsubteam_updatedsubteam_self_addedsubteam_self_removed