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
732 stars 202 forks source link

[Bug]: CAN NOT USE photoUrl from user with mockTelegramEnv #456

Closed fukemy closed 3 months ago

fukemy commented 3 months ago

Telegram Application

Other

Describe the Bug

I follow the website document:

import { mockTelegramEnv, parseInitData } from "@telegram-apps/sdk-react";

const initDataRaw = new URLSearchParams([
    ['user', JSON.stringify({
        id: -99281932,
        first_name: 'Andrew',
        last_name: 'Rogue',
        username: 'rogue',
        language_code: 'en',
        is_premium: false,
        photoUrl: 'https://avatars.githubusercontent.com/u/8202437',
        allows_write_to_pm: true,
    })],
    ['hash', '89d6079ad6762351f38c6dbbc41bb53048019256a9443988af7a48bcad16ba31'],
    ['auth_date', '1716922846'],
    ['start_param', 'debug'],
    ['chat_type', 'sender'],
    ['chat_instance', '8428209589180549439'],
]).toString();

export default function generateTelegramMockup() {
    mockTelegramEnv({
        themeParams: {
            accentTextColor: '#6ab2f2',
            bgColor: '#17212b',
            buttonColor: '#5288c1',
            buttonTextColor: '#ffffff',
            destructiveTextColor: '#ec3942',
            headerBgColor: '#17212b',
            hintColor: '#708499',
            linkColor: '#6ab3f3',
            secondaryBgColor: '#232e3c',
            sectionBgColor: '#17212b',
            sectionHeaderTextColor: '#6ab3f3',
            subtitleTextColor: '#708499',
            textColor: '#f5f5f5',
        },
        initData: parseInitData(initDataRaw),
        initDataRaw,
        version: '7.2',
        platform: 'tdesktop',
    });
}

But when get initData, I can not see the photoUrl. Tried with clear cache, delete .next folder(NextJS)...

To Reproduce

Steps to reproduce the behavior:

  1. Apply document code https://docs.telegram-mini-apps.com/packages/telegram-apps-sdk/environment
  2. Get InitData

Expected Behavior

I want to get photoUrl with mockTelegramEnv

fukemy commented 3 months ago

I tested with mini app version from MacOS but still can not get photoUrl

heyqbnk commented 3 months ago

Because it should be photo_url.

fukemy commented 3 months ago

i checked initData but can not find this, no photo_url even I have this

heyqbnk commented 3 months ago

Mocking init data, you must use this data:

const initDataRaw = new URLSearchParams([
    ['user', JSON.stringify({
        id: -99281932,
        first_name: 'Andrew',
        last_name: 'Rogue',
        username: 'rogue',
        language_code: 'en',
        is_premium: false,
        photo_url: 'https://avatars.githubusercontent.com/u/8202437',
        allows_write_to_pm: true,
    })],
    ['hash', '89d6079ad6762351f38c6dbbc41bb53048019256a9443988af7a48bcad16ba31'],
    ['auth_date', '1716922846'],
    ['start_param', 'debug'],
    ['chat_type', 'sender'],
    ['chat_instance', '8428209589180549439'],
]).toString();

Anyways, why do you need it? It is only accessible to Telegram partners