node-slackapis
v0.0.1
Published
Slack Node Client Wrapper
Downloads
3
Readme
Slack Node Client Wrapper
Prerequisite
- Generate a token for your slack workspace. (Official Guide)
- Grap your
Signing Secret
. (Official Guide)
# .env
SLACK_SIGNING_SECRET=
SLACK_TOKEN=
API
events
events.start
: this event should be called before calling otherevents
APIs.
import slack from "node-slackapis";
const PORT = 3000;
slack.events.start(PORT, () => {
console.log(`Listen on ${PORT}`);
});
events.addEvent
import slack from "node-slackapis";
const PORT = 3000;
slack.events.addEvent("app_mention", event => {
const { channel, text } = event;
console.log("app_mention event is triggered");
console.log(`TEXT: ${text}`);
console.log(`Channel ID: ${channel}`);
});
rtm
rtm.start
import slack from "node-slackapis";
slack.rtm.start();
web
web.getChannel
import slack from "node-slackapis";
// by Id
slack.web.getChannel({ id: 'a1b2c3' })
.then(channel => {
// channel = { id: 'a1b2c3', name: 'general' };
})
// by Name
slack.web.getChannel({ name: 'general' })
.then(channel => {
// channel = { id: 'a1b2c3', name: 'general' };
})
web.getUser
import slack from "node-slackapis";
// by Id
slack.web.getUser({ id: 'a1b2c3' })
.then(user => {
// user = { id: 'a1b2c3', name: 'the6thm0nth' };
})
// by Name
slack.web.getUser({ name: 'the6thm0nth' })
.then(user => {
// user = { id: 'a1b2c3', name: 'the6thm0nth' };
})
web.sendMessage
import slack from "node-slackapis";
const channel = await slack.web.getChannel({ name: 'general' });
slack.web.sendMessage(channel.id, "Hello World!");
License
MIT