forked from slackapi/node-slack-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-rtm-client-datastore.js
34 lines (26 loc) · 1.13 KB
/
example-rtm-client-datastore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
});