Fix Telegram messages: expand literal \n to real newlines before sending

In bash, \n in double-quoted strings is literal backslash+n, not a
newline character. curl --data-urlencode sends them as %5Cn and
Telegram renders them literally in message text, causing \n\n to
appear visibly around proxy links.

Fix: run msg through printf '%b' in telegram_send_message() and
tg_send() to convert \n to actual newlines (0x0A) before the string
is URL-encoded and sent to the Telegram API.

Validated: _esc() markdown escapes (\_,  \*) are unaffected since
underscore and asterisk are not printf escape sequences.
This commit is contained in:
SamNet-dev
2026-02-17 13:38:43 -06:00
parent fd38e1ff54
commit 65ad3c8999

View File

@@ -2618,7 +2618,8 @@ self_update() {
# ── Section 14: Telegram Integration ──────────────────────── # ── Section 14: Telegram Integration ────────────────────────
telegram_send_message() { telegram_send_message() {
local msg="$1" local msg
msg=$(printf '%b' "$1") # expand literal \n to real newlines
local token="${TELEGRAM_BOT_TOKEN}" local token="${TELEGRAM_BOT_TOKEN}"
local chat_id="${TELEGRAM_CHAT_ID}" local chat_id="${TELEGRAM_CHAT_ID}"
@@ -2927,7 +2928,8 @@ get_cached_ip() {
# Minimal Telegram send # Minimal Telegram send
tg_send() { tg_send() {
local msg="$1" local msg
msg=$(printf '%b' "$1") # expand literal \n to real newlines
local label="${TELEGRAM_SERVER_LABEL:-MTProxyMax}" local label="${TELEGRAM_SERVER_LABEL:-MTProxyMax}"
local _ip; _ip=$(get_cached_ip) local _ip; _ip=$(get_cached_ip)
[ -n "$_ip" ] && msg="[$(_esc "$label") | ${_ip}] ${msg}" || msg="[$(_esc "$label")] ${msg}" [ -n "$_ip" ] && msg="[$(_esc "$label") | ${_ip}] ${msg}" || msg="[$(_esc "$label")] ${msg}"