Telegram API,如何添加换行?

huangapple go评论70阅读模式
英文:

Telegram API, how to add newlines?

问题

尝试了多种方式使用parse_modeMarkdownHTML

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")"

huangapple
  • 本文由 发表于 2023年5月29日 10:59:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76354443.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定