I created a game using HTML, now I am trying to import it in my js file, and send to user.
This is my code so far
const { Telegraf } = require('telegraf')
const bot = new Telegraf(process.env.BOT_TOKEN);
const test = require('./index.html');
bot.hears('?', ctx => {
// console.log(ctx.from)
let msg = `Spin the wheel`;
ctx.deleteMessage();
bot.telegram.sendMessage(ctx.chat.id, msg, {
reply_markup: {
inline_keyboard: [
[{
text: "SPIN",
callback_data: 'wheeloffortune'
}
],
]
}
})
})
bot.action('wheeloffortune', ctx => {
bot.telegram.sendMessage(ctx.chat.id, test, {parse_mode: 'HTML'});
})
but I am getting this error
<!DOCTYPE html>
^
SyntaxError: Unexpected token '<'
Any advice is appreciated
As mentioned on Telegram BOT API's documentation, parse_mode
of type html
only supports a few tags. Therefore, you can't send your game's html file to the chat for the user with parse_mode
set to html
.
Here's what the docs say:
To use this mode, pass HTML in the parse_mode field. The following tags are currently supported:
<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>
<span class="tg-spoiler">spoiler</span>, <tg-spoiler>spoiler</tg-spoiler>
<b>bold <i>italic bold <s>italic bold strikethrough <span class="tg-spoiler">italic bold strikethrough spoiler</span></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>