openclaw - 💡(How to fix) Fix Telegram bold/italic entities not rendered as markdown in agent prompt (regression) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#52859Fetched 2026-04-08 01:18:24
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Timeline (top)
commented ×1

Telegram message formatting (bold, italic, code, strikethrough) entities are not being converted to markdown in the text passed to the agent prompt. Only text_link entities are processed via expandTextLinks().

Previously this worked — bold text sent from Telegram appeared as **word** in the agent context, allowing the agent to detect which words were highlighted.

Root Cause

Root Cause (found in source)

Fix Action

Workaround

None available currently — hooks don't intercept inbound messages before agent processing.

Code Example

const rawText = expandTextLinks(messageTextParts.text, messageTextParts.entities).trim();
RAW_BUFFERClick to expand / collapse

Bug Report

Version: OpenClaw 2026.3.13 (61d171a)

Channel: Telegram (bot DMs)

Description

Telegram message formatting (bold, italic, code, strikethrough) entities are not being converted to markdown in the text passed to the agent prompt. Only text_link entities are processed via expandTextLinks().

Previously this worked — bold text sent from Telegram appeared as **word** in the agent context, allowing the agent to detect which words were highlighted.

Root Cause (found in source)

In src/telegram/bot-message-context.body.ts (compiled in reply-Bm8VrLQh.js), the inbound text processing only calls:

const rawText = expandTextLinks(messageTextParts.text, messageTextParts.entities).trim();

expandTextLinks only handles type === 'text_link' entities. Bold, italic, code, pre, strikethrough, underline entities are extracted but never applied to the text.

Expected Behavior

Telegram entities should be converted to markdown equivalents before being passed to the agent:

  • bold**text**
  • italic_text_
  • codetext
  • pre → fenced code block
  • strikethrough~~text~~

Use Case

Users rely on bold formatting to signal important words to the agent (e.g., vocabulary learning workflows where bold words trigger dictionary lookups).

Workaround

None available currently — hooks don't intercept inbound messages before agent processing.

Steps to Reproduce

  1. Send a Telegram message with bold text: Hello **world**
  2. Check agent context — agent sees plain Hello world with no formatting markers

extent analysis

Fix Plan

To fix the issue, we need to enhance the expandTextLinks function to handle additional entity types. We'll create a new function, applyTelegramEntities, to convert Telegram entities to markdown equivalents.

Step-by-Step Solution

  1. Create a new function applyTelegramEntities in src/telegram/bot-message-context.body.ts:
function applyTelegramEntities(text, entities) {
  const entityMap = {
    bold: '**',
    italic: '_',
    code: '`',
    pre: '```',
    strikethrough: '~~',
  };

  entities.forEach((entity) => {
    const { type, offset, length } = entity;
    if (type in entityMap) {
      const start = text.substring(0, offset);
      const end = text.substring(offset + length);
      const entityText = text.substring(offset, offset + length);
      let markdown = entityText;

      if (type === 'pre') {
        markdown = `\n${entityMap[type]}${entityText}\n${entityMap[type]}`;
      } else if (type === 'code') {
        markdown = `${entityMap[type]}${entityText}${entityMap[type]}`;
      } else {
        markdown = `${entityMap[type]}${entityText}${entityMap[type]}`;
      }

      text = start + markdown + end;
    }
  });

  return text;
}
  1. Modify the expandTextLinks function call to use the new applyTelegramEntities function:
const rawText = applyTelegramEntities(expandTextLinks(messageTextParts.text, messageTextParts.entities), messageTextParts.entities).trim();

Verification

To verify the fix, send a Telegram message with bold text (e.g., Hello **world**) and check the agent context. The agent should now see the text with markdown formatting (e.g., Hello **world**).

Extra Tips

  • Make sure to test the new function with different entity types and edge cases.
  • Consider adding error handling for cases where the entity type is not recognized.
  • If you're using a linter, you may need to update your linting rules to allow for the new markdown syntax.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Telegram bold/italic entities not rendered as markdown in agent prompt (regression) [1 comments, 2 participants]