I make telegram web app using React Js.
I need method which closed telegram web app and returned to chat.
I found info that there is method close in window.Telegram.WebApp. But it’s undefined when I consoled. And this method doesn’t work.
Even console.log(window) return nothing in telegram web app
Question posted in Telegram API
A comprehensive official documentation can be found here.
A comprehensive official documentation can be found here.
3
Answers
The problem was in global params in TS Need to declare
To make Telegram object appear in global
window
object, you have to append Telegram’s script in your<head/>
tag. You can find official mention about it here.Nevertheless, I don’t recommend usage of Telegram’s script as long as its code is recognized as not optimal and probably vulnerable. To avoid known problems, you can use up-to-date TypeScript libraries, such as
twa-sdk
ortwa-bridge
.