How to use the @slack/client.MemoryDataStore function in @slack/client

To help you get started, we’ve selected a few @slack/client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jnummelin / kontena-slack-bot / index.js View on Github external
var exec = require('child_process').exec;
const stripAnsi = require('strip-ansi');

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 bot_token = process.env.SLACK_TOKEN || '';

var rtm = new RtmClient(bot_token, {
  logLevel: 'error',
  dataStore: new MemoryDataStore()
});

var botName = process.env.BOT_NAME || 'kontenabot';
var botKeyword = botName + ':';

console.log('Waiting for keyword "' + botKeyword + '"')

// Setup crude way to allow only specified users
allowChecker = function(user) {
  return true;
}
var allowedUsers = [];
if(process.env.ALLOWED_USERS) {
  allowedUsers = process.env.ALLOWED_USERS.split(',');
  allowChecker = function(userId) {
    var user = rtm.dataStore.getUserById(userId);
github slackapi / node-slack-sdk / examples / example-rtm-client-datastore.js View on Github external
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
  );
});
github LeanKit-Labs / cowpoke / src / slack.js View on Github external
module.exports = function( token, channels, logger ) {
	if ( !token ) {
		console.warn( "Slack is not configured. No Messages will be sent" );
		return {
			send() {}
		};
	}

	const rtm = new RtmClient( token, {
		// Sets the level of logging we require
		logLevel: "warn",
		// Initialise a data store for our client, this will load additional helper functions for the storing and retrieval of data
		dataStore: new MemoryDataStore(),
		// Boolean indicating whether Slack should automatically reconnect after an error response
		autoReconnect: false,
		// Boolean indicating whether each message should be marked as read or not after it is processed
		autoMark: true
	} );

	rtm.on( CLIENT_EVENTS.RTM.AUTHENTICATED, rtmStartData => {
		console.log( `Logged in as ${ rtmStartData.self.name } of team ${ rtmStartData.team.name }, but not yet connected to a channel` );
	} );
	rtm.on( CLIENT_EVENTS.RTM.DISCONNECT, () => {
		console.warn( "Disconnected from slack" );
		rtm.reconnect();
	} );
	rtm.on( CLIENT_EVENTS.RTM.ATTEMPTING_RECONNECT, () => {
		console.warn( "Attempting reconnect to slack" );
	} );
github htilly / zenmusic / index.js View on Github external
'Would some harp music be better?'
]

let voteCounter = 0
const voteLimitPerUser = 1
let voteScore = {}
let gongBanned = false
let gongTrack = '' // What track was a GONG called on

const RtmClient = require('@slack/client').RtmClient
const RTM_EVENTS = require('@slack/client').RTM_EVENTS
const MemoryDataStore = require('@slack/client').MemoryDataStore

let slack = new RtmClient(token, {
  logLevel: 'error',
  dataStore: new MemoryDataStore(),
  autoReconnect: true,
  autoMark: true
})


/* Slack handlers */
slack.on('open', function () {
  var channel, group, id
  var channels = [standardChannel]
  var groups = []
  channels = (function () {
    var _ref, _results
    _ref = slack.channels
    _results = []
    for (id in _ref) {
      channel = _ref[id]
github denouche / virtual-assistant / src / interface / slack-service.js View on Github external
init() {
        if(!this.slackToken) {
            throw "Missing slack token. You must instanciate this interface with the slack token as parameter";
        }

        this.slack = new RtmClient(process.env.SLACK_TOKEN, {
            logLevel: 'warning',
            dataStore: new MemoryDataStore()
        });
        this.slack.on(CLIENT_EVENTS.RTM.AUTHENTICATED, (rtmStartData) => {
            this.authenticatedUserId = rtmStartData.self.id;

            var channels = Object.keys(rtmStartData.channels)
                .map((k) => { return rtmStartData.channels[k]; })
                .filter((c) => { return c.is_member; })
                .map((c) => { return c.name; });
         
            var groups = Object.keys(rtmStartData.groups)
                .map((k) => { return rtmStartData.groups[k]; })
                .filter((g) => { return g.is_open && !g.is_archived; })
                .map((g) => { return g.name; });
         
            debug('Welcome to Slack. You are ' + rtmStartData.self.name + ' of ' + rtmStartData.team.name);
github FoundersFounders / door-services / door-open-service / node-backend / src / DoorSlackBot.js View on Github external
constructor(config) {
    this.rtm = new RtmClient(config.botToken, {
      dataStore: new MemoryDataStore(),
      autoReconnect: true
    });

    this.doorTimes = JSON.parse(JSON.stringify(config.doorTimes));
    this.msgCallbacks = [];

    this.rtm.on(CLIENT_EVENTS.RTM.AUTHENTICATED, rtmStartData => {
      console.log(`Logged in as ${rtmStartData.self.name}`);
    });

    this.rtm.on(CLIENT_EVENTS.RTM.RTM_CONNECTION_OPENED, () => {
      console.log("Opened RTM connection");
      this.channelInfo = this.rtm.dataStore.getChannelOrGroupByName(config.channel);
    });

    this.rtm.on(RTM_EVENTS.MESSAGE, rawData => {
github novoda / spikes / slacker / server / widget / slacker / slacker.js View on Github external
var Slacker = function(config) {
  this.messages = [];
  this.index = 0;
  this.ruleIndex = 0;
  this.rtm = new RtmClient(
    config.token,
    { dataStore: new MemoryDataStore() }
  );
  this.rtm.start();
  this.rtm.on(RTM_EVENTS.MESSAGE, messageHandler(this));
}
github SphereSoftware / RebelChat / lib / Slack.js View on Github external
constructor(options) {
    this.id = options.team_id || options.id
    this.userId = options.user_id || options.userId
    this.name = options.team_name || options.name
    this.accessToken = options.access_token || options.accessToken

    this.rtm = new RtmClient(this.accessToken, {
      logLevel: 'debug',
      dataStore: new MemoryDataStore(),
    })

    this.web = new WebClient(this.accessToken)
    this.bind()
  }
github ggauravr / slack-terminalize / dispatcher.js View on Github external
'use strict';

var logger = require('winston'),
	
	MemoryDataStore = require('@slack/client').MemoryDataStore,
	dataStore = new MemoryDataStore(),

	util = {
		config: require('./util/config'),
		command: require('./util/command')
	},
	
	path = require('path'),
	
	handlers,
	commands,
	slackClient;

/**
 * Reads commands.json from CONFIG_DIR and sets up handlers.
 * Handlers are expected to have the same name as the command, i.e.
 * of the pattern {command-name}.js