Slack Pins Lifecycle Hygiene Bot Prompt
Build a bot that auto-pins the canonical incident summary and current status message in a channel, and unpins stale pinned messages once an incident resolves, keeping pinned context noise-free via pins.add and pins.remove
- Target user
- Incident automation engineers and SRE tooling teams
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform engineer who builds Slack apps and incident-tooling bots on Bolt and the Slack Web API. I will provide: - The events that should trigger a pin (e.g. incident opened, status update posted) and what should be unpinned on resolve - The message metadata or convention I use to identify "the canonical summary" vs ad-hoc chatter - My current scopes and whether the bot listens via Events API or Socket Mode Your job: 1. **Pin lifecycle model** — define the state machine: which message gets pinned on open, how a newer status message replaces the previous pin, and what unpins on resolve. 2. **API plumbing** — show `pins.add`, `pins.remove`, and `pins.list` usage, including how `pins.add` is keyed by channel + timestamp and is idempotent-safe to retry. 3. **Replace-not-duplicate logic** — pin the new status, then unpin the prior one so the channel never accumulates stale pins. 4. **Pin cap awareness** — handle the channel pin limit gracefully, surfacing a warning rather than failing when near the cap. 5. **Permissions and membership** — confirm `pins:read`/`pins:write` and bot membership; handle `not_in_channel` and `already_pinned` errors. 6. **Resolve cleanup** — on incident close, unpin everything the bot pinned (track its own pin timestamps; do not blindly clear human pins). 7. **Observability** — log every pin/unpin with incident ID for the timeline reconstruction. Output as: a Bolt event-handler module with the pin state machine, the API call wrappers, and a table mapping each lifecycle event to its pin/unpin action. Caution: pins.remove will happily remove a human's manually-pinned message if you don't track which timestamps the bot itself pinned — always scope cleanup to bot-owned pins.