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
fix(notifications): name bot senders and channels in browser notifications (#9151)
Eric Hayesa9f8d1637cc2
diff --git a/apps/web/src/features/notifications/notification-metadata.ts b/apps/web/src/features/notifications/notification-metadata.tsindex ea3e6d25c0..492d5d8f9e 100644--- a/apps/web/src/features/notifications/notification-metadata.ts+++ b/apps/web/src/features/notifications/notification-metadata.ts@@ -125,11 +125,18 @@ export function getNotificationTargetName({ tag: P.union(...GITHUB_EVENT_TYPES) },(m) => `${m.content.owner}/${m.content.repo}#${m.content.number}`)- .with({ tag: 'channel_mention' }, () => undefined)- .with({ tag: 'channel_message_send' }, () => undefined)- .with({ tag: 'channel_message_reaction' }, () => undefined)+ .with(+ {+ tag: P.union(+ 'channel_mention',+ 'channel_message_send',+ 'channel_message_reaction',+ 'channel_message_reply'+ ),+ },+ (m) => m.content.channelName || undefined+ ).with({ tag: 'ai_response' }, () => undefined)- .with({ tag: 'channel_message_reply' }, () => undefined).with({ tag: 'call_started' }, (m) => m.content.channel_name ?? undefined).with({ tag: 'new_email' }, () => undefined).with({ tag: 'external_chat_message' }, (m) => m.content.chatName)diff --git a/apps/web/src/features/notifications/notification-platform.ts b/apps/web/src/features/notifications/notification-platform.tsindex edaa3d6aac..4c2b201b51 100644--- a/apps/web/src/features/notifications/notification-platform.ts+++ b/apps/web/src/features/notifications/notification-platform.ts@@ -3,7 +3,6 @@ import type { SplitManager } from '@components/app/split-layout/layoutManager';import { markdownToPlainText } from '@macro-inc/lexical-core';import { committedThemeAccent } from '../theme/signals/themeSignals';import type { PlatformNotificationState } from './components/PlatformNotificationProvider';-import { isEntityDiscussionEvent } from './entity-discussion';import { GITHUB_EVENT_TYPES } from './github-event-types';import {getNotificationAction,@@ -48,12 +47,11 @@ export interface PlatformNotificationData {}const USER_NAME_FALLBACK = 'Someone';-const DOCUMENT_NAME_FALLBACK = 'Something';/**- * Who the notification reads as being from. Agent notifications have no user- * sender - a bot is not a user - so the bot (or, for a mention, the author)- * named in the metadata stands in.+ * Who the notification reads as being from. Agent notifications and bot+ * messages have no user sender - a bot is not a user - so the bot (or, for a+ * mention, the author) named in the metadata stands in.*/async function resolveActorName(notification: UnifiedNotification,@@ -66,7 +64,7 @@ async function resolveActorName() {return meta.content.botName;}- if (isEntityDiscussionEvent(meta) && meta.content.senderDisplayName) {+ if ('senderDisplayName' in meta.content && meta.content.senderDisplayName) {return meta.content.senderDisplayName;}if (meta.tag === 'agent_session_mentioned') {@@ -118,14 +116,15 @@ export async function toPlatformNotificationData(]);const actor = actorName ?? USER_NAME_FALLBACK;- const showTarget = shouldShowNotificationTarget(notification);+ // An unresolved target is left out of the title, not shown as a placeholder.const targetName =getNotificationTargetName(notification) ??(await resolveDocumentName(notification.entity_id,notification.entity_type- )) ??- DOCUMENT_NAME_FALLBACK;+ ));+ const showTarget =+ shouldShowNotificationTarget(notification) && targetName !== undefined;const content = getNotificationContent(notification);const action = getNotificationAction(notification);diff --git a/apps/web/src/features/notifications/tests/notification-platform.test.ts b/apps/web/src/features/notifications/tests/notification-platform.test.tsindex a8202be7bf..709dd96635 100644--- a/apps/web/src/features/notifications/tests/notification-platform.test.ts+++ b/apps/web/src/features/notifications/tests/notification-platform.test.ts@@ -417,6 +417,44 @@ describe('platform notification sender and conversation', () => {expect(resolveUserAvatar).not.toHaveBeenCalled();});+ it('names the bot and the channel for a bot reply', async () => {+ const result = await toPlatformNotificationData(+ baseNotification({+ entity_id: 'channel-1',+ notification_event_type: 'channel_message_reply',+ notification_metadata: {+ tag: 'channel_message_reply',+ content: {+ threadId: 'thread-1',+ messageId: 'message-1',+ senderDisplayName: 'pickle',+ messageContent: 'Task completed',+ channelType: 'private',+ channelName: 'bug-reports',+ },+ },+ } as Partial<UnifiedNotification>),+ async () => undefined,+ async () => undefined,+ async () => undefined+ );++ expect(result?.title).toBe('pickle <bug-reports>');+ expect(result?.sender?.name).toBe('pickle');+ });++ it('leaves out a target it cannot name', async () => {+ const result = await toPlatformNotificationData(+ channelMessage('public'),+ async () => 'Ada',+ async () => undefined,+ async () => undefined+ );++ expect(result?.title).toBe('Ada');+ expect(result?.conversation?.name).toBeUndefined();+ });+it('has no sender when nobody can be named', async () => {const result = await toPlatformNotificationData(createChannelInviteNotification(),