AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(platform): surface Slack on the Bots settings + admin analytics pages (#13509)
Bentlyf2b91567a88f
diff --git a/autogpt_platform/backend/backend/api/features/admin/bot_analytics_routes_test.py b/autogpt_platform/backend/backend/api/features/admin/bot_analytics_routes_test.pyindex c1af6000bf..c1ffedc496 100644--- a/autogpt_platform/backend/backend/api/features/admin/bot_analytics_routes_test.py+++ b/autogpt_platform/backend/backend/api/features/admin/bot_analytics_routes_test.py@@ -74,7 +74,9 @@ def test_timeseries_returns_list(mocker):def test_command_usage_and_guilds(mocker):- mock_commands = AsyncMock(return_value=[BotCommandUsage(command="setup", uses=3)])+ mock_commands = AsyncMock(+ return_value=[BotCommandUsage(platform="DISCORD", command="setup", uses=3)]+ )mock_guilds = AsyncMock(return_value=[BotGuildInfo(diff --git a/autogpt_platform/backend/backend/api/features/platform_linking/registry.py b/autogpt_platform/backend/backend/api/features/platform_linking/registry.pyindex 790383e022..351b8a00d3 100644--- a/autogpt_platform/backend/backend/api/features/platform_linking/registry.py+++ b/autogpt_platform/backend/backend/api/features/platform_linking/registry.py@@ -10,6 +10,7 @@ from urllib.parse import urlencodefrom pydantic import BaseModel, ConfigDictfrom backend.copilot.bot.adapters.discord import config as discord_config+from backend.copilot.bot.adapters.slack import config as slack_configclass PlatformMeta(BaseModel):@@ -30,7 +31,7 @@ def enabled_platforms() -> list[PlatformMeta]:Platforms whose adapter isn't configured (missing credentials) areomitted entirely so the Bots page hides them."""- all_platforms = [_discord_meta()]+ all_platforms = [_discord_meta(), _slack_meta()]return [platform for platform in all_platforms if platform.enabled]@@ -45,6 +46,21 @@ def _discord_meta() -> PlatformMeta:)+def _slack_meta() -> PlatformMeta:+ # Slack has no Discord-style one-click invite for a self-hosted app — it's+ # installed per-workspace via the app manifest, then linked with /setup — so+ # there's no add_bot_url. Enabled once both the token and signing secret are+ # set (the same gate the webhook adapter mounts on).+ enabled = bool(slack_config.get_bot_token() and slack_config.get_signing_secret())+ return PlatformMeta(+ platform="SLACK",+ display_name="Slack",+ icon="slack.png",+ enabled=enabled,+ add_bot_url=None,+ )++def _discord_invite_url() -> str | None:client_id = discord_config.get_client_id()if not client_id:diff --git a/autogpt_platform/backend/backend/api/features/platform_linking/registry_test.py b/autogpt_platform/backend/backend/api/features/platform_linking/registry_test.pyindex 8f34818084..f1e52a0ec3 100644--- a/autogpt_platform/backend/backend/api/features/platform_linking/registry_test.py+++ b/autogpt_platform/backend/backend/api/features/platform_linking/registry_test.py@@ -4,35 +4,35 @@ from unittest.mock import patchfrom backend.api.features.platform_linking.registry import enabled_platforms+_REG = "backend.api.features.platform_linking.registry"-def test_discord_excluded_when_bot_token_not_set():- with patch(- "backend.api.features.platform_linking.registry.discord_config.get_bot_token",- return_value="",- ):++def _slack_off():+ # Slack disabled unless a test opts in — keeps the Discord assertions from+ # depending on whatever Slack creds happen to be in the environment.+ return patch(f"{_REG}.slack_config.get_bot_token", return_value="")+++def _discord_off():+ return patch(f"{_REG}.discord_config.get_bot_token", return_value="")+++def test_no_platforms_when_none_configured():+ with _discord_off(), _slack_off():assert enabled_platforms() == []def test_discord_appears_with_invite_url_when_client_id_set():with (- patch(- "backend.api.features.platform_linking.registry.discord_config.get_bot_token",- return_value="token",- ),- patch(- "backend.api.features.platform_linking.registry.discord_config.get_client_id",- return_value="my-client-id",- ),- patch(- "backend.api.features.platform_linking.registry.discord_config.get_invite_permissions",- return_value="123",- ),+ _slack_off(),+ patch(f"{_REG}.discord_config.get_bot_token", return_value="token"),+ patch(f"{_REG}.discord_config.get_client_id", return_value="my-client-id"),+ patch(f"{_REG}.discord_config.get_invite_permissions", return_value="123"),):platforms = enabled_platforms()- assert len(platforms) == 1+ assert [p.platform for p in platforms] == ["DISCORD"]discord = platforms[0]- assert discord.platform == "DISCORD"assert discord.enabled is Trueassert discord.add_bot_url is not Noneassert "client_id=my-client-id" in discord.add_bot_url@@ -41,17 +41,49 @@ def test_discord_appears_with_invite_url_when_client_id_set():def test_discord_appears_without_invite_url_when_client_id_missing():with (- patch(- "backend.api.features.platform_linking.registry.discord_config.get_bot_token",- return_value="token",- ),- patch(- "backend.api.features.platform_linking.registry.discord_config.get_client_id",- return_value="",- ),+ _slack_off(),+ patch(f"{_REG}.discord_config.get_bot_token", return_value="token"),+ patch(f"{_REG}.discord_config.get_client_id", return_value=""),):platforms = enabled_platforms()- assert len(platforms) == 1- assert platforms[0].enabled is True+ assert [p.platform for p in platforms] == ["DISCORD"]assert platforms[0].add_bot_url is None+++def test_slack_appears_when_token_and_signing_secret_set():+ with (+ _discord_off(),+ patch(f"{_REG}.slack_config.get_bot_token", return_value="xoxb-x"),+ patch(f"{_REG}.slack_config.get_signing_secret", return_value="secret"),+ ):+ platforms = enabled_platforms()++ assert [p.platform for p in platforms] == ["SLACK"]+ slack = platforms[0]+ assert slack.enabled is True+ assert slack.display_name == "Slack"+ assert slack.icon == "slack.png"+ # Slack has no one-click invite for a self-hosted app.+ assert slack.add_bot_url is None+++def test_slack_hidden_when_signing_secret_missing():+ with (+ _discord_off(),+ patch(f"{_REG}.slack_config.get_bot_token", return_value="xoxb-x"),+ patch(f"{_REG}.slack_config.get_signing_secret", return_value=""),+ ):+ assert enabled_platforms() == []+++def test_both_platforms_when_both_configured():+ with (+ patch(f"{_REG}.discord_config.get_bot_token", return_value="token"),+ patch(f"{_REG}.discord_config.get_client_id", return_value=""),+ patch(f"{_REG}.slack_config.get_bot_token", return_value="xoxb-x"),+ patch(f"{_REG}.slack_config.get_signing_secret", return_value="secret"),+ ):+ platforms = enabled_platforms()++ assert {p.platform for p in platforms} == {"DISCORD", "SLACK"}diff --git a/autogpt_platform/backend/backend/data/bot_analytics_reads.py b/autogpt_platform/backend/backend/data/bot_analytics_reads.pyindex eb1d8307c4..a50f747236 100644--- a/autogpt_platform/backend/backend/data/bot_analytics_reads.py+++ b/autogpt_platform/backend/backend/data/bot_analytics_reads.py@@ -49,6 +49,7 @@ class BotServerCountPoint(BaseModel):class BotServerActivity(BaseModel):+ platform: strserver_id: strname: str | Nonemessages: int@@ -56,6 +57,7 @@ class BotServerActivity(BaseModel):class BotCommandUsage(BaseModel):+ platform: strcommand: struses: int@@ -214,6 +216,7 @@ async def get_bot_top_servers(f"""SELECTe."serverId" AS server_id,+ e."platform" AS platform,g."name" AS name,count(*) FILTER (WHERE e."eventType" = 'message_received') AS messages,count(*) FILTER (WHERE e."eventType" = 'command_used') AS commands@@ -221,7 +224,7 @@ async def get_bot_top_servers(LEFT JOIN {{schema_prefix}}"BotGuild" gON g."serverId" = e."serverId" AND g."platform" = e."platform"WHERE e."createdAt" >= $1::timestamptz AND e."serverId" IS NOT NULL {platform_filter}- GROUP BY e."serverId", g."name"+ GROUP BY e."serverId", e."platform", g."name"ORDER BY messages DESCLIMIT ${len(params)}::int""",@@ -229,6 +232,7 @@ async def get_bot_top_servers()return [BotServerActivity(+ platform=row["platform"],server_id=row["server_id"],name=row["name"],messages=int(row["messages"]),@@ -245,18 +249,21 @@ async def get_bot_command_usage(platform_filter = _platform_filter(platform, params)rows = await query_raw_with_schema(f"""- SELECT "commandName" AS command, count(*) AS uses+ SELECT "commandName" AS command, "platform" AS platform, count(*) AS usesFROM {{schema_prefix}}"BotEvent"WHERE "eventType" = 'command_used'AND "commandName" IS NOT NULLAND "createdAt" >= $1::timestamptz {platform_filter}- GROUP BY "commandName"+ GROUP BY "commandName", "platform"ORDER BY uses DESC""",*params,)return [- BotCommandUsage(command=row["command"], uses=int(row["uses"])) for row in rows+ BotCommandUsage(+ platform=row["platform"], command=row["command"], uses=int(row["uses"])+ )+ for row in rows]diff --git a/autogpt_platform/frontend/src/app/(platform)/admin/bots/__tests__/main.test.tsx b/autogpt_platform/frontend/src/app/(platform)/admin/bots/__tests__/main.test.tsxindex 4271249329..7e9c4de854 100644--- a/autogpt_platform/frontend/src/app/(platform)/admin/bots/__tests__/main.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/admin/bots/__tests__/main.test.tsx@@ -38,10 +38,23 @@ function mockAllEndpoints() {{ date: new Date("2026-06-01T00:00:00Z"), server_count: 42 },]),getGetV2TopServersByActivityMockHandler200([- { server_id: "1", name: "Cool Guild", messages: 500, commands: 10 },+ {+ platform: "DISCORD",+ server_id: "1",+ name: "Cool Guild",+ messages: 500,+ commands: 10,+ },+ {+ platform: "SLACK",+ server_id: "T1",+ name: "Cool Workspace",+ messages: 300,+ commands: 4,+ },]),getGetV2CommandUsageBreakdownMockHandler200([- { command: "setup", uses: 12 },+ { platform: "DISCORD", command: "setup", uses: 12 },]),getGetV2BotServerRosterMockHandler200([{@@ -74,4 +87,35 @@ describe("BotsContent", () => {expect(await screen.findByText("/setup")).toBeDefined();expect(await screen.findByText("Active")).toBeDefined();});++ it("labels each row with its platform on the All platforms view", async () => {+ mockAllEndpoints();+ render(<BotsContent />);++ // Discord appears in all three tables (top servers, command usage, roster);+ // Slack only in the top-servers table — proving mixed rows are disambiguated.+ expect(+ (await screen.findAllByText("Discord")).length,+ ).toBeGreaterThanOrEqual(3);+ expect(await screen.findByText("Slack")).toBeDefined();+ });++ it("falls back to the raw platform name for an unknown platform", async () => {+ mockAllEndpoints();+ server.use(+ getGetV2TopServersByActivityMockHandler200([+ {+ platform: "TELEGRAM",+ server_id: "tg1",+ name: "Mystery",+ messages: 1,+ commands: 0,+ },+ ]),+ );+ render(<BotsContent />);++ // No label entry exists for TELEGRAM, so the badge shows the raw key.+ expect(await screen.findByText("TELEGRAM")).toBeDefined();+ });});diff --git a/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/BotsContent.tsx b/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/BotsContent.tsxindex 569178eba7..11c37c4a6f 100644--- a/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/BotsContent.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/BotsContent.tsx@@ -6,6 +6,7 @@ import { Select } from "@/components/atoms/Select/Select";import { Skeleton } from "@/components/atoms/Skeleton/Skeleton";import { MessageVolumeChart } from "./MessageVolumeChart";+import { PlatformBadge } from "./PlatformBadge";import { ServerGrowthChart } from "./ServerGrowthChart";import { SimpleTable } from "./SimpleTable";import { SummaryCard } from "./SummaryCard";@@ -23,6 +24,10 @@ export function BotsContent() {const state = useBotsContent();const { summary } = state;+ // On "All platforms" the rows mix Discord and Slack, so lead each table with a+ // platform badge. When a single platform is selected the column is redundant.+ const showPlatform = state.platform === "all";+const tiles = [{ label: "Live servers", value: formatNumber(summary?.live_servers) },{@@ -107,8 +112,16 @@ export function BotsContent() {Top servers by activity</h2><SimpleTable- columns={["Server", "Messages", "Commands"]}+ columns={[+ ...(showPlatform ? ["Platform"] : []),+ "Server",+ "Messages",+ "Commands",+ ]}rows={state.topServers.map((server) => [+ ...(showPlatform+ ? [<PlatformBadge key="p" platform={server.platform} />]+ : []),server.name || server.server_id,formatNumber(server.messages),formatNumber(server.commands),@@ -120,8 +133,15 @@ export function BotsContent() {<Card><h2 className="mb-4 text-xl font-semibold">Command usage</h2><SimpleTable- columns={["Command", "Uses"]}+ columns={[+ ...(showPlatform ? ["Platform"] : []),+ "Command",+ "Uses",+ ]}rows={state.commands.map((command) => [+ ...(showPlatform+ ? [<PlatformBadge key="p" platform={command.platform} />]+ : []),`/${command.command}`,formatNumber(command.uses),])}@@ -131,8 +151,16 @@ export function BotsContent() {<Card><h2 className="mb-4 text-xl font-semibold">Server roster</h2><SimpleTable- columns={["Server", "Status", "Joined"]}+ columns={[+ ...(showPlatform ? ["Platform"] : []),+ "Server",+ "Status",+ "Joined",+ ]}rows={state.roster.map((guild) => [+ ...(showPlatform+ ? [<PlatformBadge key="p" platform={guild.platform} />]+ : []),guild.name || guild.server_id,guild.active ? "Active" : "Left",formatDate(guild.joined_at),diff --git a/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/PlatformBadge.tsx b/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/PlatformBadge.tsxnew file mode 100644index 0000000000..d4e18cdb30--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/PlatformBadge.tsx@@ -0,0 +1,32 @@+import Image from "next/image";++import { PLATFORM_OPTIONS } from "./helpers";++const PLATFORM_LABELS: Record<string, string> = Object.fromEntries(+ PLATFORM_OPTIONS.filter((option) => option.value !== "all").map((option) => [+ option.value.toUpperCase(),+ option.label,+ ]),+);++interface Props {+ platform: string;+}++export function PlatformBadge({ platform }: Props) {+ const key = platform.toUpperCase();+ const label = PLATFORM_LABELS[key] ?? platform;++ return (+ <span className="inline-flex items-center gap-2 whitespace-nowrap">+ <Image+ src={`/integrations/${key.toLowerCase()}.png`}+ alt={`${label} icon`}+ width={16}+ height={16}+ className="rounded-sm"+ />+ {label}+ </span>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/helpers.tsindex 993015cd0a..7a62b70dbc 100644--- a/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/admin/bots/components/helpers.ts@@ -9,6 +9,7 @@ export const DAYS_OPTIONS = [export const PLATFORM_OPTIONS = [{ value: "all", label: "All platforms" },{ value: "DISCORD", label: "Discord" },+ { value: "SLACK", label: "Slack" },];export function formatNumber(value: number | null | undefined): string {diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/bots/__tests__/main.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/bots/__tests__/main.test.tsxindex d51d3f99b7..4ed9b0a600 100644--- a/autogpt_platform/frontend/src/app/(platform)/settings/bots/__tests__/main.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/settings/bots/__tests__/main.test.tsx@@ -31,6 +31,20 @@ function discordPlatform(};}+function slackPlatform(+ overrides: Partial<BotPlatformInfo> = {},+): BotPlatformInfo {+ return {+ platform: "SLACK",+ display_name: "Slack",+ icon: "slack.png",+ add_bot_url: null, // Slack has no one-click invite for a self-hosted app+ dm_link: undefined,+ server_links: [],+ ...overrides,+ };+}+describe("SettingsBotsPage", () => {test("renders the header and the Discord card with an Add bot button", async () => {server.use(getListBotPlatformsMockHandler([discordPlatform()]));@@ -48,6 +62,19 @@ describe("SettingsBotsPage", () => {).toBeDefined();});+ test("renders the Slack card without an Add bot button (no invite URL)", async () => {+ server.use(getListBotPlatformsMockHandler([slackPlatform()]));++ render(<SettingsBotsPage />);++ expect(+ await screen.findByRole("heading", { name: /slack/i }),+ ).toBeDefined();+ expect(+ screen.queryByRole("link", { name: /add bot to slack/i }),+ ).toBeNull();+ });+test("shows the 'no bots enabled' empty state when no platforms are configured", async () => {server.use(getListBotPlatformsMockHandler([]));diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.jsonindex 5a42446f12..cb523b96e7 100644--- a/autogpt_platform/frontend/src/app/api/openapi.json+++ b/autogpt_platform/frontend/src/app/api/openapi.json@@ -14375,11 +14375,12 @@},"BotCommandUsage": {"properties": {+ "platform": { "type": "string", "title": "Platform" },"command": { "type": "string", "title": "Command" },"uses": { "type": "integer", "title": "Uses" }},"type": "object",- "required": ["command", "uses"],+ "required": ["platform", "command", "uses"],"title": "BotCommandUsage"},"BotGuildInfo": {@@ -14443,6 +14444,7 @@},"BotServerActivity": {"properties": {+ "platform": { "type": "string", "title": "Platform" },"server_id": { "type": "string", "title": "Server Id" },"name": {"anyOf": [{ "type": "string" }, { "type": "null" }],@@ -14452,7 +14454,7 @@"commands": { "type": "integer", "title": "Commands" }},"type": "object",- "required": ["server_id", "name", "messages", "commands"],+ "required": ["platform", "server_id", "name", "messages", "commands"],"title": "BotServerActivity"},"BotServerCountPoint": {