Skip to content

feat(telegram): expose parseMode config option#367

Open
Koshkoshinsk wants to merge 2 commits intovercel:mainfrom
Koshkoshinsk:telegram-parse-mode-config
Open

feat(telegram): expose parseMode config option#367
Koshkoshinsk wants to merge 2 commits intovercel:mainfrom
Koshkoshinsk:telegram-parse-mode-config

Conversation

@Koshkoshinsk
Copy link
Copy Markdown

Re-opens #366 — that PR was closed in error and GitHub will not let me reopen it after the branch was deleted. Same commit, same diff.

Problem

Since #245, the Telegram adapter hardcodes parse_mode: \"Markdown\" whenever the caller passes { markdown: ... }. Telegram considers legacy Markdown a deprecated mode (see Bot API formatting options) and it has no escape support, so callers can hit Bad Request: can't parse entities with no way to recover other than dropping the message permanently.

For example, an agent reply containing routine markdown like:

```

  • Trigger required? (does every message need the trigger…)
  • Folder name (e.g. `telegram_family-chat`)
    ```

is rejected by Telegram, and there is currently no way for the caller to pick a different parse mode or disable parsing entirely.

Change

Adds an optional `parseMode` field to `TelegramAdapterConfig`:

```ts
parseMode?: "Markdown" | "MarkdownV2" | "HTML" | "none";
```

The markdown converter is unchanged; this PR only exposes a knob. Callers whose upstream renderer produces MarkdownV2/HTML/plain-text can now tell the adapter not to ask Telegram to parse legacy Markdown entities.

Tests

  • New: `parseMode: "MarkdownV2"` and `"HTML"` round-trip into the request body.
  • New: `parseMode: "none"` omits `parse_mode` entirely.
  • New: invalid `parseMode` value throws `ValidationError` from the constructor.
  • Existing parse_mode tests continue to pass with the unchanged default.

`pnpm turbo build --filter @chat-adapter/telegram` and `pnpm vitest run` (105 tests) both clean.

Since vercel#245, the Telegram adapter hardcodes parse_mode: "Markdown" whenever
the caller passes { markdown: ... }. Telegram considers legacy Markdown a
deprecated mode and it has no escape support, so callers can hit
"Bad Request: can't parse entities" with no way to recover other than
dropping the message.

Add an optional parseMode field to TelegramAdapterConfig that lets callers
choose between "Markdown" (default, backward compatible), "MarkdownV2",
"HTML", or "none" (omit parse_mode entirely as a safety valve).

The converter is unchanged; this PR only exposes a knob so callers whose
upstream renderer produces MarkdownV2/HTML/plain-text can tell the adapter
not to ask Telegram to parse legacy Markdown entities.
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 12, 2026

@Koshkoshinsk is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

TelegramParseMode type is not re-exported from the package entry point, making it inaccessible to consumers of @chat-adapter/telegram.

Fix on Vercel

@Koshkoshinsk
Copy link
Copy Markdown
Author

Good catch — pushed 048b951 adding TelegramParseMode to the type re-export block in src/index.ts. Build + 105 tests still clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant