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(email): convert booking link mentions to clickable links in sent emails (#8362)
Jacob Beckermanb8ad5bd10600
diff --git a/apps/web/src/features/calendar/utils/calendar-description.ts b/apps/web/src/features/calendar/utils/calendar-description.tsindex becdc45ebf..a76aa16726 100644--- a/apps/web/src/features/calendar/utils/calendar-description.ts+++ b/apps/web/src/features/calendar/utils/calendar-description.ts@@ -1,4 +1,5 @@import { editorIsEmpty } from '@core/component/LexicalMarkdown/utils';+import { convertBookingLinkMentionsToLinks } from '@core/component/LexicalMarkdown/utils/convertBookingLinkMentionsToLinks';import { convertDocumentMentionsToLinks } from '@core/component/LexicalMarkdown/utils/convertDocumentMentionsToLinks';import { getWebOrigin } from '@core/util/webOrigin';import { $generateHtmlFromNodes } from '@lexical/html';@@ -66,6 +67,7 @@ export function exportCalendarDescription(editor: LexicalEditor): string {if (editorIsEmpty(editor)) return '';const doc = parseHtml(editor.read(() => $generateHtmlFromNodes(editor)));convertDocumentMentionsToLinks(doc.body);+ convertBookingLinkMentionsToLinks(doc.body);sanitizeDocument(doc, false);return doc.body.innerHTML;}diff --git a/apps/web/src/features/email-compose/primitives/prepare-email-body.test.ts b/apps/web/src/features/email-compose/primitives/prepare-email-body.test.tsindex 21ed0f5918..c597529cae 100644--- a/apps/web/src/features/email-compose/primitives/prepare-email-body.test.ts+++ b/apps/web/src/features/email-compose/primitives/prepare-email-body.test.ts@@ -167,4 +167,18 @@ describe('prepareEmailBodyFromHtml', () => {expect(quotes).toHaveLength(1);expect(quotes[0].textContent).toContain('already quoted');});++ it('converts booking link mentions to clickable anchor tags', () => {+ const prepared = prepareEmailBodyFromHtml(+ '<p>Book a meeting: <span data-booking-link-mention="true" data-booking-profile-id="abc123" data-booking-slug="30min" data-booking-label="30 Minute Meeting" data-booking-url="https://macro.com/app/book/abc123/30min">30 Minute Meeting</span></p>'+ );+ const decoded = decodeBase64Utf8(prepared.bodyHtml);+ const body = new DOMParser().parseFromString(decoded, 'text/html').body;+ const link = body.querySelector('a[data-booking-link-mention="true"]');+ expect(link).not.toBeNull();+ expect(link?.getAttribute('href')).toBe(+ 'https://macro.com/app/book/abc123/30min'+ );+ expect(link?.textContent).toBe('30 Minute Meeting');+ });});diff --git a/apps/web/src/features/email-compose/primitives/prepare-email-body.ts b/apps/web/src/features/email-compose/primitives/prepare-email-body.tsindex 0822b03f95..8c7f6f5f55 100644--- a/apps/web/src/features/email-compose/primitives/prepare-email-body.ts+++ b/apps/web/src/features/email-compose/primitives/prepare-email-body.ts@@ -3,6 +3,7 @@ import {normalizeContentId,staticFileIdsByContentId,} from '@app/features/email-message/core/inline-images';+import { convertBookingLinkMentionsToLinks } from '@core/component/LexicalMarkdown/utils/convertBookingLinkMentionsToLinks';import { convertDocumentMentionsToLinks } from '@core/component/LexicalMarkdown/utils/convertDocumentMentionsToLinks';import { staticFileReferenceEndpoint } from '@core/constant/servers';import { formatEmailDate } from '@core/util/date';@@ -450,8 +451,9 @@ export function prepareEmailBodyFromHtml(// Apply image scale to width/height attributes so the recipient sees the resized dimensionsapplyMediaScale(parsed.body);- // Convert Macro document mentions to HTML links in the parsed DOM+ // Convert Macro mentions to HTML links in the parsed DOMconst mentions = convertDocumentMentionsToLinks(parsed.body);+ convertBookingLinkMentionsToLinks(parsed.body);// HtmlRenderNode exports as declarative shadow DOM; email clients and the// backend sanitizer drop template content, so inline itdiff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/convertBookingLinkMentionsToLinks.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/convertBookingLinkMentionsToLinks.test.tsnew file mode 100644index 0000000000..c122d0b452--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/utils/convertBookingLinkMentionsToLinks.test.ts@@ -0,0 +1,60 @@+// @vitest-environment jsdom+import { describe, expect, it } from 'vitest';+import { convertBookingLinkMentionsToLinks } from './convertBookingLinkMentionsToLinks';++function convert(html: string) {+ const body = new DOMParser().parseFromString(html, 'text/html').body;+ convertBookingLinkMentionsToLinks(body);+ return { body, link: body.querySelector('a') };+}++describe('convertBookingLinkMentionsToLinks', () => {+ it('converts a booking link mention span to an anchor tag', () => {+ const { link } = convert(+ '<span data-booking-link-mention="true" data-booking-profile-id="abc123" data-booking-slug="30min" data-booking-label="30 Minute Meeting" data-booking-url="https://macro.com/app/book/abc123/30min">30 Minute Meeting</span>'+ );++ expect(link).not.toBeNull();+ expect(link?.href).toBe('https://macro.com/app/book/abc123/30min');+ expect(link?.textContent).toBe('30 Minute Meeting');+ expect(link?.getAttribute('data-booking-link-mention')).toBe('true');+ expect(link?.getAttribute('data-booking-profile-id')).toBe('abc123');+ expect(link?.getAttribute('data-booking-slug')).toBe('30min');+ expect(link?.getAttribute('data-booking-label')).toBe('30 Minute Meeting');+ expect(link?.getAttribute('data-booking-url')).toBe(+ 'https://macro.com/app/book/abc123/30min'+ );+ });++ it('uses slug as fallback label when label is missing', () => {+ const { link } = convert(+ '<span data-booking-link-mention="true" data-booking-profile-id="abc123" data-booking-slug="quick-call" data-booking-url="https://macro.com/app/book/abc123/quick-call">quick-call</span>'+ );++ expect(link?.textContent).toBe('quick-call');+ });++ it('uses text content as fallback when label and slug are missing', () => {+ const { link } = convert(+ '<span data-booking-link-mention="true" data-booking-profile-id="abc123" data-booking-url="https://macro.com/app/book/abc123">Book a meeting</span>'+ );++ expect(link?.textContent).toBe('Book a meeting');+ });++ it('skips elements without a booking URL', () => {+ const { link } = convert(+ '<span data-booking-link-mention="true" data-booking-profile-id="abc123">Missing URL</span>'+ );++ expect(link).toBeNull();+ });++ it('does not add slug attribute when slug is empty', () => {+ const { link } = convert(+ '<span data-booking-link-mention="true" data-booking-profile-id="abc123" data-booking-slug="" data-booking-url="https://macro.com/app/book/abc123">Booking link</span>'+ );++ expect(link?.hasAttribute('data-booking-slug')).toBe(false);+ });+});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/convertBookingLinkMentionsToLinks.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/convertBookingLinkMentionsToLinks.tsnew file mode 100644index 0000000000..5393c4574e--- /dev/null+++ b/apps/web/src/lib/core/component/LexicalMarkdown/utils/convertBookingLinkMentionsToLinks.ts@@ -0,0 +1,36 @@+/** Replace Macro booking-link-mention elements with portable HTML links. */+export function convertBookingLinkMentionsToLinks(root: ParentNode): void {+ const mentionElements = root.querySelectorAll<HTMLElement>(+ '[data-booking-link-mention="true"]'+ );++ mentionElements.forEach((element) => {+ const url = element.getAttribute('data-booking-url');+ const label =+ element.getAttribute('data-booking-label') ||+ element.getAttribute('data-booking-slug') ||+ element.textContent ||+ 'Booking link';++ if (!url) return;++ const link = document.createElement('a');+ link.href = url;+ link.textContent = label;++ // Preserve mention data attributes so importing this HTML into Macro can+ // recreate the richer Lexical node.+ link.setAttribute('data-booking-link-mention', 'true');+ link.setAttribute(+ 'data-booking-profile-id',+ element.getAttribute('data-booking-profile-id') || ''+ );+ const slug = element.getAttribute('data-booking-slug');+ if (slug) link.setAttribute('data-booking-slug', slug);+ const bookingLabel = element.getAttribute('data-booking-label');+ if (bookingLabel) link.setAttribute('data-booking-label', bookingLabel);+ link.setAttribute('data-booking-url', url);++ element.replaceWith(link);+ });+}