slack-message-parser is a JavaScript/TypeScript library designed to parse Slack's rich message formatting syntax into a structured Abstract Syntax Tree (AST). This allows developers to programmatically inspect, transform, or render Slack messages outside of the Slack client itself. The current stable version is 3.0.2. The library maintains a steady release cadence, primarily focusing on bug fixes, improvements to parsing accuracy, and adapting to changes in Node.js environments, with major versions introducing breaking changes like the shift to ESM and higher Node.js version requirements. A key differentiator of slack-message-parser is its output: instead of directly rendering to a format like HTML, it provides a hierarchical AST, enabling highly customizable processing, such as converting to various markup languages, performing content analysis, or implementing custom rendering logic. It ships with comprehensive TypeScript types, ensuring robust and type-safe development.
npm install slack-message-parserVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to parse a Slack message string into an AST and then recursively convert that AST into an HTML string, illustrating custom rendering.
Ensure your Node.js environment is at least version 16.0.0. Update Node.js if necessary.
Migrate to `import` statements and ensure your project or Node.js environment is configured for ESM. For CJS projects that cannot migrate, consider dynamic `import()` or use a transpiler.
Explicitly type the return of `parse` as `Root` or adjust type assertions/guards to correctly handle the `Root` type for the top-level AST structure.
Upgrade to slack-message-parser v3.0.2 or newer to ensure accurate parsing of multiline quotes, regardless of whether the `>>>` prefix is used.
Ensure your project is configured as an ES Module (e.g., by adding `"type": "module"` to `package.json` or using `.mjs` file extensions), or use dynamic `import()` if you must remain in CJS.
Use the ESM `import` syntax: `import slackMessageParser from 'slack-message-parser';`. If you must use `require()` in a CJS context, try `const { default: slackMessageParser } = require('slack-message-parser');` or ensure Node.js correctly interops.Implement type guards or switch statements based on `node.type` to correctly narrow the `Node` type to `Root` or other specific types (e.g., `NodeType.Bold`, `NodeType.Italic`) before accessing properties like `children`.
No dependency data recorded yet.