Skip to main content
The Slack integration works through a Slack app that belongs to the NervesHub instance. Organizations connect a workspace by installing that app. A self-hosted instance has no Slack app until you create one, and Slack stays hidden on every organization’s Integrations page until you do. What an organization admin does afterwards is on the Slack page.

Requirements

  • NervesHub 2.5.0 or later.
  • A Slack workspace to develop the app in, where you can create apps.
  • The instance’s URL. The examples use https://your.nerveshub.host.
  • A SECRETS_ENCRYPTION_KEY. NervesHub encrypts each workspace’s bot token with it. In production, a node with SLACK_CLIENT_ID set and no key refuses to boot.

Choose how Slack reaches the instance

Slack sends events, button clicks and slash commands to the instance. There are two ways for them to arrive: Posting notifications, installing the app and linking accounts work either way. The instance calls Slack to post, and installs and account links go through the person’s browser. Buttons, /nerveshub commands and link previews need one of the two.

Create the app with request URLs

1

Set the secrets encryption key

Generate a key and set it as SECRETS_ENCRYPTION_KEY on every node, if the instance does not have one yet:
2

Create the app from a manifest

Go to api.slack.com/apps. Choose Create New App, then From a manifest, and pick a workspace to develop the app in.Paste the manifest below. Replace your.nerveshub.host with your instance’s host everywhere it appears.
Slack checks the events URL when you save the manifest. The instance must already answer at that URL with SLACK_SIGNING_SECRET set, which it cannot do before the app exists. On a first setup, save the manifest without the event_subscriptions block, finish the remaining steps, then add the block back.
3

Turn on distribution

Under Manage Distribution, turn on public distribution. Without it, only the development workspace can install the app.
4

Set the variables

From the app’s Basic Information page, copy the credentials into the instance’s environment:
5

Restart the instance

Restart every node. Slack now appears on each organization’s Integrations page.
6

Add event subscriptions back

If you saved the manifest without event_subscriptions, add the block back now and save. Slack can verify the events URL once the instance is running with the signing secret.

Create the app with Socket Mode

1

Set the secrets encryption key

Generate a key and set it as SECRETS_ENCRYPTION_KEY on every node, if the instance does not have one yet:
2

Create the app from the Socket Mode manifest

Go to api.slack.com/apps. Choose Create New App, then From a manifest, and pick a workspace to develop the app in.Paste the manifest below. It turns Socket Mode on and has no request URLs. The redirect URLs stay, because only browsers follow them. Replace your.nerveshub.host with your instance’s host.
3

Turn on distribution

Under Manage Distribution, turn on public distribution. Without it, only the development workspace can install the app.
4

Generate an app-level token

Under Basic Information, generate an App-Level Token with the connections:write scope. It starts with xapp-.
5

Set the variables

You do not need SLACK_SIGNING_SECRET. Without it, the instance’s /integrations/slack/ URLs answer 404.
6

Allow outbound connections to Slack

Let the instance reach slack.com and the WebSocket hosts Slack hands out, such as wss-primary.slack.com, over HTTPS.
7

Restart the instance

Restart every node. Slack now appears on each organization’s Integrations page.
Each web node keeps two Socket Mode connections open. Slack replaces every connection every few hours, and the second one carries on while the first reconnects. Slack allows ten connections per app, so an instance can run up to five web nodes in Socket Mode. Nodes started with NERVES_HUB_APP=device open none.

Check that it works

  1. Sign in as an organization admin and open the organization’s Integrations page. An organization with no integrations yet shows a Slack card with an Add to Slack button. Otherwise, Add integration offers Connect a Slack workspace.
  2. Click Add to Slack and approve the install in Slack. Slack sends you back to the Integrations page, which lists the workspace.
  3. Add a Slack channel and use Send test message. The message arrives in the channel.
  4. In Slack, run /nerveshub help. A reply listing the commands confirms that Slack reaches the instance, by request URL or Socket Mode.

Variables

Set these on every node. All are read at boot. Slack is on when SLACK_CLIENT_ID and SLACK_CLIENT_SECRET are set, along with SLACK_SIGNING_SECRET, SLACK_APP_TOKEN, or both.
Changing SECRETS_ENCRYPTION_KEY makes the stored bot tokens unreadable. Every organization would have to connect its workspaces again. The same key also protects two-factor authentication secrets and Teams and Discord webhook URLs.

What the app asks for

The app requests these bot scopes when a workspace installs it: Linking a Slack account to a NervesHub account uses Sign in with Slack, which asks for the openid and profile scopes. NervesHub uses them only to read who signed in, and does not keep that token. The app subscribes to three bot events: app_uninstalled and tokens_revoked, so NervesHub disconnects a workspace that removes the app, and link_shared, for link previews.

Requests from Slack

With request URLs, Slack calls three paths on the instance: Every request there must carry a valid X-Slack-Signature for the app’s signing secret and be no more than five minutes old. NervesHub answers anything else with 401. When the instance has no Slack app, or has no signing secret because it uses Socket Mode alone, these paths answer 404.

Limits

  • Unfurl domain. Register the instance’s own host as its unfurl domain. Slack also matches subdomains of a registered domain, so a parent domain shared by several instances would send each instance’s app the others’ links. When two apps in a workspace register the same domain, Slack sends a link only to the app installed there first.
  • Enterprise Grid. NervesHub refuses organization-wide installs on Slack Enterprise Grid. Install the app in a single workspace.
  • New scopes need a reinstall. Slack only grants new scopes when the app is installed again. If you add scopes to an existing app, each connected workspace has to install it again.

Updating an older app

An app created from an earlier manifest needs these added: