Telegram-Mini-Apps / tma.js

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
338 stars 68 forks source link

[Bug]: utils.shareURL creates link, which doesn't work correctly inside Telegram app #356

Open rodnoycry opened 2 weeks ago

rodnoycry commented 2 weeks ago

Telegram Application

Telegram for Android, Telegram for iOS, Telegram Desktop

Describe the Bug

shareURL method creates link in the next format:

https://t.me/share?url=<url>

Which should trigger share modal in the app according to official documentation of the Share links API. The thing is - this format works correctly only if link was opened outside of the telegram app, for example this link:

https://t.me/share?url=google.com

Will show share modal after redirecting to the app if was clicked in the web environment. But if you copy this exact link to the Telegram app and send it - the same link will give the next error (tested on Windows Desktop, iOS and Android app):

Username @share not found

This is probably happening because Telegram thinks that t.me/share is actual link to the user with "@share" username, when link in such format used in the Telegram application

The same problem happened when I tried to use shareURL method inside my Telegram Mini App. I got error that user was not found

To make link work you actually need to use this format:

https://t.me/share/url?url=<url>

With the additional /url part. Links in this format behaves correctly, you can check it out both inside and outside of the Telegram app:

https://t.me/share/url?url=google.com

P.S. Links, that use tg://msg_url variation of links which are also described in docs and looks like this:

tg://msg_url?url=<url>&text=<text>

Work as expected, but it's not possible to use links in this format in Telegram Mini App

To Reproduce

Steps to reproduce the behavior:

  1. Initialize utils
    
    import { initUtils } from '@tma.js/sdk';

const [utils] = initUtils();


2. Call shareLink method with example link
utils.shareURL('https://google.com', 'Test message');

### Expected Behavior

Opens Telegram app with share modal
heyqbnk commented 2 weeks ago

Thanks for the issue.

We found it not really long time ago. The problem is Telegram has 2 formats of sharing links, both of them doesn't work in some specific Telegram applications.

Related fresh issues: — Telegram Web K: https://github.com/morethanwords/tweb/issues/327 — Telegram for iOS: https://github.com/TelegramMessenger/Telegram-iOS/issues/1415

rodnoycry commented 2 weeks ago

Oh, got it, thank you. Should I also add reproduction in these opened issues?

heyqbnk commented 2 weeks ago

No. We are just waiting for the repositories owners to fix the problem

heyqbnk commented 1 week ago

I have rolled out an update with the link changed, check out @tma.js/sdk@2.5.1. Not closing the issue until the Telegram team fixes the problem on their side.