Simple Slack Bot
This is Node.js library for easy operation with Slack's Real Time Messaging API.
Installation (module)
npm install simple-slack-bot
Events
slack.login
- event fired, when Real Time Messaging API is started (via websocket).slack.logout
- event fired, when bot logout from Slack.ws.message
- event fired, when something happens in Slack. Description of all events here.ws.open
- websocket connection is open and ready to communicate.ws.close
- websocket connection is closed.ws.error
- an error occurred while connecting to Slack.ws.ping
- websocket connection is pinged.ws.pong
- websocket connection is ponged.
Methods
login()
- Start a connection to Real Time Messaging API,logout()
- Logout from Slack and close websocket connection,setCached(enabled)
- Enable/Disable caching (default: true) to keep channels/groups/users updated,getChannels(callback)
- Returns a list of all channels in the team,getGroups(callback)
- Returns a list of all groups in the team,getUsers(callback)
- Returns a list of all users in the team,getChannelByName(name, callback)
- Gets channel by name,getGroupByName(name, callback)
- Gets group by name,getUserByName(name, callback)
- Gets user by name,getChannelId(name, callback)
- Gets channel ID by name,getGroupId(name, callback)
- Gets group ID by name,getUserId(name, callback)
- Gets user ID by name,getChatId(name, callback)
- Returns or opens and returns a direct message channel id,postMessage(id, text, params, [callback])
(return: promise) - posts a message to channel | group | user by id,updateMessage(channelId, timestamp, text, params, [callback])
- updates a message in a channel,postTo(name, message [, params, callback])
- posts a message to channel | group | user by name,postMessageToUser(name, message [, params, callback])
- posts a direct message by user name,postMessageToGroup(name, message [, params, callback])
- posts a message to private group by name,postMessageToChannel(name, message [, params, callback])
- posts a message to channel by name.
Usage
var SlackBot = ; // create a botvar bot = // Slack configuration cached: true // Enable/Disable caching (default: true) token: 'xoxb-012345678-ABC1DFG2HIJ3' // Add a bot https://my.slack.com/services/new/bot and put the token name: 'My Bot' // Websocket connection parameters protocols: ... options: ... }; bot; bot
Credits
- Made with ♥ by SlugBay engineers