Slack bot

Updated

Run npm run setup in packages/slack-bot. It opens Slack with the app pre-filled, checks the two keys you paste, sends a test message and saves everything to .env. Then run npm run dev. The bot posts only the most serious calls to

Before you start

You needWhy
A Slack workspace where you may add appsThe bot is a Slack app you create once.
Crowsnest running on port 8000The bot asks it for every answer.
Node.js 20 or newerThe bot is built from source; it is not in a package store.

The bot connects out to Slack, so there is no public web address to set up and no signing secret.

Set it up

The guided setup takes about three minutes.

  1. Run the setup. From the Crowsnest folder:

    bash
    cd packages/slack-bot
    npm install
    npm run setup
  2. Create the app. Setup opens Slack's "create app from manifest" page with every permission and slash command already filled in. Pick a workspace and click Create.

  3. Paste two keys. Setup checks each one with Slack as you paste it.

  4. Choose a channel. Setup posts a test message there and saves the keys to the .env file in the Crowsnest folder.

  5. Start the bot. Run npm run dev.

KeyWhere to find it
Bot key (xoxb-...)The app's OAuth & Permissions page, after you click Install to Workspace.
App key (xapp-...)Basic Information, App-Level Tokens, with the connections:write permission.

Run npm run doctor any time to check the keys, permissions and the backend without changing anything. If Slack refuses to connect, the bot prints what went wrong in plain words and points to this command.

Setting it up by hand

Create the app from packages/slack-bot/slack-app-manifest.json (Slack, Your Apps, Create New App, From a manifest), install it, and put the two keys in .env:

text
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
CROWSNEST_ALERT_CHANNEL=#security

The manifest includes the chat:write.public permission, so the bot can post in any public channel without being invited. For a private channel, invite it with /invite @Crowsnest.

Commands

CommandWhat it does
/crowsnest-scan /path/to/projectScans a project and posts the result. With no path it scans /tmp/project, which is rarely what you want, so always give one.
/crowsnest-investigate left-padChecks one package.
/crowsnest-blast-radius some-loginLists what is affected if one publisher is compromised. A leading @ is fine.
/crowsnest-statusShows how many packages Crowsnest has checked and how many serious calls are open.

The path in /crowsnest-scan is read by the Crowsnest service, so with Docker it must be a folder the container can see (Quickstart).

What it posts on its own

CallIn SlackIn the dashboard
Hold, including Hold marked "urgent"Posted to the channelYes
WatchNoYes
NoteNoYes

Each post has a button that opens the dashboard on the matching page: Horizon, Lookout, Installed or Log.

Settings

Set these in .env. Only the two keys are required.

SettingDefaultPurpose
SLACK_BOT_TOKENnoneThe bot key.
SLACK_APP_TOKENnoneThe app key.
CROWSNEST_ALERT_CHANNEL#securityWhere serious calls are posted.
CROWSNEST_API_URLhttp://localhost:8000Where Crowsnest runs.
CROWSNEST_DASHBOARD_URLhttp://localhost:3000Where the buttons in each post point.

If a key is missing, the bot stops and tells you to run npm run setup. If Crowsnest is not running yet, the bot keeps trying again with longer waits.

If something goes wrong

You seeDo this
"Crowsnest API is unreachable" in SlackStart Crowsnest, or set CROWSNEST_API_URL. The message names the address it tried.
The bot stops at startRun npm run setup, or npm run doctor to see which key is wrong.
A button opens the wrong pageSet CROWSNEST_DASHBOARD_URL to where your dashboard runs.
Nothing is postedOnly Hold calls are posted. Watch and Note stay in the dashboard.

More fixes are on the Troubleshooting page.

Limits

  • It does not post Watch or Note calls. Open the dashboard for those.
  • It does not check installs. Only crowsnest install does that.
  • It does not store your Slack keys safely. They sit in a plain text .env file, so keep it out of version control.
  • It does not run itself. Start it again after a restart of your machine.

See also Configuration and the VS Code extension.

Nib's tip: keep the channel small.