英文:
Telegram API, how to add newlines?
问题
尝试了多种方式使用parse_mode
:Markdown
或HTML
:
curl -s "https://api.telegram.org/bot$botToken/sendMessage" \
-H 'Content-Type: application/json' \
-d '{ "parse_mode": "Markdown", "chat_id": "234567", "text": "xxx", "description": "xxxxxxx" }
但都没有奏效。
搜索了许多网站。API文档https://core.telegram.org/bots/api#formatting-options没有提到换行符的事情。
我应该如何保留输入文本中的\n
?
英文:
Tried many way with parse_mode
: Markdown
or HTML
:
curl -s "https://api.telegram.org/bot$botToken/sendMessage" \
-H 'Content-Type: application/json' \
-d '{ "parse_mode": "Markdown", "chat_id": "234567", "text": "xxx", "description": "xxxxxxx" }
But nothing works.
Searched many web sites. API doc https://core.telegram.org/bots/api#formatting-options don't say anything about newlines.
How can I do to preserve \n
from my input text?
答案1
得分: 0
默认支持。我需要将我的换行符翻倍:
message="$(perl -pe 's/\n/\\n/g' <<< "$message")"
英文:
Its supported by default. I need to double my newlines:
message="$(perl -pe 's/\n/\\n/g' <<< "$message")"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论