feat: convert standard Markdown to Slack mrkdwn and WhatsApp formatting on fallback - #137
Conversation
feat: implement first-party Fastify webhook adapter
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds ChangesPlatform-specific markdown converters and fallback routing
Fastify webhook plugin
Sequence Diagram(s)sequenceDiagram
participant Client
participant FastifyServer
participant SpectrumPlugin
participant WebhookReceiver
participant onMessage
Client->>FastifyServer: POST /spectrum/webhook (raw bytes)
FastifyServer->>SpectrumPlugin: wildcard parser buffers body into Buffer
SpectrumPlugin->>WebhookReceiver: app.webhook(request, onMessage)
WebhookReceiver->>onMessage: verified Message delivered
onMessage-->>WebhookReceiver: handler resolves
WebhookReceiver-->>SpectrumPlugin: {status, headers, body}
SpectrumPlugin-->>Client: HTTP response with status + binary body
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/src/platform/build.ts (1)
389-391:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winMake the fallback log message platform-agnostic.
Line 390 currently says fallback sends “plain text”, but Slack/WhatsApp paths now send platform-formatted downgraded text. This can mislead debugging and telemetry interpretation.
Suggested patch
- `${platform} does not support markdown; sending the content as plain text instead.`, + `${platform} does not support markdown; sending downgraded text content instead.`,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/core/src/platform/build.ts` around lines 389 - 391, The log message in the platformLog.info call states content is being sent as "plain text" when markdown is not supported, but different platforms like Slack and WhatsApp now send platform-formatted downgraded text instead of actual plain text. Update the message at line 390 to be platform-agnostic by removing the specific reference to "plain text" and instead use a more generic description that accurately reflects that the content is being sent in an alternative format without claiming it is plain text.
🧹 Nitpick comments (1)
packages/spectrum-ts/src/fastify.ts (1)
4-4: ⚡ Quick winReplace wildcard re-export with explicit exports to keep the surface controlled.
export *violates the repository rule against barrel-style re-exports and can unintentionally widen the metapackage API over time.♻️ Proposed change
-export * from "`@spectrum-ts/core/fastify`"; +export { spectrum } from "`@spectrum-ts/core/fastify`"; +export type { + SpectrumPluginOptions, + WebhookHandler, + Message, + Space, +} from "`@spectrum-ts/core/fastify`";As per coding guidelines, "Avoid barrel files (index files that re-export everything) in JavaScript/TypeScript".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/spectrum-ts/src/fastify.ts` at line 4, The wildcard re-export statement export * from "`@spectrum-ts/core/fastify`" violates the repository guidelines against barrel-style re-exports. Replace this wildcard export with explicit named exports by identifying which specific types, functions, or interfaces are being exported from the "`@spectrum-ts/core/fastify`" module and list them individually in the export statement instead of using the wildcard.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/test/webhook/fastify.test.ts`:
- Line 1: Save the original value of process.env.SPECTRUM_WEBHOOK_SECRET before
the test suite runs and restore it after the suite completes. Use a beforeAll
hook to store the original value and an afterAll hook to restore it, ensuring
that any modifications to process.env.SPECTRUM_WEBHOOK_SECRET during the test
suite (around lines 21-23 where it is mutated) do not leak into other test
suites. This pattern prevents nondeterministic behavior in test execution order.
---
Outside diff comments:
In `@packages/core/src/platform/build.ts`:
- Around line 389-391: The log message in the platformLog.info call states
content is being sent as "plain text" when markdown is not supported, but
different platforms like Slack and WhatsApp now send platform-formatted
downgraded text instead of actual plain text. Update the message at line 390 to
be platform-agnostic by removing the specific reference to "plain text" and
instead use a more generic description that accurately reflects that the content
is being sent in an alternative format without claiming it is plain text.
---
Nitpick comments:
In `@packages/spectrum-ts/src/fastify.ts`:
- Line 4: The wildcard re-export statement export * from
"`@spectrum-ts/core/fastify`" violates the repository guidelines against
barrel-style re-exports. Replace this wildcard export with explicit named
exports by identifying which specific types, functions, or interfaces are being
exported from the "`@spectrum-ts/core/fastify`" module and list them individually
in the export statement instead of using the wildcard.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a1b0f91b-4a03-4351-9024-adb056d4baf3
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (12)
packages/core/package.jsonpackages/core/src/authoring.tspackages/core/src/fastify.tspackages/core/src/platform/build.tspackages/core/src/utils/markdown.tspackages/core/test/core/send-markdown-fallback.test.tspackages/core/test/utils/markdown.test.tspackages/core/test/webhook/fastify.test.tspackages/core/tsdown.config.tspackages/spectrum-ts/package.jsonpackages/spectrum-ts/src/fastify.tspackages/spectrum-ts/tsdown.config.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Use explicit types for function parameters and return values when they enhance clarity in TypeScript
Preferunknownoveranywhen the type is genuinely unknown in TypeScript
Use const assertions (as const) for immutable values and literal types in TypeScript
Leverage TypeScript's type narrowing instead of type assertions
Files:
packages/spectrum-ts/tsdown.config.tspackages/core/src/authoring.tspackages/core/src/fastify.tspackages/spectrum-ts/src/fastify.tspackages/core/test/webhook/fastify.test.tspackages/core/tsdown.config.tspackages/core/test/utils/markdown.test.tspackages/core/src/platform/build.tspackages/core/src/utils/markdown.tspackages/core/test/core/send-markdown-fallback.test.ts
**/*.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{js,ts,jsx,tsx}: Use meaningful variable names instead of magic numbers - extract constants with descriptive names
Use arrow functions for callbacks and short functions in JavaScript/TypeScript
Preferfor...ofloops over.forEach()and indexedforloops in JavaScript/TypeScript
Use optional chaining (?.) and nullish coalescing (??) for safer property access in JavaScript/TypeScript
Prefer template literals over string concatenation in JavaScript/TypeScript
Use destructuring for object and array assignments in JavaScript/TypeScript
Useconstby default,letonly when reassignment is needed, nevervarin JavaScript/TypeScript
Alwaysawaitpromises in async functions - don't forget to use the return value in JavaScript/TypeScript
Useasync/awaitsyntax instead of promise chains for better readability in JavaScript/TypeScript
Handle errors appropriately in async code with try-catch blocks in JavaScript/TypeScript
Don't use async functions as Promise executors in JavaScript/TypeScript
Removeconsole.log,debugger, andalertstatements from production code in JavaScript/TypeScript
ThrowErrorobjects with descriptive messages, not strings or other values in JavaScript/TypeScript
Usetry-catchblocks meaningfully - don't catch errors just to rethrow them in JavaScript/TypeScript
Prefer early returns over nested conditionals for error cases in JavaScript/TypeScript
Keep functions focused and under reasonable cognitive complexity limits
Extract complex conditions into well-named boolean variables in JavaScript/TypeScript
Use early returns to reduce nesting in JavaScript/TypeScript
Prefer simple conditionals over nested ternary operators in JavaScript/TypeScript
Group related code together and separate concerns in JavaScript/TypeScript
Don't useeval()or assign directly todocument.cookiein JavaScript/TypeScript
Validate and sanitize user input in JavaScript/TypeScript
Avoid spread syntax in accumulators within loops in JavaScript/Ty...
Files:
packages/spectrum-ts/tsdown.config.tspackages/core/src/authoring.tspackages/core/src/fastify.tspackages/spectrum-ts/src/fastify.tspackages/core/test/webhook/fastify.test.tspackages/core/tsdown.config.tspackages/core/test/utils/markdown.test.tspackages/core/src/platform/build.tspackages/core/src/utils/markdown.tspackages/core/test/core/send-markdown-fallback.test.ts
**/*.{test,spec}.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{test,spec}.{js,ts,jsx,tsx}: Write assertions insideit()ortest()blocks in test files
Avoid done callbacks in async tests - use async/await instead in test files
Don't use.onlyor.skipin committed code in test files
Keep test suites reasonably flat - avoid excessivedescribenesting in test files
Files:
packages/core/test/webhook/fastify.test.tspackages/core/test/utils/markdown.test.tspackages/core/test/core/send-markdown-fallback.test.ts
🔇 Additional comments (10)
packages/core/src/fastify.ts (1)
73-113: LGTM!Also applies to: 115-117
packages/core/package.json (1)
47-50: LGTM!Also applies to: 77-78, 108-108, 118-118, 132-134
packages/core/tsdown.config.ts (1)
10-10: LGTM!Also applies to: 17-17
packages/spectrum-ts/package.json (1)
47-51: LGTM!Also applies to: 87-90
packages/spectrum-ts/tsdown.config.ts (1)
10-10: LGTM!packages/core/src/utils/markdown.ts (1)
168-459: LGTM!packages/core/src/authoring.ts (1)
38-42: LGTM!packages/core/src/platform/build.ts (1)
26-30: LGTM!Also applies to: 250-299, 385-388, 392-397
packages/core/test/utils/markdown.test.ts (1)
2-6: LGTM!Also applies to: 101-162
packages/core/test/core/send-markdown-fallback.test.ts (1)
300-348: LGTM!
This PR implements automatic conversion of standard Markdown (CommonMark + GFM) into platform-specific rich text styles (Slack mrkdwn, WhatsApp formatting, and plain text fallbacks) inside the core send fallbacks pipeline.
Key Changes
markdownToSlackandmarkdownToWhatsappunderpackages/core/src/utils/markdown.tsusingmarkedtoken parsing.sendWithFallbackspipeline (replaceMarkdown/downgradeMarkdown) to receive the platform name and apply these translations.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by CodeRabbit
New Features
fastifyentrypoint.markdownToSlackandmarkdownToWhatsappfor richer platform-specific formatting.Improvements
Bug Fixes
Developer Experience