npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

slack-router

v1.12.0

Published

An express.js router for Slack Apps

Downloads

71

Readme

Slack Router

Start building a Slack App quickly with OAuth support, url parsing, and authenticated HTTPS client to call Slack’s API. This was made to build Slack Apps on Glitch even faster, but it works anywhere.

Install

npm i slack-router

Usage

const express = require('express'),
  SlackRouter = require('slack-router'),
  app = express()

// Configure express with the Slack App settings
const slackRouter = new SlackRouter({
  scope: 'chat:write,bot',
  client_id: "XXXXXXXXXXXXXXXXXXXXX",
  client_secret: "XXXXXXXXXXXXXXXXX",
  signing_secret: "XXXXXXXXXXXXXXXX",
  verification_token: "XXXXXXXXXXXX", // optional
  redirect_uri: 'XXXXXXXXXXXXX'       // optional
  datastore: '.data/workspaces'       // optional
})

// All GET routes redirect to the “Add to Slack” OAuth flow
app.get('/', slackRouter, (req, res) => {
  
  // a writeable datastore associated to the workspace
  req.slack.data
})

// All POST routes expect Slack callback events
// and verify against the verification token
app.post('/', slackRouter, (req, res) => {

  // a writeable datastore associated to the workspace
  req.slack.data

  // the api function auto-appends the workspace’s token
  req.slack.api('users.info', { user: req.slack.user.id }).then(r => {
    r.data // the results of 'users.info' API request
  })
  
})

Features

☑ OAuth support without 3rd-party database

☑ Supports Single Channel Installations single_channel=true

☑ Verifies request signatures and/or verification tokens

☑ Support for short-lived tokens with automatic refresh

☑ Automatic retrieval of workspace's authentication info

☑ Auto-parsing of string-encoded JSON payloads

☑ Authenticated HTTP client for Slack's API

☑ Writeable datastore associated to the workspace

Configuration

The configuration options used for the constructor

  • scope - A comma-delimited scopes for Slack OAuth
  • client_id - The Slack App client id
  • client_secret - The Slack App client secret
  • signing_secret - The Slack App signing secret
  • redirect_uri - The Slack App OAuth redirect uri
  • verification_token - Slack App verification token
  • access_token - Access token to use when the App is not distributed (optional)
  • datastore - A file name to write workspace info to or pass in an object to use an alternate datastore (optional)
  • slack_root - The root domain to make Slack requests to (optional)

Slack Request

The Slack record object is appended to all requests where the router is used. It is a Object that can be written to and saved for future requests.

data

The datastore associated to the workspace

app_url

The redirect url to open the App DM in Slack

api(endpoint or uri, args)

An authenticated HTTP client that will post to Slack’s API

reply(message)

Sends a message back to the channel the event was recieved on

set(key, value)

Sets a value in the workspace datastore

get(key)

Returns a value from the workspace datastore

DataStore Interface

The default datastore is file-based and stored at .data/workspaces. If you would like to change this, there are two options:

  • Passing in a new file path to datastore will attempt to use that file path
  • Passing in a new Object to datastore will attempt to call two functions get and save

DataStore.get(team_id)

This method should return a Promise containing a single workspace info associated to a team_id

DataStore.save(team_id, {})

The method should return a Promise containing the saved workspace info associated to a team_id

DataStore.update(team_id, {})

The method should return a Promise containing the updated workspace info associated to a team_id