The simplest library for Slack Web API.
Call Slack Web API endpoints just like functions
Install via npm
npm install slack-wrapi --save
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.
// ES5 Syntax with callback
slack.chat.postMessage({
"channel": "#general",
"text": "Hello World!"
},
function(err, res) {
if (!err) {
console.log('Message posted: ', res.ts);
}
}
)
// ES2015 Promise
slack.chat.postMessage({
"channel": "#general",
"text": "Hello World!"
})
.then((res) => {
console.log('Message posted: ', res.ts);
})
.catch(console.error);
// 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.
slack.emoji.list(function(err, data) {
if (!err) {
console.log(data);
}
});
slack.channels.list({exclude_archived:1}, function(err, data) {
if (!err) {
console.log(data);
}
});
slack.groups.info({channel:"G1234567890"}, function(err, data) {
if (!err) {
console.log(data);
}
});
slack.reactions.add({
name: "thumbsup",
file: "F1234567890",
file_comment: "Fc1234567890",
channel:"G1234567890",
timestamp: "1234567890.123456"
},
function(err, data) {
if (!err) {
console.log(data);
}
}
);
slack.users.info({user: "U1234567890"}, function(err, data) {
if (!err) {
console.log(data);
}
});
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);
}
}
)
slack.dnd.info({
"user": "U1234"
},
function(err, data) {
if (!err) {
console.log(data);
}
}
)
- 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.delete
- chat.getPermalink
- chat.meMessage
- chat.postEphemeral
- chat.postMessage
- chat.unfurl
- chat.update
- 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
- 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