skip to Main Content

i’m trying to use Web App in my telegram bot. As the docs says, i have included the script telegram-web-app.js.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <script src="https://telegram.org/js/telegram-web-app.js"></script>   <--
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>

  </body>
</html>

So i connected the script and try to use window.Telegram.WebApp.

const tg = window.Telegram.WebApp;

But i have an error: Unresolved variable Telegram, Unresolved variable WebApp

2

Answers


  1. Chosen as BEST ANSWER

    (window as any).Telegram.WebApp works for me.


  2. Try to put inside body tag

    <body>
    ...
    <script src="https://telegram.org/js/telegram-web-app.js"></script>
    ...
    </body>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search