简体   繁体   English

如何发送彩色短信?

[英]How to send a colored text message?

I am trying to send a colored text message to a user as reply, using sendMessage with HTML parsing.我正在尝试使用带有 HTML 解析的sendMessage向用户发送彩色文本消息作为回复。

bot.sendMessage(update.message.chat_id, "<span style=\"color:blue\">foo</span>", telegram.ParseMode.HTML)

Sending <span style="color:blue">foo</span> doesn't work, as span is not supported:发送<span style="color:blue">foo</span>不起作用,因为不支持span

Bad Request: Can't parse message text: Unsupported start tag "span" at byte offset 0 (400)错误请求:无法解析消息文本:字节偏移量 0 (400) 处不支持的起始标记“span”

I am using the python-telegram-bot v. 4.0.3.我正在使用python-telegram-bot v. 4.0.3。

Is there another way?还有别的办法吗?

Unfortunately there is no documentation about the tag accepted by the bot, except the unit test for parsemode .不幸的是,除了parsemode单元测试之外,没有关于机器人接受的标签的文档。

The tags that work are b , i , a for bold, italic and link elements, this is what is offered, maybe there's more but I couldn't find it in the docs有效的标签是b , i , a表示粗体、斜体和链接元素,这就是所提供的,也许还有更多,但我在文档中找不到

Your can enlight piece of text with grave character "`"您可以点亮带有严重字符“`”的文本

AAAA ` enlight piece ` BBB enlight piece `BBB

According to the core API docs , Telegram only supports the <span> tag for spoiler text.根据核心 API 文档,Telegram 仅支持剧透文本的<span>标签。 I tried to send a message with HTML parsing and the text:我尝试发送一条带有 HTML 解析和文本的消息:

"<span style=\"color:#fc5252;\">text</span>"

And got:并得到:

Can't parse entities: tag "span" must have class "tg-spoiler" at byte offset 0无法解析实体:标记“span”必须在字节偏移量 0 处具有 class“tg-spoiler”

I'm guessing this means the <span> tag can only be used for spoiler text.我猜这意味着<span>标签只能用于剧透文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM