Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(bots): create team-owned bots from settings (#5446)
teoc144439282bf
diff --git a/apps/web/src/features/channel/Bots/BotCreatePage.tsx b/apps/web/src/features/channel/Bots/BotCreatePage.tsxindex cca93ac6b6..cc5f1bc911 100644--- a/apps/web/src/features/channel/Bots/BotCreatePage.tsx+++ b/apps/web/src/features/channel/Bots/BotCreatePage.tsx@@ -11,8 +11,9 @@ import {useAddBotToChannelsMutation,useCreateChannelScopedBotMutation,} from '@queries/channel/channel-bots';+import { useCurrentTeamQuery, useIsTeamAdmin } from '@queries/team/teams';import type { Bot } from '@service-storage/generated/schemas/bot';-import { Button } from '@ui';+import { Button, ToggleSwitch } from '@ui';import { createMemo, createSignal, Show } from 'solid-js';import { createStore } from 'solid-js/store';import { BotCreationResult } from './BotCreationResult';@@ -32,11 +33,14 @@ type Stage = 'form' | 'creating' | 'ready';export function BotCreate(props: { channelId?: string; onBack: () => void }) {const channelsContext = useChannelsContext();+ const currentTeamQuery = useCurrentTeamQuery();+ const isTeamAdmin = useIsTeamAdmin();const createBotMutation = useCreateBotMutation();const createTokenMutation = useCreateBotTokenMutation();const createScopedBotMutation = useCreateChannelScopedBotMutation();const addBotToChannelsMutation = useAddBotToChannelsMutation();const [stage, setStage] = createSignal<Stage>('form');+ const [teamOwned, setTeamOwned] = createSignal(false);const [handleEdited, setHandleEdited] = createSignal(false);const [errors, setErrors] = createSignal<BotFormErrors>({});const [createdBot, setCreatedBot] = createSignal<Bot>();@@ -54,6 +58,10 @@ export function BotCreate(props: { channelId?: string; onBack: () => void }) {const channelOptions = createMemo(() =>botAssignableChannelOptions(channelsContext.channels()));+ const currentTeam = createMemo(() => currentTeamQuery.data?.team);+ const canCreateTeamBot = createMemo(+ () => currentTeam() !== undefined && isTeamAdmin()+ );const resultChannels = createMemo(() => {const selected = new Set(createdChannelIds());return channelOptions().filter((channel) => selected.has(channel.id));@@ -72,6 +80,12 @@ export function BotCreate(props: { channelId?: string; onBack: () => void }) {};const submit = () => {+ const teamId = teamOwned() ? currentTeam()?.id : undefined;+ if (teamOwned() && (!teamId || !canCreateTeamBot())) {+ toast.failure('Only team admins and owners can create team bots');+ return;+ }+const parsed = validateBotForm({...form,handle: form.handle || slugBotHandle(form.name),@@ -92,6 +106,7 @@ export function BotCreate(props: { channelId?: string; onBack: () => void }) {createScopedBotMutation.mutate({channelId: firstChannelId,+ team_id: teamId,name: values.name,handle: values.handle,description: values.description || undefined,@@ -125,6 +140,7 @@ export function BotCreate(props: { channelId?: string; onBack: () => void }) {createBotMutation.mutate({+ teamId,name: values.name,handle: values.handle,description: values.description || undefined,@@ -221,6 +237,35 @@ export function BotCreate(props: { channelId?: string; onBack: () => void }) {/></BotFormSection>+ <BotFormSection+ title="Ownership"+ description="Bots are personal by default."+ >+ <div class="flex items-center justify-between gap-4">+ <div class="min-w-0">+ <div class="text-sm font-medium text-ink">Team bot</div>+ <p class="mt-0.5 text-xs text-ink-muted">+ Share this bot with your team and let it use team scope.+ </p>+ </div>+ <ToggleSwitch+ size="md"+ checked={teamOwned()}+ disabled={currentTeamQuery.isLoading || !canCreateTeamBot()}+ onChange={setTeamOwned}+ label={<span>Create as a team bot</span>}+ labelClass="sr-only"+ />+ </div>+ <Show when={!currentTeamQuery.isLoading && !canCreateTeamBot()}>+ <p class="mt-3 border-t border-edge-muted pt-3 text-xs text-ink-extra-muted">+ {currentTeam()+ ? 'Only team admins and owners can create team bots.'+ : 'Join or create a team to create a team bot.'}+ </p>+ </Show>+ </BotFormSection>+<BotFormSectiontitle="Channels"description="Add the bot now to get ready-to-use webhook URLs."diff --git a/apps/web/src/features/settings/BotSettingsList.tsx b/apps/web/src/features/settings/BotSettingsList.tsxindex 82c5886d9d..5576745be0 100644--- a/apps/web/src/features/settings/BotSettingsList.tsx+++ b/apps/web/src/features/settings/BotSettingsList.tsx@@ -12,6 +12,8 @@ import { SettingsCard, SettingsPage, SettingsSection } from './primitives';function BotSettingsRow(props: { bot: Bot; onOpen: (botId: string) => void }) {const channelsQuery = useBotChannelsQuery(() => props.bot.id);const channels = () => channelsQuery.data ?? [];+ const ownerLabel = () =>+ props.bot.owner?.type === 'team' ? 'Team' : 'Personal';const channelSummary = () => {if (channelsQuery.isLoading) return 'Loading channels…';@@ -30,13 +32,16 @@ function BotSettingsRow(props: { bot: Bot; onOpen: (botId: string) => void }) {><BotAvatar bot={props.bot} size="lg" /><div class="min-w-0 flex-1">- <div class="flex min-w-0 items-baseline gap-2">+ <div class="flex min-w-0 items-center gap-2"><span class="truncate text-sm font-medium text-ink">{props.bot.name}</span><span class="truncate text-xs text-ink-extra-muted">@{props.bot.handle}</span>+ <span class="shrink-0 rounded-full border border-edge-muted px-2 py-0.5 font-mono text-xxs font-medium uppercase text-ink-extra-muted">+ {ownerLabel()}+ </span></div><div class="mt-0.5 truncate text-xs text-ink-muted">{props.bot.description || channelSummary()}