How to use the @slack/client.CLIENT_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) => {
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
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 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]+'-'+
github sillygwailo / Slack-Twitter / slack-twitter.js View on Github external
var S = require('@slack/client');
var RtmClient = S.RtmClient;
var WebClient = S.WebClient;
var CLIENT_EVENTS = S.CLIENT_EVENTS;

var Twit = require('twit');
var TwitterText = require('twitter-text');
var U = require('url');

var twitterOptions = {
  consumer_key: process.env.TWITTER_CONSUMER_KEY,
  consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
  access_token: process.env.TWITTER_ACCESS_TOKEN_KEY,
  access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
}

var T = new Twit(twitterOptions);

var slackOptions = {
  token: process.env.SLACK_TOKEN,
github FabricLabs / doorman / lib / slack / slackSupport.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...');
    Doorman.Slack = new RtmClient(Doorman.Auth.slack.bot_token);
    Doorman.Slack.c_events = require('@slack/client').CLIENT_EVENTS;
    Doorman.Slack.rtm_events = require('@slack/client').RTM_EVENTS;
    Doorman.Slack.start();
    require('./onEvent/auth-and-connect')(Doorman);
    require('./onEvent/message')(Doorman);
    require('./onEvent/team-join')(Doorman);
  } else {
    console.log(chalk.red('ERROR: Doorman must have a Slack bot token...'));
  }
};
github lvn / botstrap / lib / bot.js View on Github external
'use strict';

var Slack = require('@slack/client'),
  RtmClient = Slack.RtmClient,
  WebClient = Slack.WebClient,
  MemoryDataStore = Slack.MemoryDataStore,
  introject = require('introject'),
  relative = require('require-relative'),
  sequoria = require('sequoria'),
  uuid = require('uuid'),
  util = require('util'),
  truncate = require('truncate'),
  botstrapUtil = require('./util');

let CLIENT_EVENTS = Slack.CLIENT_EVENTS,
  RTM_EVENTS = Slack.RTM_EVENTS;

const MAX_MSG_LEN = 8000;

var constants = require('./constants'),
  Message = require('./message').Message,
  OutgoingMessage = require('./message').OutgoingMessage,
  Thread = require('./thread').Thread,
  Channel = require('./channel').Channel;

var _dispatchCommand = function _dispatchCommand(bot, context, message) {
  if (!message.text || !message.text.startsWith('!')) {
    return;
  }

  var text = message.text.slice(1);
github broidHQ / integrations / broid-slack / lib / core / Adapter.js View on Github external
}
        this.session = new client_1.RtmClient(this.token, { autoReconnect: true });
        this.sessionWeb = new client_1.WebClient(this.token);
        this.session.start();
        const connected = Rx_1.Observable
            .fromEvent(this.session, client_1.CLIENT_EVENTS.RTM.RTM_CONNECTION_OPENED)
            .map(() => Promise.resolve({ type: 'connected', serviceID: this.serviceId() }));
        const authenticated = Rx_1.Observable
            .fromEvent(this.session, client_1.CLIENT_EVENTS.RTM.AUTHENTICATED)
            .map((e) => {
            R.forEach((user) => this.storeUsers.set(user.id, user), e.users || []);
            R.forEach((channel) => this.storeChannels.set(channel.id, channel), e.channels || []);
            return Promise.resolve({ type: 'authenticated', serviceID: this.serviceId() });
        });
        const disconnected = Rx_1.Observable
            .fromEvent(this.session, client_1.CLIENT_EVENTS.RTM.DISCONNECT)
            .map(() => Promise.resolve({ type: 'disconnected', serviceID: this.serviceId() }));
        const rateLimited = Rx_1.Observable
            .fromEvent(this.session, client_1.CLIENT_EVENTS.WEB.RATE_LIMITED)
            .map(() => Promise.resolve({ type: 'rate_limited', serviceID: this.serviceId() }));
        this.connected = true;
        return Rx_1.Observable.merge(connected, authenticated, disconnected, rateLimited)
            .mergeAll();
    }
    disconnect() {
github novoda / spikes / slacker / server / widget / slacker / slacker.js View on Github external
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 MemoryDataStore = require('@slack/client').MemoryDataStore;

var rules = [
  require('./biggest-slacker.js'),
  require('./most-active-channel.js'),
  require('./thanks.js'),
  require('./gallery')
]

var Slacker = function(config) {
  this.messages = [];
  this.index = 0;
  this.ruleIndex = 0;
  this.rtm = new RtmClient(
    config.token,
    { dataStore: new MemoryDataStore() }
github broidHQ / integrations / broid-slack / lib / core / adapter.js View on Github external
connect() {
        if (this.connected) {
            return Rx_1.Observable.of({ type: "connected", serviceID: this.serviceId() });
        }
        if (!this.token) {
            return Rx_1.Observable.throw(new Error("Credential should exist."));
        }
        this.connected = true;
        this.webhookServer = new webHookServer_js_1.default(this.HTTPOptions, this.logLevel);
        this.webhookServer.listen();
        this.session = new client_1.RtmClient(this.token, { autoReconnect: true });
        this.sessionWeb = new client_1.WebClient(this.token);
        this.session.start();
        const connected = Rx_1.Observable
            .fromEvent(this.session, client_1.CLIENT_EVENTS.RTM.RTM_CONNECTION_OPENED)
            .map(() => Promise.resolve({ type: "connected", serviceID: this.serviceId() }));
        const authenticated = Rx_1.Observable
            .fromEvent(this.session, client_1.CLIENT_EVENTS.RTM.AUTHENTICATED)
            .map((e) => {
            R.forEach((user) => this.storeUsers.set(user.id, user), e.users || []);
            R.forEach((channel) => this.storeChannels.set(channel.id, channel), e.channels || []);
            return Promise.resolve({ type: "authenticated", serviceID: this.serviceId() });
        });
        const disconnected = Rx_1.Observable
            .fromEvent(this.session, client_1.CLIENT_EVENTS.RTM.DISCONNECT)
            .map(() => Promise.resolve({ type: "connected", serviceID: this.serviceId() }));
        const rateLimited = Rx_1.Observable
            .fromEvent(this.session, client_1.CLIENT_EVENTS.WEB.RATE_LIMITED)
            .map(() => Promise.resolve({ type: "rate_limited", serviceID: this.serviceId() }));
        return Rx_1.Observable.merge(connected, authenticated, disconnected, rateLimited)
            .mergeAll();