Babybot — /babyfoot on Slack

A Slack bot that gathers four players for a babyfoot game, on one of the office's two tables (RDC and -1). It speaks English (but says « babyfoot »).

  • /babyfoot (no arguments) opens a modal: Time, a dropdown — « Now (14:35) » (now rounded up to 5 min, the time of the Post), then every quarter hour up to 21:00 (BABYFOOT_LAST_TIME) —, Table (RDC by default) and an optional Message (≤ 200 characters, shown as a quote under the title). After 21:00, /babyfoot answers « Babyfoot closes at 21:00 — see you tomorrow! » instead. Post puts « ⚽ @here @user wants to play babyfoot at 12:30 — 📍 RDC » in the channel with a Me too! (N spots left) button.
  • @here while players are missing: it is in the message until the 4th player joins, and that edit removes it (an edit never notifies again). With a Slack user group's id in BABYFOOT_PING (S…: the group → ⋮ → Copy group ID), the bot pings that group instead — only its members are notified, so people can stay in the channel without @here.
  • The creator is player 1 and the organizer; Me too! adds the clicker, I'm out takes them off. Nobody joins twice, and « I'm out » from someone who isn't playing just gets a private reply — Slack shows everyone the same message, so both buttons are there for all. The game's state lives in the buttons' value — no database, and a restart of the bot loses nothing.
  • At four players « Me too! » goes, the message says « Game full! » and the four are mentioned in the thread. « I'm out » stays: leaving a full game reopens the spot, and a thread reply « @x dropped out — 1 spot left @here », also sent to the channel, tells people (the edit itself never notifies).
  • The organizer leaving hands the game to the next player; the last one out turns the message into « Babyfoot at 12:30 (RDC) — cancelled » and frees the table.
  • Double booking: if the table already has a game within 20 minutes of that time, the modal says so under Table and names the free one; pressing Post again books it anyway. The bot remembers the day's games in memory only, so a restart forgets them (and a game posted before it).
  • Games start in #babyfoot only (BABYFOOT_CHANNELS in .env: channel names without # or channel ids, comma-separated; empty = everywhere). A slash command shows up in every channel of the workspace — Slack has no per-channel setting — so elsewhere the bot answers privately (« Games are started in #babyfoot! ») instead of posting. A renamed channel needs its new name here, or use its id (channel details → bottom of About).
  • The bot posts as itself, so it must be in the channel (/invite @Babybot). Not yet invited to a public channel, it falls back to the slash command's reply URL and asks the poster (privately) to invite it; in a private one it tells you to invite it.
  • A game posted through that reply URL isn't the bot's own message: Slack refuses to let it edit it (cant_update_message) or reply in its thread (not_in_channel). So every click falls back to its own reply URL — the button updates the message all the same, private answers stay private, and « Game on! » / « dropped out » become plain channel messages instead of thread replies. A click that still fails answers the clicker « Something went wrong — try again » rather than nothing.
  • The tables are BABYFOOT_TABLES in .env (RDC,-1; the first is the default) — e.g. Ground floor,-1 for English names.

Node 24 + @slack/bolt v4 in Socket Mode: the bot dials out to Slack over a WebSocket, so there is no port, no public URL and no reverse-proxy route.

Where it runs

A Docker container (docker-compose.yml): restart: unless-stopped, read-only root filesystem, no capabilities, no published port, 160 MB memory cap. The image is built on the host from this repo.

File
app.js, package.json, manifest.yml the bot and its Slack app manifest — the handed-over bot, in English, + channel restriction, modal, tables, @here
package-lock.json pins @slack/bolt 4.x for npm ci
Dockerfile node:24-alpine pinned by digest, npm ci --omit=dev, runs as node
docker-compose.yml the service
.env (not in git) BABYFOOT_CHANNELS, BABYFOOT_TABLES, then SLACK_BOT_TOKEN + SLACK_APP_TOKEN, chmod 600 — see .env.example

.env sits next to docker-compose.yml on the host, chmod 600. The maintainer's deploy script (scripts/deploy.sh: token check, sync, build, waits for « ⚽ Babybot started ») is kept out of the repo — it is gitignored.

Run it

docker compose up -d --build   # deploy or update (code, dependencies or tokens)
docker compose logs -f         # logs — « ⚽ Babybot started » once connected
docker compose restart         # restart it

Update: change the code here, commit, rebuild on the host. To move to a newer @slack/bolt 4.x: npm update --package-lock-only, then deploy. To bump Node: change the tag and digest in the Dockerfile (docker buildx imagetools inspect node:<tag>).

Tokens: put the new value in .env, then docker compose up -d.

Slack app

Done once, in a browser, by a workspace member who can install apps:

  1. https://api.slack.com/apps → Create New App → From a manifest → choose the workspace → paste manifest.yml.
  2. Basic Information → App-Level Tokens → Generate with the scope connections:write → the xapp-… token (SLACK_APP_TOKEN).
  3. Install App → Install to Workspace → the Bot User OAuth Token xoxb-… (SLACK_BOT_TOKEN).
  4. Invite the bot to the babyfoot channel: /invite @Babybot.

After a change to manifest.yml (the command's description or usage hint), paste it again in the app's App Manifest page and save — Slack doesn't read it from here. The bot's picture is Basic Information → Display Information → App icon (square, 512–2000 px); the manifest can't set it.

Testing in a DM first

With directmessage in BABYFOOT_CHANNELS (babyfoot,directmessage), the bot also plays in your DM with Babybot — sidebar → Apps → Babybot → Messages (the manifest's app_home turns that tab on). There:

  • /babyfoot → the modal → Post: the same message as in the channel. Its @here notifies nobody: only you and the bot are in a DM.
  • Nobody joins twice, there either: filling a game to 4/4 takes three other people (a private test channel with colleagues — add its channel id).
  • Double booking: post twice at the same time on the same table. DM games only clash with that DM's games, never with #babyfoot's.
  • /babyfoot in a DM between people opens the modal, but posts nothing — it says test games live in Babybot's DM.

Done testing: take directmessage out of .env and redeploy.

Troubleshooting

  • /babyfoot answers dispatch_failed, or nothing: the container isn't running (docker compose ps), or Socket Mode / Interactivity is off in the Slack app.
  • not_allowed_token_type: the two tokens are swapped.
  • The button or the modal does nothing: Interactivity must be on (it is in the manifest) — then read the logs.
  • cant_update_message / not_in_channel in the logs: the bot isn't in the channel (/invite @Babybot). Clicks still work through their reply URL, but the thread pings go to the channel until it's invited.
  • No notification for @here: the workspace may restrict who can use @here (Slack admin → Settings & permissions → Messaging).
  • chat.update fails with channel_not_found in a private channel: invite the bot to that channel.
S
Description
No description provided
Readme
96 KiB
0 Stars 1 Watchers 0 Forks
Languages
JavaScript 96.9%
Dockerfile 3.1%