这不是重复的问题。我想在由C#编写的电报机器人中使用html代码。我搜索了SO,但没有找到任何答案。怎么做?我使用了TelegramBotSharp。这是与我所解释的部分有关的代码:
MessageTarget target = (MessageTarget)update.Chat ?? update.From;
if(Text.StartsWith("Hello")) {
bot.SendMessage(target, "Hello <a href='http://google.com'> dear</a>", true);
}
Run Code Online (Sandbox Code Playgroud)
Use the following syntax in your message:
*bold text*
_italic text_
[inline URL](http://www.example.com/)
[inline mention of a user](tg://user?id=123456789)
pre-formatted fixed-width code block
Run Code Online (Sandbox Code Playgroud)
注意:目前仅支持上述标记。
标签不得嵌套。
所有不属于标记或HTML实体的<,>和&符号必须替换为相应的HTML实体 (< with <, > with > and & with &).
支持所有数字HTML实体。
该API当前仅支持以下命名的HTML实体: <, >, & and ".
如果需要使用html进行格式化,则需要将“parse_mode”设置为“html”;
https://api.telegram.org/bot1328912345:BBCCDDExVAKD2GOEA1mXWfXfhQ_z8Y6rRh8/sendmessage?chat_id=12345678&text=Sample message&parse_mode=html)
Run Code Online (Sandbox Code Playgroud)
截至目前,Bot 仅支持以下标签:
<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
<u>underline</u>, <ins>underline</ins>
<s>strikethrough</s>, <strike>strikethrough</strike>, <del>strikethrough</del>
<b>bold <i>italic bold <s>italic bold strikethrough</s> <u>underline italic bold</u></i> bold</b>
<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>
<pre><code class="language-python">pre-formatted fixed-width code block written in the Python programming language</code></pre>
Run Code Online (Sandbox Code Playgroud)
来源: https: //core.telegram.org/bots/api#formatting-options