在 Telegram 机器人中使用 HTML
Using HTML in Telegram bot
这不是一个重复的问题。
我想在我用 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);
}
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
注意:
目前仅支持上述标签。
标签不得嵌套。
所有不属于标签或 HTML 实体的 <、> 和 & 符号必须替换为相应的 HTML 实体 (< with <, > with > and & with &).
支持所有数字 HTML 实体。
API 目前仅支持以下命名的 HTML 实体:<, >, & and ".
使用 sendMessage
时,在 parse_mode
字段中传递 HTML
。
如果您需要使用 html 进行格式化,您需要将“parse_mode”设置为“html”;
https://api.telegram.org/bot1328912345:BBCCDDExVAKD2GOEA1mXWfXfhQ_z8Y6rRh8/sendmessage?chat_id=12345678&text=Sample message&parse_mode=html)
截至目前,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>
这不是一个重复的问题。 我想在我用 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);
}
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
注意: 目前仅支持上述标签。
标签不得嵌套。
所有不属于标签或 HTML 实体的 <、> 和 & 符号必须替换为相应的 HTML 实体 (< with <, > with > and & with &).
支持所有数字 HTML 实体。
API 目前仅支持以下命名的 HTML 实体:<, >, & and ".
使用 sendMessage
时,在 parse_mode
字段中传递 HTML
。
如果您需要使用 html 进行格式化,您需要将“parse_mode”设置为“html”;
https://api.telegram.org/bot1328912345:BBCCDDExVAKD2GOEA1mXWfXfhQ_z8Y6rRh8/sendmessage?chat_id=12345678&text=Sample message&parse_mode=html)
截至目前,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>