A Meteor wrapper for the Slack API
Add khamoud:slack-api to your applications .meteor/packages file
Alternatively:
meteor add khamoud:slack-api
SlackAPI is a global object server side only*
It is used to make the method calls which can be synchronous or asynchronous.
Asynchronous calls will return a callback with one error argument upon failure or return the object as the second argument upon success.
// async calls
SlackAPI.api.test({good:1}, function(err,res){
console.log(err); // will return null
console.log(res); // will return {"ok":true, "args":{good:1}}
});
SlackAPI.api.test({good:1, error:1}, function(err,res){
console.log(err); // will return {"ok":false, "error":1, "args":{good:1, error:1}}
console.log(res); // will return undefined
});
// sync calls
SlackAPI.api.test({good:1}); // return {"ok":true, "args":{good:1}}
SlackAPI.api.test({good:1, error:1}) // return {"ok":false, "error":1, "args":{good:1, error:1}}Each API method receives arguments for the request, and an optional callback function to execute once the request has completed. The available request parameters are explained for each method below.
Each callback function receives one or two arguments: error and response (one for errors, two for success).
error applicable when there's an issue with the request connection.
response is the request response body parsed as JSON.
- SlackAPI.channels.archive(token, channel, callback)
- SlackAPI.channels.create(token, name, callback)
- SlackAPI.channels.history(token, channel, latest, oldest, inclusive, count, callback)
- SlackAPI.channels.info(token, channel, callback)
- SlackAPI.channels.invite(token, channel, user, callback)
- SlackAPI.channels.join(token, name, callback)
- SlackAPI.channels.kick(token, channel, user, callback)
- SlackAPI.channels.leave(token, channel, callback)
- SlackAPI.channels.list(token, callback)
- SlackAPI.channels.mark(token, channel, name, callback)
- SlackAPI.channels.rename(token, channel, name, callback)
- SlackAPI.channels.setPurpose(token, channel, purpose, callback)
- SlackAPI.channels.setTopic(token, channel, topic, callback)
- SlackAPI.channels.unarchive(token, channel,callback)
- SlackAPI.chat.delete(token, ts, channel, callback)
- SlackAPI.chat.postMessage(token, channelId, message, options, callback)
- SlackAPI.chat.update(token, ts, channel, text, callback)
- SlackAPI.files.delete(token, file, callback)
- SlackAPI.files.info(token, file, count, page, callback)
- SlackAPI.files.list(token, user, ts_from, ts_to, types, count, page, callback)
- SlackAPI.files.upload(token, file, content, filetype, title, initial_comment, channels, callback)
- SlackAPI.groups.archive(token, channel, callback)
- SlackAPI.groups.close(token,channel, callback)
- SlackAPI.groups.create(token, name,callback)
- SlackAPI.groups.createChild(token, channel, callback)
- SlackAPI.groups.history(token, channel, latest, oldest, inclusive, count, callback)
- SlackAPI.groups.info(token, channel, callback)
- SlackAPI.groups.invite(token, channel, user,callback)
- SlackAPI.groups.kick(token, channel, user, callback)
- SlackAPI.groups.leave(token, channel,callback)
- SlackAPI.groups.list(token, exclude_archived, callback)
- SlackAPI.groups.mark(token, channel, ts, callback)
- SlackAPI.groups.open(token, channel, callback)
- SlackAPI.groups.rename(token, channel, name, callback)
- SlackAPI.groups.setPurpose(token, channel, purpose, callback)
- SlackAPI.groups.setTopic(token, channel, topic, callback)
- SlackAPI.groups.unarchive(token, channel, callback)
- SlackAPI.im.close(token, channel, callback)
- SlackAPI.im.history(token, channel, callback)
- SlackAPI.im.list(token, callback)
- SlackAPI.im.mark(token, channel, ts, callback)
- SlackAPI.im.open(token, userId, callback)
- SlackAPI.search.all(token, query, sort, sort_dir, highlight, count, page, callback)
- SlackAPI.search.files(token, query, sort, sort_dir, highlight, count, page, callback)
- SlackAPI.search.messages(token, query, sort, sort_dir, highlight, count, page, callback)
- SlackAPI.users.getPresence(token, callback)
- SlackAPI.users.info(token, userId, callback)
- SlackAPI.users.list(token, callback)
- SlackAPI.users.setActive(token, callback)
- SlackAPI.users.setPresence(token, presence, callback)
I have tested all of the synchronous calls. Their tests can be found in slack-api-tests.js
To run the tests yourself you are going to need an accessToken and a slack userId then you can run the tests with this command.
export USER="U123456789"
export TOKEN="TOKEN"`
meteor test-packages ./
- test async calls