twa-dev / SDK

npm package for TWA SDK
https://codesandbox.io/s/sdk-kj5961
MIT License
238 stars 21 forks source link

openTelegramLink crashes Mac OS app. Works fine on mobile and web #30

Open artem-lazarev opened 6 days ago

artem-lazarev commented 6 days ago
import type { WebApp } from "@twa-dev/types";

function getMiniApp(): WebApp | null {
  if (
    typeof window !== "undefined" &&
    window.Telegram &&
    window.Telegram.WebApp
  ) {
    return window?.Telegram?.WebApp;
  }
  return null;
}

export default function InviteFriends() {

  const app = getMiniApp();
  const shareUrl = encodeURIComponent(`https://t.me/WhalemapBot/app?startapp=${userId}`);
  const telegramUrl = `https://t.me/share/url?url=${shareUrl}`;

  return (
    <div>
      <Button onClick={() => {app.openTelegramLink(telegramUrl))>
        Send
      </Button>
    </div>
  )
}