当 parse_mode = 降价时转义电报 api 中的下划线



如何正确发送此文本:

$parameters['text'] = 'you must see [example](example.com) or contact with @exmaple_com';

如果我不使用"降价",电报不会显示上面的链接 如果我使用"降价",电报无法处理下划线。

你应该使用反斜杠来做到这一点:

$parameters['text'] = 'you must see [example](example.com) or contact with @exmaple\_com';

当您在 Markdown 或 MarkdownV2 上设置parse_mode时,您不能直接使用以下字符:()._-

你应该使用反斜杠转义它们,

此外,您应该转义反斜杠本身。 例如,在 Golang 中,我编写了这个函数来解决我的问题:

func FmtTelegram(input string) string {
return strings.NewReplacer(
"(", "\(", // ()_-. are reserved by telegram.
")", "\)",
"_", "\_",
".", "\.",
"-", "\-",
).Replace(input)
}

在PHP中,你应该像这样转义:

$parameters['text'] = '\_com';
# or
$parameters['text'] = '\.com';
# or
$parameters['text'] = '\-com';
# or
$parameters['text'] = '\(com\)';

最新更新