lnp2pBot/bot

Bug: Persian taker message not delivered due to Telegram MarkdownV2 parse error — proposed fallback fix

Open

#882 opened on Jul 29, 2026

 (0 comments) (0 reactions) (0 assignees)TypeScript (138 forks)auto 404
UXbuggood first issuehelp wantedpriority: high

Repository metrics

Stars
 (290 stars)
PR merge metrics
 (PR metrics pending)

Description

Summary

When a user with language set to Persian (fa) takes an order, the bot sometimes does not send the taker message. Root cause: the Persian translation for the key you_took_someone_order can contain characters that break Telegram's MarkdownV2 parsing, causing bot.telegram.sendMessage(...) to throw and the message not to reach the taker.

Reproduction

  1. Set a Telegram user language to Persian (fa) in the bot.
  2. Publish an order (sell/buy) and have another user take it.
  3. Observe that the taker (buyer/seller) does not receive the "you took order" message and logs show a MarkdownV2 parse-related error.

Proposed fix

Wrap the sendMessage call in beginTakeSellMessage with a try/catch that:

  • first attempts to send with parse_mode: 'MarkdownV2' (preserve intended formatting for safe locales),
  • on failure retries once without parse_mode as a safe fallback.

Minimal patch (applies to bot/messages.ts, function beginTakeSellMessage):

const message = ctx.i18n.t('you_took_someone_order', { expirationTime }); try { await bot.telegram.sendMessage(buyer.tg_id, message, { parse_mode: 'MarkdownV2' }); } catch (err) { logger.error('Failed to send MarkdownV2 message, retrying without parse_mode', err); try { await bot.telegram.sendMessage(buyer.tg_id, message); } catch (err2) { logger.error('Retry without parse_mode also failed', err2); } }

Why this is safe

  • Keeps MarkdownV2 for locales/translations that are already Markdown-safe.
  • Ensures users still receive the message when translations contain unescaped characters.
  • Minimal and local change; no behaviour change for other flows.

Files changed (local patch created)

  • bot/messages.ts (beginTakeSellMessage) — patch saved locally as: C:\Users\gatmiri.majid.copilot\session-state\22f19408-ad09-4767-974a8a675dc4a3a9\files\0001-Fix-fallback-for-MarkdownV2-send-in-beginTakeSellMes.patch

Testing

  • Run the bot (npm run dev or npm start). Set a user language to fa and take an order. Taker should receive the message.
  • If errors still occur, inspect logs for Telegram parse errors and escape MarkdownV2 special chars in locales/fa.yaml (key: you_took_someone_order).

Next steps

  • Apply the change and merge into main/release branch.
  • Optional: sanitize/escape MarkdownV2 in locales/fa.yaml to keep full MarkdownV2 formatting.

If useful, I can open a PR directly if given push rights; otherwise please apply the patch above or run the included patch with git am.

Contributor guide