Skip to content

Telegram adapter: parse_mode not set for markdown messages #226

@buremba

Description

@buremba

Bug

When sending messages with { markdown: ... } payload, the Telegram adapter does not set parse_mode on the Telegram API call. This causes Telegram to render the message as plain text, showing raw markdown characters (**bold**, _italic_) instead of formatted text.

Root Cause

In @chat-adapter/telegram, both postMessage and editMessage only set parseMode when a card is present:

const parseMode = card ? TELEGRAM_MARKDOWN_PARSE_MODE : void 0;

When the message payload is { markdown: "**hello**" }, the formatConverter.renderPostable() correctly processes the markdown text, but parseMode remains undefined because there's no card. The Telegram API then treats the text as plain.

Expected Behavior

parse_mode should be set to "Markdown" when the message contains a markdown field:

const parseMode = (card || (typeof message === "object" && message !== null && "markdown" in message))
  ? TELEGRAM_MARKDOWN_PARSE_MODE
  : void 0;

Affected Methods

  • postMessage (line ~527 in dist)
  • editMessage (line ~593 in dist)

Reproduction

const chat = new Chat({ adapters: { telegram: telegramAdapter } });
const thread = await chat.getThread("telegram", threadId);

// This renders as plain text with visible ** characters
await thread.post({ markdown: "**bold** and _italic_" });

// This works correctly (has card → parseMode is set)
await thread.post({ card: Card({ children: [CardText("hello")] }), fallbackText: "hello" });

Workaround

We're using bun patch to fix this locally:

-    const parseMode = card ? TELEGRAM_MARKDOWN_PARSE_MODE : void 0;
+    const parseMode = (card || (typeof message === "object" && message !== null && "markdown" in message)) ? TELEGRAM_MARKDOWN_PARSE_MODE : void 0;

Version

@chat-adapter/telegram@4.20.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions