Telegram Bot Web 应用程序长时间加载

问题描述 投票:0回答:1

我正在开发一个带有 Web 应用程序的电报机器人,使用 React 作为 Web 界面,使用 Node.js (node-telegram-bot-api) 来实现机器人功能。在某些设备上,Web 应用程序的初始加载速度很快,但有时(主要是在 iPhone 上),首次加载速度非常慢,需要 3-5 秒。我正在使用反应。并尽快调用 telegram web_app

ready()
方法。

index.html

<head>
    <script src="https://telegram.org/js/telegram-web-app.js"></script>
    <meta charset="UTF-8"/>
    <link rel="icon" type="image/svg+xml" href="/logo.svg"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Goodjoy</title>
</head>
<body class="loader">
<div id="root"></div>
 
<script>
    if (window.Telegram && window?.Telegram?.WebApp) {
        window.Telegram.WebApp.ready();
    }
</script>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>

bot.js

const bot = new TelegramBot(TOKEN, { polling: true });
const app = express();
app.use(express.json());
app.use(cors({
    origin: []
}));
const upload = multer();
app.use(express.json());
bot.onText(/\/start/, async (msg) => {
    console.log('start');
    const chatId = msg.chat.id;
    const telegramId = msg.from.id;
    try {
        await bot.sendMessage(chatId, 'Welcome to my bot', {
            reply_markup: {
                inline_keyboard: [
                    [{ text: 'Open web app', web_app: { url: webappurl } }]
                ]
            }
        });
    } catch (e) {
        console.log(e);
    }
});

有人遇到过这个问题或者有解决办法吗?

我正在使用 React 并尽快利用电报的 read() 方法。我已将其添加到index.html 正文部分的标记脚本中。此外,我尝试创建一个预加载器并向index.html 添加样式,但它最终出现在渲染过程结束时。结果,用户首先看到白屏 2-5 秒,然后预加载器出现 1 秒,最后显示整个应用程序。

node.js reactjs telegram node-telegram-bot-api
1个回答
0
投票

我面临着完全相同的问题。最初,我以为要等到免费套餐服务器启动,但后来在 Android 移动设备上尝试,应用程序立即启动。

© www.soinside.com 2019 - 2024. All rights reserved.