LIFF Bridge

<!-- LIFF SDK -->
<script src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
<script>
(async () => {
  try {
    const LIFF_ID = "2008184237-A9PoJpEe"; // 例: 165xxxx-xxxxxx
    const BOOKING_URL = "https://munedrumlab.com/contact"; // Ameliaの予約ページURL

    await liff.init({ liffId: LIFF_ID });
    if (!liff.isLoggedIn()) { liff.login(); return; }

    // ユーザーIDの取得(どちらでもOK。両方取得して冗長化)
    const profile = await liff.getProfile();          // profile.userId
    const idtoken = liff.getIDToken();                // JWT
    let lineId = (profile && profile.userId) ? profile.userId : "";

    // 念のためIDトークンからsubも拾う(同一チャンネルで不変のユーザー識別子)
    try {
      const decoded = liff.getDecodedIDToken();       // { sub: "...", name: "...", ... }
      if (!lineId && decoded && decoded.sub) lineId = decoded.sub;
    } catch(e) {}

    // 取得したLINE IDをクエリに付けて予約ページへ遷移
    const sep = BOOKING_URL.includes("?") ? "&" : "?";
    const next = `${BOOKING_URL}${sep}line_id=${encodeURIComponent(lineId)}`;
    window.location.replace(next);
  } catch (e) {
    // 失敗時は予約ページへ(line_idなしで可)
    window.location.replace("https://munedrumlab.com/booking");
  }
})();
</script>