Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
slack app: improvment (#2352)
Thibault Le Ouay32dc4be8ed1e
diff --git a/apps/server/slack-manifest.json b/apps/server/slack-manifest.jsonindex f882dc5fb..b6574141d 100644--- a/apps/server/slack-manifest.json+++ b/apps/server/slack-manifest.json@@ -3,7 +3,7 @@"name": "openstatus","description": "Manage incidents and status pages directly from Slack.","background_color": "#000000",- "long_description": "openstatus brings incident management into your team's Slack workspace. Mention the bot or send it a direct message to create, update, and resolve status reports — no context switching required.\n\n How it works:\n :one: Describe the issue by mentioning @openstatus in any channel or thread\n :two: The assistant reads the conversation, queries your status pages, and drafts a status update\n :three: Review the proposed action and click Approve, Approve & Notify, or Cancel\n\n What you can do:\n :white_check_mark: Create status reports from natural conversation\n :white_check_mark: Post progress updates as incidents evolve\n :white_check_mark: Resolve incidents when the issue is fixed\n :white_check_mark: Notify your status page subscribers with one click\n :white_check_mark: Edit report titles and affected components\n\n The assistant understands context — tag it in an ongoing thread and it will synthesize the discussion into a clear, public-facing status update. It infers incident status automatically: \"we found the root cause\" becomes Identified, \"it's fixed\" becomes Resolved.\n\n AI disclaimer: openstatus uses large language models (LLMs) to summarize conversations, draft status updates, and infer incident status. AI-generated content may sometimes be inaccurate, incomplete, or misleading. Always review every draft before approving it — nothing is posted to your status page until you explicitly confirm. Only the person who triggered the action can approve it, and you can edit or cancel any draft."+ "long_description": "openstatus brings incident management into your team's Slack workspace. Mention the bot in any channel to create, update, and resolve status reports — no context switching required.\n\n How it works:\n :one: Describe the issue by mentioning @openstatus in any channel or thread\n :two: The assistant reads the conversation, queries your status pages, and drafts a status update\n :three: Review the proposed action and click Approve, Approve & Notify, or Cancel\n\n What you can do:\n :white_check_mark: Create status reports from natural conversation\n :white_check_mark: Post progress updates as incidents evolve\n :white_check_mark: Resolve incidents when the issue is fixed\n :white_check_mark: Notify your status page subscribers with one click\n :white_check_mark: Edit report titles and affected components\n\n The assistant understands context — tag it in an ongoing thread and it will synthesize the discussion into a clear, public-facing status update. It infers incident status automatically: \"we found the root cause\" becomes Identified, \"it's fixed\" becomes Resolved.\n\n AI disclaimer: openstatus uses large language models (LLMs) to summarize conversations, draft status updates, and infer incident status. AI-generated content may sometimes be inaccurate, incomplete, or misleading. Always review every draft before approving it — nothing is posted to your status page until you explicitly confirm. Only the person who triggered the action can approve it, and you can edit or cancel any draft."},"features": {"app_home": {@@ -19,8 +19,8 @@{"command": "/openstatus","url": "https://api.openstatus.dev/slack/commands",- "description": "Subscribe this channel to a status page",- "usage_hint": "subscribe | unsubscribe | subscriptions <status-page-url>",+ "description": "Manage this channel's status page subscriptions",+ "usage_hint": "subscribe | unsubscribe | subscriptions | help","should_escape": false}]@@ -38,11 +38,7 @@"commands","groups:history","groups:read",- "groups:write",- "im:history",- "im:read",- "im:write",- "mpim:history"+ "groups:write"]},"pkce_enabled": false@@ -50,7 +46,12 @@"settings": {"event_subscriptions": {"request_url": "https://api.openstatus.dev/slack/events",- "bot_events": ["app_home_opened", "message.channels", "message.groups"]+ "bot_events": [+ "app_home_opened",+ "app_mention",+ "message.channels",+ "message.groups"+ ]},"interactivity": {"is_enabled": true,diff --git a/apps/server/src/libs/test/doubles/slack-web-api.mock.ts b/apps/server/src/libs/test/doubles/slack-web-api.mock.tsindex fd8d3c935..c4479e9ef 100644--- a/apps/server/src/libs/test/doubles/slack-web-api.mock.ts+++ b/apps/server/src/libs/test/doubles/slack-web-api.mock.ts@@ -23,4 +23,10 @@ export class WebClient {conversations = {replies: () => s.repliesImpl(),};+ views = {+ publish: (args: Record<string, unknown>) => {+ s.calls.push({ method: "views.publish", args });+ return Promise.resolve({ ok: true });+ },+ };}diff --git a/apps/server/src/routes/slack/handler.test.ts b/apps/server/src/routes/slack/handler.test.tsindex 0bfcfbadb..0c49074fd 100644--- a/apps/server/src/routes/slack/handler.test.ts+++ b/apps/server/src/routes/slack/handler.test.ts@@ -110,6 +110,46 @@ describe("handleSlackEvent", () => {expect(json.ok).toBe(true);});+ test("publishes the home view on app_home_opened", async () => {+ const res = await signAndPost(app, {+ type: "event_callback",+ team_id: "T_KNOWN",+ event_id: `evt_home_${Date.now()}`,+ event: {+ type: "app_home_opened",+ tab: "home",+ user: "U1",+ },+ });++ expect(res.status).toBe(200);+ await new Promise((r) => setTimeout(r, 50));++ const publish = slackTestState.calls.find(+ (m) => m.method === "views.publish",+ );+ expect(publish).toBeDefined();+ expect((publish?.args.view as { type: string }).type).toBe("home");+ expect(publish?.args.user_id).toBe("U1");+ });++ test("ignores app_home_opened for the messages tab", async () => {+ const res = await signAndPost(app, {+ type: "event_callback",+ team_id: "T_KNOWN",+ event_id: `evt_home_msgs_${Date.now()}`,+ event: {+ type: "app_home_opened",+ tab: "messages",+ user: "U1",+ },+ });++ expect(res.status).toBe(200);+ await new Promise((r) => setTimeout(r, 50));+ expect(slackTestState.calls.length).toBe(0);+ });+test("handles app_uninstalled event", async () => {const res = await signAndPost(app, {type: "event_callback",@@ -219,7 +259,7 @@ describe("handleSlackEvent", () => {expect(slackTestState.calls.length).toBe(0);});- test("processes DM messages without bot mention", async () => {+ test("ignores DM messages", async () => {const res = await signAndPost(app, {type: "event_callback",team_id: "T_KNOWN",@@ -236,8 +276,7 @@ describe("handleSlackEvent", () => {expect(res.status).toBe(200);await new Promise((r) => setTimeout(r, 50));- // DM should trigger a response (postMessage for "Thinking...")- expect(slackTestState.calls.length).toBeGreaterThan(0);+ expect(slackTestState.calls.length).toBe(0);});test("ignores events without channel", async () => {diff --git a/apps/server/src/routes/slack/handler.ts b/apps/server/src/routes/slack/handler.tsindex 1c9723218..fbdaf05d3 100644--- a/apps/server/src/routes/slack/handler.ts+++ b/apps/server/src/routes/slack/handler.ts@@ -13,6 +13,7 @@ import {} from "./blocks";import { findByThread, replace, store } from "./confirmation-store";import type { PendingPayload } from "./confirmation-store";+import { publishHomeView } from "./home";import { getComponentNames, getPageDashboardLink } from "./page-urls";import { getRegistryTool, isSlackToolDraft } from "./registry-runner";import { resolveWorkspace } from "./workspace-resolver";@@ -51,6 +52,7 @@ const slackEventSchema = z.object({ts: z.string().optional(),thread_ts: z.string().optional(),bot_id: z.string().optional(),+ tab: z.string().optional(),}).optional(),event_id: z.string().optional(),@@ -138,6 +140,21 @@ async function processEvent(body: SlackEvent) {return;}+ if (event.type === "app_home_opened") {+ if (event.tab && event.tab !== "home") return;+ const teamId = body.team_id;+ const userId = event.user;+ if (!teamId || !userId) return;+ const resolved = await resolveWorkspace(teamId);+ if (!resolved) return;+ try {+ await publishHomeView(new WebClient(resolved.botToken), userId);+ } catch (err) {+ logger.error("slack failed to publish home view", { error: err, teamId });+ }+ return;+ }+if (event.type !== "app_mention" && event.type !== "message") return;if (event.type === "message" && event.bot_id) return;@@ -163,8 +180,8 @@ async function processEvent(body: SlackEvent) {const botUserId = resolved.botUserId;const threadTs = event.thread_ts ?? event.ts;- if (event.type === "message" && event.channel_type !== "im") {- if (!event.text?.includes(`<@${botUserId}>`)) return;+ if (event.type === "message" && !event.text?.includes(`<@${botUserId}>`)) {+ return;}logger.info("slack event received", {diff --git a/apps/server/src/routes/slack/home.ts b/apps/server/src/routes/slack/home.tsnew file mode 100644index 000000000..a7030af6e--- /dev/null+++ b/apps/server/src/routes/slack/home.ts@@ -0,0 +1,54 @@+import type { WebClient } from "@slack/web-api";+import type { KnownBlock } from "@slack/web-api";++const DOCS_URL = "https://www.openstatus.dev/docs";++export function buildHomeBlocks(): KnownBlock[] {+ return [+ {+ type: "header",+ text: { type: "plain_text", text: "openstatus", emoji: true },+ },+ {+ type: "section",+ text: {+ type: "mrkdwn",+ text: "Manage incidents and status pages without leaving Slack. Mention *@openstatus* in any channel or thread and it drafts a status update from the conversation — nothing is published until you approve it.",+ },+ },+ { type: "divider" },+ {+ type: "section",+ text: {+ type: "mrkdwn",+ text: '*Create & update incidents*\nMention `@openstatus` describing the issue. It reads the thread, drafts a report, and you click *Approve*, *Approve & Notify*, or *Cancel*. Say _"we found the cause"_ or _"it\'s fixed"_ and it moves the incident to Identified or Resolved.',+ },+ },+ {+ type: "section",+ text: {+ type: "mrkdwn",+ text: "*Slash commands*\n• `/openstatus subscribe <status-page-url>` — subscribe this channel to a status page\n• `/openstatus unsubscribe <status-page-url>` — unsubscribe this channel\n• `/openstatus subscriptions` — list this channel's subscriptions\n• `/openstatus help` — show these commands",+ },+ },+ {+ type: "context",+ elements: [+ {+ type: "mrkdwn",+ text: `<${DOCS_URL}|Documentation> · Updates from subscribed status pages appear as threaded messages in the channel.`,+ },+ ],+ },+ ];+}++export async function publishHomeView(+ slack: WebClient,+ userId: string,+): Promise<void> {+ await slack.views.publish({+ user_id: userId,+ view: { type: "home", blocks: buildHomeBlocks() },+ });+}diff --git a/apps/server/src/routes/slack/oauth.test.ts b/apps/server/src/routes/slack/oauth.test.tsindex 19624dd0d..cb99f2650 100644--- a/apps/server/src/routes/slack/oauth.test.ts+++ b/apps/server/src/routes/slack/oauth.test.ts@@ -98,10 +98,6 @@ describe("handleSlackInstall", () => {"groups:history","groups:read","groups:write",- "im:history",- "im:read",- "im:write",- "mpim:history",];for (const s of expectedScopes) {diff --git a/apps/server/src/routes/slack/oauth.ts b/apps/server/src/routes/slack/oauth.tsindex 636fedd9d..9faaa2aeb 100644--- a/apps/server/src/routes/slack/oauth.ts+++ b/apps/server/src/routes/slack/oauth.ts@@ -25,10 +25,6 @@ const BOT_SCOPES = ["groups:history","groups:read","groups:write",- "im:history",- "im:read",- "im:write",- "mpim:history",].join(",");interface OAuthState {diff --git a/packages/subscriptions/src/channels/slack-blocks.ts b/packages/subscriptions/src/channels/slack-blocks.tsindex 32004f2b5..be418d372 100644--- a/packages/subscriptions/src/channels/slack-blocks.ts+++ b/packages/subscriptions/src/channels/slack-blocks.ts@@ -107,14 +107,24 @@ export function buildRootMessage(elements: [{type: "mrkdwn",- text: `Updated ${pageUpdate.date} · <${eventUrl(pageUpdate, subscription)}|View details> · Manage with \`/openstatus remove\``,+ text: `Updated ${pageUpdate.date} · <${eventUrl(pageUpdate, subscription)}|View details> · Manage with \`/openstatus unsubscribe\``,},],});+ const title = `${emoji} ${pageUpdate.title} — ${label}`;return {- text: `${emoji} ${pageUpdate.title} — ${label}`,- attachments: [{ color: COLORS[statusColor(pageUpdate.status)], blocks }],+ // `text` is the notification/accessibility fallback only — it is NOT sent+ // as the message body, otherwise the title renders twice (once here, once+ // in the card's header block). See the root post/update calls in slack.ts.+ text: title,+ attachments: [+ {+ color: COLORS[statusColor(pageUpdate.status)],+ fallback: title,+ blocks,+ },+ ],};}diff --git a/packages/subscriptions/src/channels/slack-store.ts b/packages/subscriptions/src/channels/slack-store.tsindex 77d0e38c4..a635cf809 100644--- a/packages/subscriptions/src/channels/slack-store.ts+++ b/packages/subscriptions/src/channels/slack-store.ts@@ -1,8 +1,14 @@import { Redis } from "@upstash/redis";+import type { SlackReplyMessage } from "./slack-blocks";+export interface SlackThreadAnchor {ts: string;channelId: string;+ // The first update lives only in the root message until a second update+ // arrives and re-renders the root. We stash its reply payload here so the+ // next update can backfill it into the thread before it's overwritten.+ pendingRootReply?: SlackReplyMessage;}export interface SlackAnchorStore {diff --git a/packages/subscriptions/src/channels/slack.test.ts b/packages/subscriptions/src/channels/slack.test.tsindex d4494cf31..8dabbe03b 100644--- a/packages/subscriptions/src/channels/slack.test.ts+++ b/packages/subscriptions/src/channels/slack.test.ts@@ -14,6 +14,7 @@ interface RecordedCall {channel: string;thread_ts?: string;ts?: string;+ text?: string;}function makeClient(opts: { failPostWith?: string } = {}) {@@ -25,6 +26,7 @@ function makeClient(opts: { failPostWith?: string } = {}) {method: "post",channel: args.channel,thread_ts: args.thread_ts,+ text: (args as { text?: string }).text,});if (opts.failPostWith) {const error = new Error("slack error") as Error & {@@ -96,7 +98,7 @@ describe("createSlackChannel", () => {expect(await store.getAnchor(10, 1)).not.toBeNull();});- test("subsequent update replies in thread and re-renders root", async () => {+ test("subsequent update backfills the first update then replies in thread and re-renders root", async () => {const { client, calls } = makeClient();const store = createMemoryAnchorStore();const channel = createSlackChannel({@@ -106,18 +108,59 @@ describe("createSlackChannel", () => {softUnsubscribe: noopUnsub,});- await channel.sendNotifications([makeSub()], makeUpdate({ updateId: 100 }));await channel.sendNotifications([makeSub()],- makeUpdate({ updateId: 101, status: "monitoring" }),+ makeUpdate({ updateId: 100, message: "first update" }),+ );+ await channel.sendNotifications(+ [makeSub()],+ makeUpdate({+ updateId: 101,+ status: "monitoring",+ message: "second update",+ }),);const posts = calls.filter((c) => c.method === "post");- expect(posts.length).toBe(2);+ // root post + backfill of the first update + reply for the second update+ expect(posts.length).toBe(3);+ // The first update is preserved in the thread, not lost to the root re-render.expect(posts[1]?.thread_ts).toBe("1700000000.0001");+ expect(posts[1]?.text).toContain("first update");+ expect(posts[2]?.thread_ts).toBe("1700000000.0001");+ expect(posts[2]?.text).toContain("second update");expect(calls.some((c) => c.method === "update")).toBe(true);});+ test("third update does not backfill the first update again", async () => {+ const { client, calls } = makeClient();+ const store = createMemoryAnchorStore();+ const channel = createSlackChannel({+ store,+ createClient: () => client,+ getBotToken: token,+ softUnsubscribe: noopUnsub,+ });++ await channel.sendNotifications(+ [makeSub()],+ makeUpdate({ updateId: 100, message: "first update" }),+ );+ await channel.sendNotifications(+ [makeSub()],+ makeUpdate({ updateId: 101, message: "second update" }),+ );+ await channel.sendNotifications(+ [makeSub()],+ makeUpdate({ updateId: 102, message: "third update" }),+ );++ const backfills = calls.filter(+ (c) => c.method === "post" && c.text?.includes("first update"),+ );+ expect(backfills.length).toBe(1);+ });+test("same update delivered twice posts once (idempotent)", async () => {const { client, calls } = makeClient();const store = createMemoryAnchorStore();diff --git a/packages/subscriptions/src/channels/slack.ts b/packages/subscriptions/src/channels/slack.tsindex f70589e15..0c81d01cc 100644--- a/packages/subscriptions/src/channels/slack.ts+++ b/packages/subscriptions/src/channels/slack.ts@@ -134,7 +134,6 @@ export function createSlackChannel(deps: SlackChannelDeps) {const res = await runSlack(sub.id, () =>client.postMessage({channel: channelId,- text: root.text,attachments: root.attachments,}),);@@ -165,7 +164,6 @@ export function createSlackChannel(deps: SlackChannelDeps) {const res = await runSlack(sub.id, () =>client.postMessage({channel: channelId,- text: root.text,attachments: root.attachments,}),);@@ -174,11 +172,43 @@ export function createSlackChannel(deps: SlackChannelDeps) {return res === TEAM_TOKEN_INVALID ? TEAM_TOKEN_INVALID : undefined;}if (res.ts) {- await deps.store.setAnchor(reportId, sub.id, { ts: res.ts, channelId });+ // Stash this first update so the next one can backfill it into the+ // thread before the root is re-rendered and its content lost.+ await deps.store.setAnchor(reportId, sub.id, {+ ts: res.ts,+ channelId,+ pendingRootReply: buildReplyMessage(pageUpdate),+ });}return;}+ // The first update only ever lived in the root. Before we overwrite the+ // root below, post it into the thread so its history is preserved.+ if (anchor.pendingRootReply) {+ const backfill = anchor.pendingRootReply;+ const backfillRes = await runSlack(sub.id, () =>+ client.postMessage({+ channel: anchor.channelId,+ thread_ts: anchor.ts,+ text: backfill.text,+ blocks: backfill.blocks,+ }),+ );+ if (!backfillRes || backfillRes === TEAM_TOKEN_INVALID) {+ await deps.store.releaseDelivery(reportId, sub.id, updateId);+ return backfillRes === TEAM_TOKEN_INVALID+ ? TEAM_TOKEN_INVALID+ : undefined;+ }+ // Clear before posting the current reply: if that reply fails and the+ // delivery is retried, the first update must not be backfilled twice.+ await deps.store.setAnchor(reportId, sub.id, {+ ts: anchor.ts,+ channelId: anchor.channelId,+ });+ }+const reply = buildReplyMessage(pageUpdate);const replyRes = await runSlack(sub.id, () =>client.postMessage({@@ -198,7 +228,6 @@ export function createSlackChannel(deps: SlackChannelDeps) {client.update({channel: anchor.channelId,ts: anchor.ts,- text: root.text,attachments: root.attachments,}),);