How to use the @slack/client.RTM_EVENTS 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 automerge / mpl / src / ampl / amplnet / slack-signaler.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 bot_token = process.env.SLACK_BOT_TOKEN || '';

let rtm;// = new RtmClient(bot_token);
let uuidv4 = require('uuid/v4');

function init(config) {
  let HANDLERS = { hello: () => {}, reply: () => {}, offer: () => {}, error: () => {}, connect: () => {}, disconnect: () => {} }
  let CHANNEL;
  let SESSION = config.session || uuidv4()
  let NAME = config.name || "unknown"
  let DOC_ID;
  let last_ts
  let onConnectHandler = () => {}
  let CONNECT_DISPATCH = (h) => {
    onConnectHandler = h
github novoda / spikes / slacker / app.js View on Github external
const token = process.env.token;
var Slack = require('./slack.js');
var RtmClient = require('@slack/client').RtmClient;
var RTM_EVENTS = require('@slack/client').RTM_EVENTS;
var RTM_CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS.RTM;
var slack = new Slack(token);
const GENERAL_CHANNEL_ID = 'C029J9QTH';
const LONDON_CHANNEL_ID = 'C096DG4EN';
const BERLIN_CHANNEL_ID = 'C029K2NUY';
const BARCELONA_CHANNEL_ID = 'C096CQ5QW';
const LIVERPOOL_CHANNEL_ID = 'C054WA0TJ';
const TEST_CHANNEL_ID = 'C09H0TJ9Y';

var latest = new Date();
var oldest = new Date();
oldest.setMinutes(latest.getMinutes() - 1000);

// getBiggestSlacker(oldest, latest, result => {
//   console.log(result);
// });
github FabricLabs / doorman / lib / slack / index.js View on Github external
module.exports = doorman => {
  console.log(chalk.magenta(`Slack enabled.  Starting...`));
  if (doorman.auth.slack && doorman.auth.slack.bot_token) {
    console.log('Logging in to Slack...');

    // initialize Slack client
    doorman.slack = new RTMClient(doorman.auth.slack.bot_token);
    doorman.slack.c_events = Slack.CLIENT_EVENTS;
    doorman.slack.rtm_events = Slack.RTM_EVENTS;

    // TODO: ask naterchrdsn why this is before plugins in the control flow?
    doorman.slack.start();

    // load event handlers?
    require('./onEvent/auth-and-connect')(doorman);
    require('./onEvent/message')(doorman);
    require('./onEvent/team-join')(doorman);
  }
};
github cagataycali / xss-listener / index.js View on Github external
const express = require('express');
const app = express();
require('dotenv').config()
const Datastore = require('nedb');
const db = new Datastore({
  filename: 'out.db',
  autoload: true
});
const bodyParser = require('body-parser');
const Telegram = require('node-telegram-bot-api');
const SlackIncomingWebhook = require('@slack/client').IncomingWebhook;
const RtmClient = require('@slack/client').RtmClient;
const RTM_EVENTS = require('@slack/client').RTM_EVENTS;
let SlackWebhook;
let chatId;
let rtm;
let TelegramBot;
// Middleware usage ..
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: true
}));
app.set('port', (process.env.PORT || 5000));
if (process.env.SLACK_HOOK_URL && process.env.SLACK_RTM_TOKEN) {
  SlackWebhook = new SlackIncomingWebhook(process.env.SLACK_HOOK_URL || '');
  const bot_token = process.env.SLACK_RTM_TOKEN || '';

  rtm = new RtmClient(bot_token);
github automerge / trellis / src / lib / ampl / amplnet / slack-signaler.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 bot_token = process.env.SLACK_BOT_TOKEN || '';

let rtm;// = new RtmClient(bot_token);

var UUID = (function() {
  var self = {};
  var lut = []; for (var i=0; i<256; i++) { lut[i] = (i<16?'0':'')+(i).toString(16); }
  self.generate = function() {
    var d0 = Math.random()*0xffffffff|0;
    var d1 = Math.random()*0xffffffff|0;
    var d2 = Math.random()*0xffffffff|0;
    var d3 = Math.random()*0xffffffff|0;
    return lut[d0&0xff]+lut[d0>>8&0xff]+lut[d0>>16&0xff]+lut[d0>>24&0xff]+'-'+
      lut[d1&0xff]+lut[d1>>8&0xff]+'-'+lut[d1>>16&0x0f|0x40]+lut[d1>>24&0xff]+'-'+
      lut[d2&0x3f|0x80]+lut[d2>>8&0xff]+'-'+lut[d2>>16&0xff]+lut[d2>>24&0xff]+
github Moishe / catbot / catbot.js View on Github external
app.listen(http_port, function(err) {
  if (err) {
    throw err;
  }

  console.log('Listening on ' + http_port);

  var catbotRunner = new catbotModule.CatRunner();

  catbotRunner.init(slackClient.RtmClient, slackClient.RTM_EVENTS, slackToken);
  catbotRunner.start();
});
github ElevenGiants / eleven-server / src / comm / slackChat.js View on Github external
return;
	}
	var logger = getSlackLogger();
	log.debug('connecting to Slack');
	slack = new Slack.RtmClient(token, {
		autoReconnect: true,
		autoMark: true,
		logLevel: 'silly',
		logger: logger,
		dataStore: new Slack.MemoryDataStore({
			logLevel: 'silly',
			logger: logger,
		}),
	});
	slack.on(Slack.CLIENT_EVENTS.RTM.RTM_CONNECTION_OPENED, onSlackOpen);
	slack.on(Slack.RTM_EVENTS.MESSAGE, onSlackMessage);
	slack.on('error', onSlackError);
	slack.login();
}
github lvn / botstrap / lib / constants.js View on Github external
'use strict';

let RTM_EVENTS = require('@slack/client').RTM_EVENTS;

/*
These are all the events that can be fired by the slack-client EventEmitter.
The values of each pair are the semantic names of the corresponding argument
in the event callback. These names will be used to inject the argument into the
context.
TODO: convert all eventArgs to the new style.
*/
let eventArgs = {
  'error': ['error'],
  'loggedIn': ['self', 'team'],
  'error': ['error'],
  'star_added': ['message'],
  'star_removed': ['message'],
  'raw_message': ['message'],
  'presenceChange': ['user', 'presence'],
github lvn / botstrap / lib / message.js View on Github external
'use strict';

let NotImplementedError = require('./constants').NotImplementedError;
let RTM_EVENTS = require('@slack/client').RTM_EVENTS;
let util = require('./util');
let lfmt = require('lfmt');
let truncate = require('truncate');

/*
A message is the most common event in a conversation.

Legacy stuff: The 'response' injected object used to be of a Response
type, but has been replaced with Message, which is a more generalized
abstraction.

In the standard use case, there shouldn't really be a need to manually
construct instances of these types, since the bot should automatically
build and inject them to callbacks.
*/
github nashdev / jobs / server / services / slack / bot.js View on Github external
"use strict";

const Slack = require("@slack/client");
const RtmClient = Slack.RtmClient;
const WebClient = Slack.WebClient;
const MemoryDataStore = Slack.MemoryDataStore;
const RTM_CLIENT_EVENTS = Slack.CLIENT_EVENTS.RTM;
const RTM_EVENTS = Slack.RTM_EVENTS;
const JOBS_CHANNEL = process.env.SLACK_JOBS_CHANNEL;
const pkg = require("../../../package.json");

class Bot {
  constructor(token) {
    this.listeners = [];
    this.rtmClient = new RtmClient(token, {
      logLevel: "error",
      dataStore: new MemoryDataStore(),
      autoReconnect: true,
      autoMark: true
    });

    this.webClient = new WebClient(token);
    this.setupRtmHandlers();
    this.rtmClient.start();