slack-wrapi
v1.1.0
Published
Slack Web API Client Library
Downloads
69
Maintainers
Readme
Slack Web API
The simplest library for Slack Web API.
Call Slack Web API endpoints just like functions
Installation
Install via npm
npm install slack-wrapi --save
Usage
Create a Slack client with the API token.
const slackWrapi = require('slack-wrapi');
const slack = new slackWrapi(SLACK_API_TOKEN);
// Now you are ready to make API calls to Slack.
Function names match with Slack API endpoints (methods) as per the documentation.
Just provide parameters and a callback or get back a Promise.
API calls follow this syntax:
slack.apigroup.action(queryString, callback);
queryString
- (as required) API method parameters as key-value pairs.
If no callback is provided, the function returns a Promise object.
Post a message with callback:
// ES5 Syntax with callback
slack.chat.postMessage({
"channel": "#general",
"text": "Hello World!"
},
function(err, res) {
if (!err) {
console.log('Message posted: ', res.ts);
}
}
)
Post a message. Get back a Promise:
// ES2015 Promise
slack.chat.postMessage({
"channel": "#general",
"text": "Hello World!"
})
.then((res) => {
console.log('Message posted: ', res.ts);
})
.catch(console.error);
Post a message via async/await:
// ES2017 async/await
(async () => {
try {
const res = await slack.chat.postMessage({
"channel": "#general",
"text": "Hello World!"
});
console.log('Message posted: ', res.ts);
}
catch(err) {
console.error(err);
}
})();
Call any Slack Web API methods with the client object.
Examples
Lists custom emojis for a team.
slack.emoji.list(function(err, data) {
if (!err) {
console.log(data);
}
});
Lists all channels in a Slack team.
slack.channels.list({exclude_archived:1}, function(err, data) {
if (!err) {
console.log(data);
}
});
Gets information about a private group.
slack.groups.info({channel:"G1234567890"}, function(err, data) {
if (!err) {
console.log(data);
}
});
Adds a reaction to an item.
slack.reactions.add({
name: "thumbsup",
file: "F1234567890",
file_comment: "Fc1234567890",
channel:"G1234567890",
timestamp: "1234567890.123456"
},
function(err, data) {
if (!err) {
console.log(data);
}
}
);
Gets information about a user.
slack.users.info({user: "U1234567890"}, function(err, data) {
if (!err) {
console.log(data);
}
});
Post chat messages to Slack.
slack.chat.postMessage({
"channel": "#general",
"text": "Hello <@u12345678|world>!",
"username": "Wrapi Bot",
"as_user": false,
"parse": "full",
"link_names": 1,
"attachments": [{"pretext": "pre-hello", "text": "text-world"}],
"unfurl_links": true,
"unfurl_media": false
},
function(err, data) {
if (!err) {
console.log(data);
}
}
)
Check user's current Do Not Disturb
settings.
slack.dnd.info({
"user": "U1234"
},
function(err, data) {
if (!err) {
console.log(data);
}
}
)
API Methods
api
apps.permissions
apps.permissions.resources
apps.permissions.scopes
apps.permissions.users
apps
auth
bots
channels
- channels.archive
- channels.create
- channels.history
- channels.info
- channels.invite
- channels.join
- channels.kick
- channels.leave
- channels.list
- channels.mark
- channels.rename
- channels.replies
- channels.setPurpose
- channels.setTopic
- channels.unarchive
chat
conversations
- conversations.archive
- conversations.close
- conversations.create
- conversations.history
- conversations.info
- conversations.invite
- conversations.join
- conversations.kick
- conversations.leave
- conversations.list
- conversations.members
- conversations.open
- conversations.rename
- conversations.replies
- conversations.setPurpose
- conversations.setTopic
- conversations.unarchive
dialog
dnd
emoji
files.comments
files
groups
- groups.archive
- groups.create
- groups.createChild
- groups.history
- groups.info
- groups.invite
- groups.kick
- groups.leave
- groups.list
- groups.mark
- groups.open
- groups.rename
- groups.replies
- groups.setPurpose
- groups.setTopic
- groups.unarchive
im
migration
mpim
oauth
pins
reactions
reminders
rtm
search
stars
team
team.profile
usergroups
usergroups.users
users
- users.conversations
- users.deletePhoto
- users.getPresence
- users.identity
- users.info
- users.list
- users.lookupByEmail
- users.setActive
- users.setPhoto
- users.setPresence