Skip to content

Telegram messages show raw Markdown instead of formatted text #24

Open

Description

@iNicholasBE

Problem

Messages sent to Telegram show raw Markdown syntax instead of rendered formatting. Bold text shows as **text**, and links show as [text](url) instead of being clickable.

Example output in Telegram

Right now in **Antwerp**, the temperature is approximately **6°C (43°F)**, with a feels-like temperature of around **4°C**. There are brief showers occurring in the area, and conditions are quite chilly and wintry. Humidity is high at around 93%.

Sources:
- [Weather Today - Antwerp, Belgium (Weather Atlas)](https://www.weather-atlas.com/en/belgium/antwerp)
- [Antwerp Current Weather (AccuWeather)](https://www.accuweather.com/en/be/antwerp/27046/current-weather/27046)
- [BBC Weather - Antwerp](https://www.bbc.com/weather/2803138)

Expected

Bold text should be rendered as bold, and links should be clickable.

Notes

The AI model outputs standard Markdown (**bold**, [text](url)), but Telegram requires either:

  • Markdown v1 parse mode — natively supports *bold*, _italic_, `code`, and [links](url). Only needs **bold** → *bold* conversion.
  • HTML parse mode — needs Markdown → HTML conversion.
  • MarkdownV2 parse mode — requires escaping all special characters, which conflicts with the AI's standard Markdown output.

Markdown v1 is likely the simplest option.

Activity

  1. Mohammedamaan5714 commented on Mar 23, 2026

    @Mohammedamaan5714
    Contributor

    Proposal to fix Markdown rendering issues using HTML ParseMode

    Hi @iNicholasBE ,

    I would like to work on this issue.

    Proposed Solution:
    Instead of using MarkdownV2 (which is highly sensitive to special character escaping and prone to errors with AI-generated text), I propose converting the AI's Markdown output to HTML before sending it to the Telegram API.

    Implementation Details:

    Library: Use commonmark-java within the Gradle build to handle the conversion efficiently.

    Formatting Logic: Implement a utility service to map standard Markdown tags (**, ) to Telegram-compatible HTML tags (, ).

    API Update: Set the parse_mode to HTML in the outgoing SendMessage payload.

    This approach is more robust than regex-based string replacement and ensures that links and bold text render correctly across all Telegram clients.

    Could you please assign this issue to me? I can have a PR ready shortly.

  2. rdehuyss commented on Mar 23, 2026

    @rdehuyss
    Collaborator

    Hi @Mohammedamaan5714 - sounds like a good plan!

    Markdown to html is indeed also my preferred solution.

  3. Mohammedamaan5714 commented on Mar 26, 2026

    @Mohammedamaan5714
    Contributor
    Image

    Hi @rdehuyss,

    I’ve implemented the Markdown → HTML conversion using CommonMark and integrated it with Telegram’s HTML parse mode.

    I also added a unit test (formatsMarkdownToHtmlAndSetsParseMode) to verify that Markdown is correctly transformed into Telegram-compatible HTML.

    The test is passing locally. However, for full end-to-end validation with actual bot responses, I would need an OpenAI API key, which I currently don’t have.

    Please let me know if you’d like me to validate this in any other way or make further improvements.

  4. iNicholasBE commented on Mar 26, 2026

    @iNicholasBE
    ContributorAuthor

    Hi @Mohammedamaan5714 , can you make a pull request? Thanks for your contribution!
    Can you make a pull request? Then we can check your code and validate it in a real environment!

  5. Mohammedamaan5714 commented on Mar 26, 2026

    @Mohammedamaan5714
    Contributor

    Hi @rdehuyss, I have opened a PR for this. Please review when you get time.

  6. rdehuyss commented on Mar 26, 2026

    @rdehuyss
    Collaborator

    Will do! Probably for somewhere end of today. Thx!

  7. added 2 commits that reference this issue on Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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