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 = SlackRouter = app = // Configure express with the Slack App settingsconst 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 flowapp // All POST routes expect Slack callback events// and verify against the verification tokenapp
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 OAuthclient_id
- The Slack App client idclient_secret
- The Slack App client secretsigning_secret
- The Slack App signing secretredirect_uri
- The Slack App OAuth redirect uriverification_token
- Slack App verification tokenaccess_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
endpoint
or uri
, args
)
api(An authenticated HTTP client that will post to Slack’s API
message
)
reply(Sends a message back to the channel the event was recieved on
key
, value
)
set(Sets a value in the workspace datastore
key
)
get(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 functionsget
andsave
team_id
)
DataStore.get(This method should return a Promise containing a single workspace info associated to a team_id
team_id
, {}
)
DataStore.save(The method should return a Promise containing the saved workspace info associated to a team_id
team_id
, {}
)
DataStore.update(The method should return a Promise containing the updated workspace info associated to a team_id