Telegram-Mini-Apps / telegram-apps

Made from scratch TypeScript packages, examples and documentation you will surely need to start developing on Telegram Mini Apps.
https://docs.telegram-mini-apps.com/
MIT License
734 stars 202 forks source link

How to open tg://-like links #451

Closed mikhaillav closed 3 months ago

mikhaillav commented 3 months ago

I need to open links like tg://user?id=12345678. So for example by pressing a button you can open someones profile.

I tried to use utils.openLink and openTelegramLink (just in case).

Code to reproduce crash (assuming you have <SDKProvider />)

// page.tsx
"use client";

import { initUtils } from "@telegram-apps/sdk-react";

function openUserProfile() {
    const utils = initUtils();

    utils.openLink("tg://user?id=12345678"); // put your own id here
}

export default function Home() {
    return (
        <button onClick={openUserProfile}>
            <p>Click me!</p>
        </button>
    );
}

I also used nextjs <Link> & <a> but they don't seem to be working (just nothing happens on click).

I ran out of ideas how to implement this feature, maybe this even a bug. Will appreciate any help.

heyqbnk commented 3 months ago

I am not sure, there is a way to open such kind of links. You could try opening them via usual way we use in browsers. In case, it works fine in all Telegram applications, we may add it in the SDK

mikhaillav commented 3 months ago

I tried to open it via browser. It asked me to open telegram but didn't open requested chat. image Thats sad. But thank you for the response!

mikhaillav commented 3 months ago

Accroding to documentation normal clients should ignore these links. Its telegram issue.