I've created a bot in telegram
I want to send bold and italic text with HTML page to bot
My HTML code is:
<html>
<head><title>Telegram</title></head>
<body>
<form method="GET" action="https://api.telegram.org/bot(token)/sendMessage">
<input type="hidden" name="chat_id" value="@testadminch">
<input type="hidden" name="parse_mod" value="markdown">
<textarea name="text"></textarea>
<input type="submit" value="Submit">
</form>
</body>
</html>
If I send *bold*
the output should be bold but it doesn't work
Maak
There are two possibilities to get: bold
- Set the
parse_mode
tomarkdown
and send*bold*
- Set the
parse_mode
tohtml
and send<b>bold</b>
If you are using PHP you can use this, and I'm sure it's almost similar in other languages as well
$WebsiteURL = "https://api.telegram.org/bot".$BotToken;
$text = "<b>This</b> <i>is some Text</i>";
$Update = file_get_contents($WebsiteURL."/sendMessage?chat_id=$chat_id&text=$text&parse_mode=html);
echo $Update;
Here is the list of all tags that you can use
<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
<a href="http://www.example.com/">inline URL</a>
<code>inline fixed-width code</code>
<pre>pre-formatted fixed-width code block</pre>
For italic you can use the 'i' tag, for bold try the 'b' tag
<i> italic </i>
<b> bold </b>
So when sending the message to telegram you use:
$token = <Enter Your Token Here>
$url = "https://api.telegram.org/bot".$token;
$chat_id = <The Chat Id Goes Here>;
$test = <Message goes Here>;
//sending Message normally without styling
$response = file_get_content($url."\sendMessage?chat_id=$chat_id&text=$text");
If our message has html tags in it we add "parse_mode" so that our url becomes:
$response = file_get_content($url."\sendMessage?chat_id=$chat_id&text=$text&parse_mode=html")
parse mode can be "HTML" or "markdown"
来源:https://stackoverflow.com/questions/38119481/send-bold-italic-text-on-telegram-bot-with-html