D M
D M

Reputation: 190

Web mini app in Telegram send data no responce

I have a web mini app in Telegram.

I send data back to bot by function:


    const notifyBotAndClose = async () => {
        if (window.Telegram && window.Telegram.WebApp) {
            console.log("Telegram WebApp API is available");
        } else {
            console.log("Telegram WebApp API is NOT NOT available");
        }
      try {
        window.Telegram.WebApp.ready();
        window.Telegram.WebApp.sendData(JSON.stringify({ command: "start" }));
        sdk.close(); // Closes the mini app
      } catch (error) {
        console.error("Error sending /start:", error);
      }
    };

I can see localy that its sending:


    Telegram WebApp API is available
    telegram-web-apps.js:135 [Telegram.WebView] > postEvent web_app_ready 
    telegram-web-apps.js:135 [Telegram.WebView] > postEvent web_app_data_send {data: '{"command":"start"}'}

I try to catch it on backend of bot


    @router.message()
        async def get_web_app_data(message: types.Message):
            print(message.__dict__)
            if message.web_app_data:
                print(f"Received WebApp data: {message.web_app_data.data}")
                await message.answer(f"Received WebApp data: {message.web_app_data.data}")
            else:
                print("No WebApp data")
                print(message.__dict__)

and cannot see nothing. How can I debug it?

Upvotes: 1

Views: 57

Answers (0)

Related Questions