Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/slack/slack-app-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"settings": {
"event_subscriptions": {
"bot_events": [
"app_home_opened",
"app_mention",
"assistant_thread_context_changed",
"assistant_thread_started",
Expand Down
22 changes: 22 additions & 0 deletions apps/slack/src/slack/app-home.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from "bun:test";
import { buildAppHomeView } from "@/slack/app-home";
import { SLACK_SUGGESTED_PROMPTS } from "@/slack/messages";

describe("buildAppHomeView", () => {
it("builds a home view with a header and blocks", () => {
const view = buildAppHomeView();
expect(view.type).toBe("home");
const blocks = view.blocks as Array<Record<string, unknown>>;
expect(blocks[0]).toMatchObject({ type: "header" });
expect((blocks[0].text as { text: string }).text).toBe("Databuddy");
expect(blocks.length).toBeGreaterThan(3);
});

it("lists the suggested prompts", () => {
const view = buildAppHomeView();
const text = JSON.stringify(view);
for (const prompt of SLACK_SUGGESTED_PROMPTS) {
expect(text).toContain(prompt.message);
}
});
});
43 changes: 43 additions & 0 deletions apps/slack/src/slack/app-home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { SLACK_SUGGESTED_PROMPTS } from "@/slack/messages";

export function buildAppHomeView(): Record<string, unknown> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Use an explicit Slack view type

Returning Record<string, unknown> forces the listener to double-cast the result before publishing and prevents the compiler from validating future Block Kit changes. Type the builder with Slack's Home view contract and use the same concrete block types in the test.

Context Used: Basic guidelines for the project so vibe coders do... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

const prompts = SLACK_SUGGESTED_PROMPTS.map(
(prompt) => `• ${prompt.message}`
).join("\n");

return {
type: "home",
blocks: [
{
type: "header",
text: { type: "plain_text", text: "Databuddy" },
},
{
type: "section",
text: {
type: "mrkdwn",
text: "Ask about your analytics right here in Slack — traffic, pages, conversions, campaigns, errors, and product usage. Mention *@Databuddy*, send a direct message, or use the assistant.",
},
},
{ type: "divider" },
{
type: "section",
text: { type: "mrkdwn", text: "*Try asking*" },
},
{
type: "section",
text: { type: "mrkdwn", text: prompts },
},
{ type: "divider" },
{
type: "context",
elements: [
{
type: "mrkdwn",
text: "Commands: `/databuddy-status` `/databuddy-help` `/databuddy-bind`",
},
],
},
],
};
}
17 changes: 17 additions & 0 deletions apps/slack/src/slack/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { createRPCContext } from "@databuddy/rpc";
import { appendInvestigationReply } from "@databuddy/rpc/insights";
import type { DatabuddyAgentClient, SlackAgentRun } from "@/agent/agent-client";
import { buildAppHomeView } from "@/slack/app-home";
import { createSlackEventLog } from "@/lib/evlog-slack";
import { abortSlackActiveRun } from "@/slack/active-runs";
import { getSlackChannelMentionPolicy } from "@/slack/channel-policy";
Expand Down Expand Up @@ -156,6 +157,22 @@ export function registerSlackListeners(

app.assistant(createDatabuddyAssistant({ agent, dedupe, threadQueue }));

app.event("app_home_opened", async ({ client, event, logger }) => {
if (event.tab !== "home") {
return;
}
try {
await client.views.publish({
user_id: event.user,
view: buildAppHomeView() as unknown as Parameters<
typeof client.views.publish
>[0]["view"],
});
} catch (error) {
logger.warn("Failed to publish Slack App Home", error);
}
});

app.event(
"app_mention",
async ({ body, client, context, event, logger, say }) => {
Expand Down
1 change: 1 addition & 0 deletions apps/slack/src/slack/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface SlackAgentClient {
"history" | "info" | "replies"
>;
reactions: Pick<WebClient["reactions"], "add">;
views: Pick<WebClient["views"], "publish">;
}

export type SlackSay = (
Expand Down