How to use the @slack/events-api.createEventAdapter function in @slack/events-api

To help you get started, we’ve selected a few @slack/events-api 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 slackapi / node-slack-sdk / examples / greet-and-react / index.js View on Github external
// 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));
  }
github universoimpulso / atena / routes / slack.js View on Github external
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(

@slack/events-api

Official library for using the Slack Platform's Web API

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis