UNPKG

@slack/client

Version:

A library for creating a Slack client

35 lines (26 loc) 1.16 kB
var RtmClient = require('@slack/client').RtmClient; var CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS; var RTM_EVENTS = require('@slack/client').RTM_EVENTS; var MemoryDataStore = require('@slack/client').MemoryDataStore; var token = process.env.SLACK_API_TOKEN || ''; var rtm = new RtmClient(token, { logLevel: 'error', // check this out for more on logger: https://github.com/winstonjs/winston dataStore: new MemoryDataStore() // pass a new MemoryDataStore instance to cache information }); rtm.start(); rtm.on(CLIENT_EVENTS.RTM.AUTHENTICATED, function handleRTMAuthenticated() { console.log('RTM client authenticated!'); }); rtm.on(RTM_EVENTS.MESSAGE, function handleRtmMessage(message) { console.log( 'User %s posted a message in %s channel', rtm.dataStore.getUserById(message.user).name, rtm.dataStore.getChannelGroupOrDMById(message.channel).name ); }); rtm.on(RTM_EVENTS.REACTION_ADDED, function handleRtmReactionAdded(reaction) { console.log('Reaction added:', reaction); }); rtm.on(RTM_EVENTS.REACTION_REMOVED, function handleRtmReactionRemoved(reaction) { console.log('Reaction removed:', reaction); });