Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Load environment variables from `.env` file (optional)
require('dotenv').config();
const { createEventAdapter } = require('@slack/events-api');
const { WebClient } = require('@slack/web-api');
const passport = require('passport');
const LocalStorage = require('node-localstorage').LocalStorage;
const SlackStrategy = require('@aoberoi/passport-slack').default.Strategy;
const http = require('http');
const express = require('express');
// *** Initialize event adapter using signing secret from environment variables ***
const slackEvents = createEventAdapter(process.env.SLACK_SIGNING_SECRET, {
includeBody: true
});
// Initialize a Local Storage object to store authorization info
// NOTE: This is an insecure method and thus for demo purposes only!
const botAuthorizationStorage = new LocalStorage('./storage');
// Helpers to cache and lookup appropriate client
// NOTE: Not enterprise-ready. if the event was triggered inside a shared channel, this lookup
// could fail but there might be a suitable client from one of the other teams that is within that
// shared channel.
const clients = {};
function getClientByTeamId(teamId) {
if (!clients[teamId] && botAuthorizationStorage.getItem(teamId)) {
clients[teamId] = new WebClient(botAuthorizationStorage.getItem(teamId));
}
import express from "express";
import { createEventAdapter } from "@slack/events-api";
import interactionController from "../controllers/interaction";
import { getChannel } from "../utils/interactions";
import { isValidChannel, getStyleLog } from "../utils";
const router = express.Router();
const slackEvents = createEventAdapter(process.env.SLACK_SIGNIN_EVENTS);
router.use("/events", slackEvents.expressMiddleware());
const handleEvent = async e => {
const channel = getChannel(e);
if (isValidChannel(channel)) {
if (e.type === "article") {
e.origin = "blog";
}
e.type === "reaction_removed"
? interactionController.remove(e)
: interactionController.save(e);
console.log(getStyleLog("blue"), "\nevent:", e);
} else {
console.log(