use*_*979 8 markdown telegram-bot
电报不会逃避某些降价字符,例如:
这很好用
_测试一下_
但是这个返回解析错误
*测试一下*
我做错了什么?
Ole*_*leg 11
唯一的解决方法是HTML在parse_mode
https://core.telegram.org/bots/api#html-style
Sta*_*nko 11
根据电报 API
In all other places characters '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!' must be escaped with the preceding character '\'.
所以这是我用过的函数
text
.replace(/\_/g, '\\_')
.replace(/\*/g, '\\*')
.replace(/\[/g, '\\[')
.replace(/\]/g, '\\]')
.replace(/\(/g, '\\(')
.replace(/\)/g, '\\)')
.replace(/\~/g, '\\~')
.replace(/\`/g, '\\`')
.replace(/\>/g, '\\>')
.replace(/\#/g, '\\#')
.replace(/\+/g, '\\+')
.replace(/\-/g, '\\-')
.replace(/\=/g, '\\=')
.replace(/\|/g, '\\|')
.replace(/\{/g, '\\{')
.replace(/\}/g, '\\}')
.replace(/\./g, '\\.')
.replace(/\!/g, '\\!')
Run Code Online (Sandbox Code Playgroud)
但请记住,这意味着如果您打算使用*某些文本*作为粗体文本,此脚本将渲染*某些文本*而不应用粗体效果
String escapedMsg = toEscapeMsg
.replace("_", "\\_")
.replace("*", "\\*")
.replace("[", "\\[")
.replace("`", "\\`");
Run Code Online (Sandbox Code Playgroud)
不要逃避]性格.如果[被转义,]则被视为普通字符.
实际上两者都出现错误。
{
"ok": false,
"error_code": 400,
"description": "Bad Request: Can't parse message text: Can't find end of the entity starting at byte offset 11"
}
Run Code Online (Sandbox Code Playgroud)
听起来 Telegram 不支持 Markdown 的转义字符,所以我建议你改用 HTML:
<b>test*test</b>
| 归档时间: |
|
| 查看次数: |
6136 次 |
| 最近记录: |