Skip to content

Support markdown with your agent built with XMTP

Use the markdown content type to send rich formatted text messages with your agent. Markdown allows you to include headers, lists, tables, code blocks, and other formatting elements to create more engaging and structured messages.

Install the package

In some SDKs, the MarkdownCodec is already included in the SDK. If not, you can install the package using the following command:

npm
npm i @xmtp/content-type-markdown

Send markdown content

With XMTP, markdown content is sent as a string containing markdown formatting:

Node
import { ContentTypeMarkdown } from '@xmtp/content-type-markdown';
 
// Basic markdown message
const markdownContent = `## Welcome to XMTP
 
This is a **bold** message with *italic* text and \`inline code\`.
 
- Item 1
- Item 2
- Item 3`;
 
await ctx.conversation.send(markdownContent, ContentTypeMarkdown);

Supported markdown patterns

The markdown content type supports the following formatting patterns:

Headers

  • # H1 headers
  • ## H2 headers
  • ### H3 headers
  • #### H4 headers
  • ##### H5 headers
  • ###### H6 headers

Text formatting

  • **bold text** or __bold text__
  • *italic text* or _italic text_
  • ~~strikethrough text~~
  • `inline code`
  • ```code block```
  • block quote

  • link text

Lists

  • Unordered lists with -, *, or +
  • Ordered lists with numbers
  • Nested lists with proper indentation

Tables

  • Standard markdown table syntax with | separators
  • Header rows with --- separators

Example usage

Node
import { ContentTypeMarkdown } from '@xmtp/content-type-markdown';
 
const content = `## Results Summary
 
- **Total items:** ${count}
- *Status:* ${status}
- \`Processing time:\` ${duration}ms
 
### Next Steps
1. Review results
2. Update configuration
3. Deploy changes
 
| Metric | Value | Status |
|--------|-------|--------|
| Total  | ${total} | ✅ |
| Active | ${active} | 🟡 |
| Errors | ${errors} | ❌ |
 
\`\`\`javascript
const agent = await Agent.create(signer, {
  env: 'dev',
});
\`\`\``;
 
await ctx.conversation.send(content, ContentTypeMarkdown);

Receive markdown content

Node
import { MarkdownCodec } from '@xmtp/content-type-markdown';
 
agent.on('message', async (ctx) => {
  if (ctx.usesCodec(MarkdownCodec)) {
    const markdownContent = ctx.message.content;
    console.log('Received markdown:', markdownContent);
 
    // Process the markdown content
    // You can parse it, extract data, or display it formatted
  }
});

Filter for markdown content

Node
import { MarkdownCodec } from '@xmtp/content-type-markdown';
 
// Check if the message contains markdown
if (ctx.usesCodec(MarkdownCodec)) {
  const markdown: string = ctx.message.content;
  // Handle markdown content
}