telegramtelegram-bot

How to check if the bot url is opened within telegram's in app browser only


I'm new to telegram bots and found its features fantastic for further development of my project and now know that I can send a link button to the bot user so that when tapped, the target url will be opened in telegram's in app browser.

The question I have is how to check in the server if this url is opened within telegram's in app webview only and not in another browser, by copying the url and pasting it for example into chrome?

I need to check that if the url copied and pasted to another browser then redirect the user to a message page and not opening the target page. I want my user to open the url using the telegram's in app browser only and nowhere else. And this telegram should be the one that has received the bot link and even not another telegram of another user.

Therefore checking and controlling the user agent sent to the server will not solve my problem because it may be another telegram of another user or even a faked desktop browser so can't rely on this from a security perspective.

Thanx for your help


Solution

  • Questions

    I want my user to open the url using the telegram's in app browser only and nowhere else

    Telegram bot API does not provide any mechanisms for that on client side.

    ... how to check in the server if this url is opened within telegram's in app webview only and not in another browser, by copying the url and pasting it for example into chrome?

    You cannot detect "invalid" browser usage on server side as well, because you will need some kind of authentication mechansim to ensure that particular user has permissions to read particular page. Server does not receive any kind of cookies, specific for your service and of course it does not receive any information about telegram session and related Telegram API stuff.

    And of course you can't rely on User-Agent header because it can be easily manually specified in utilities like curl.


    Workarounds

    There are some possible solutions, but there's no easy one.