In TMA app you need telegram js script: https://telegram.org/js/telegram-web-app.js and we insert it on the start page. If user try to open link outside telegram, you can detect it in your code (just check js object InitData etc. as written in https://docs.telegram-mini-apps.com/platform/init-data Telegram documentation).