c# - 哪些 HTML 标签可用于在 Telegram Bot 上发送消息?

标签 c# html markdown telegram-bot

我正在用 C# 开发电报机器人。 使用 TelegramBotClient 库中的类 Telegram.Bot

我想使用 HTML 选项发送带有 SendTextMessageAsync 的消息。 在官方文档 ( https://core.telegram.org/bots/api#markdown-style ) 中,我可以看到:

string texto = @"<b>bold</b>, <strong> bold </strong>" +
               @"<i> italic </i>, <em> italic </em>" +
               @"<a href = 'http://www.example.com/'> inline URL </a>" +
               @"<a href = 'tg://user?id=123456789'> inline mention of a user</a>" +
               @"<code> inline fixed-width code </code>" +
               @"<pre> pre - formatted fixed-width code block</pre>";

 Bot.SendTextMessageAsync(chatId: id_chat,
                          text: texto,
                          parseMode: ParseMode.HTML);

它工作正常,但我想使用“新行”和“列表”。我在电报官方通知中看到了他们,就像这张照片:

enter image description here

我试过 <br>, </br>, <br/> ...等

但是我得到了

Telegram.Bot.Exceptions.ApiRequestException: 'Bad Request: can't parse entities: Unexpected end tag at byte offset 36

有人知道这是否可行吗?

如果可能的话,还要链接一个电话号码吗?

最佳答案

如果您阅读文档中 html 示例下方的下一段,您会看到它说 only the tags mentioned mentioned above are currently supported.

因此,我建议您使用markdown,因为这种解析方式没有提到任何限制。 MD 中的换行符是通过 two spaces 实现的或 <br/> .可以使用 *, + or - 创建 MD 中的列表在列表项的前面,有关更多信息,请参阅 this documentation on MD例如。

对于问题的第二部分,Telegram 电话应用程序会自动突出显示电话号码,但桌面客户端没有此类功能,API/库中也没有内置方式。此外,它仅适用于 0-200 个字符范围内的消息,如下所述: How to make phone number a link in Telegram Bot?

关于c# - 哪些 HTML 标签可用于在 Telegram Bot 上发送消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57394179/

相关文章:

c# - 在 Entity Framework 中将多个外键设置为主键

html - 如何使用 node_load()?

html - 让网站像在智能手机上一样出现在 iframe 中?

r - 运行过滤器 pandoc-citeproc : Could not find executable pandoc-citeproc 时出错

c# - ASP.NET MVC 电子邮件

c# - 为什么 ObjectContext.DetectChanges 不将 State 重置为 Unchanged?

C#定时器我可以加速但不能减速

html - 为什么我不能设置导航标签的宽度

javascript - 如何在 JSF 上使用 Markdown 编辑器 - Primefaces

amazon-web-services - AWS Codecommit Markdown 嵌入图片图像