wl-slack-chatbot
v1.0.2
Published
Using this package we can post messages to slack channel and other features like scheduling messages, upload files etc.,
Downloads
3
Readme
Node.js wrapper for Slack bot
Using this package we can post messages to slack channel and other features like scheduling messages, upload files etc.,
Installation
npm install wl-slack-chatbot
Initialize
import WLSlackChatbot from 'wl-slack-chatbot';
let wlobj = new WLSlackChatbot('SLACKBOT_API_KEY');
Process steps for getting slack bot key
Usage
Send message to channel
let target = 'any_channel_name'
let message = 'Hello world!'
wlobj.postMessage(target, message)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
Send message to channel at scheduled time
let target = 'any_channel_name'
let message = 'Hello world!'
let timestamp = '1671513293';
wlobj.postScheduleMessage(target, message, timestamp)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
Get list of scheduled messages
let options = {limit:100,cursor:''};
cursor is used for pagination to get next set of results.
wlobj.getScheduledMessages(options)
.then((res) => {
console.log(JSON.stringify(res));
})
.catch((err) => {
console.log(err);
});
Delete scheduled message
let target = 'any_channel_name'
let messageId = 'message_id'
wlobj.deleteScheduledMessage(target, messageId)
.then((res) => {
console.log(JSON.stringify(res));
})
.catch((err) => {
console.log(err);
});
Get list of all channel in workspace
let options = {limit:100,cursor:''};
cursor is used for pagination to get next set of results.
wlobj.getChannels(options)
.then((res) => {
console.log(JSON.stringify(res));
})
.catch((err) => {
console.log(err);
});
Get list of users in workspace
let options = {limit:100,cursor:''};
cursor is used for pagination to get next set of results.
wlobj.getUsers(options)
.then((res) => {
console.log(JSON.stringify(res));
})
.catch((err) => {
console.log(err);
});
Upload file
let options = {
channels: 'any-channel_name',
file: fs.createReadStream('/path/dir/test.jpeg'),
}
wlobj.uploadFile(options)
.then((res) => {
console.log(JSON.stringify(res));
})
.catch((err) => {
console.log(err);
});