Reputation: 93
Environment: Vanilla TS + Vite
Package: @telegram-apps/sdk - v3.4.0
I have used a bunch of different ways to try and use mockEnvironment but it just doesn't seem to work, and there's no documentations for the new version about the mock that I could find, I'm not sure how to make this work.
A couple of things I've tried that didn't work:
mockTelegramEnv({
tgWebAppThemeParams: {
accent_text_color: '#6ab2f2',
bg_color: '#17212b',
button_Color: '#5288c1',
button_text_color: '#ffffff',
destructive_text_color: '#ec3942',
header_bg_color: '#17212b',
hint_color: '#708499',
link_color: '#6ab3f3',
secondary_bg_color: '#232e3c',
section_bg_color: '#17212b',
section_header_text_color: '#6ab3f3',
subtitle_text_color: '#708499',
text_color: '#f5f5f5',
},
tgWebAppData: {
user: {
id: 99281932,
first_name: 'Andrew',
last_name: 'Rogue',
username: 'rogue',
language_code: 'en',
},
hash: '89d6079ad6762351f38c6dbbc41bb53048019256a9443988af7a48bcad16ba31',
auth_date: new Date(1716922846000),
signature: 'abc',
start_param: 'debug',
chat_type: 'sender',
chat_instance: '8428209589180549439',
},
tgWebAppVersion: "8.0",
tgWebAppPlatform: "tdesktop",
tgWebAppStartParam: "debug"
});
and:
window.Telegram = {
tgWebAppThemeParams: {
accent_text_color: '#6ab2f2',
bg_color: '#17212b',
button_Color: '#5288c1',
button_text_color: '#ffffff',
destructive_text_color: '#ec3942',
header_bg_color: '#17212b',
hint_color: '#708499',
link_color: '#6ab3f3',
secondary_bg_color: '#232e3c',
section_bg_color: '#17212b',
section_header_text_color: '#6ab3f3',
subtitle_text_color: '#708499',
text_color: '#f5f5f5',
},
tgWebAppData: {
user: {
id: 99281932,
first_name: 'Andrew',
last_name: 'Rogue',
username: 'rogue',
language_code: 'en',
},
hash: '89d6079ad6762351f38c6dbbc41bb53048019256a9443988af7a48bcad16ba31',
auth_date: new Date(1716922846000),
signature: 'abc',
start_param: 'debug',
chat_type: 'sender',
chat_instance: '8428209589180549439',
},
tgWebAppVersion: "6.0",
tgWebAppPlatform: "web",
tgWebAppStartParam: "debug"
} as LaunchParams;
Upvotes: 0
Views: 55
Reputation: 26
Found this in tests:
It is working perfect for me:
mockTelegramEnv({
launchParams:
"tgWebAppData=user%3D%257B%2522id%2522%253A279058397%252C%2522first_name%2522%253A%2522Vladislav%2522%252C%2522last_name%2522%253A%2522Kibenko%2522%252C%2522username%2522%253A%2522vdkfrost%2522%252C%2522language_code%2522%253A%2522ru%2522%252C%2522is_premium%2522%253Atrue%252C%2522allows_write_to_pm%2522%253Atrue%252C%2522photo_url%2522%253A%2522https%253A%255C%252F%255C%252Ft.me%255C%252Fi%255C%252Fuserpic%255C%252F320%255C%252F4FPEE4tmP3ATHa57u6MqTDih13LTOiMoKoLDRG4PnSA.svg%2522%257D%26chat_instance%3D-9019086117643313246%26chat_type%3Dsender%26auth_date%3D1736409902%26signature%3DFNWSy6kv5n4kkmYYmfTbrgRtswTvwXgHTRWBVjp-YOv2srtMFSYCWZ9nGr_PohWZeWcooFo_oQgsnTJge3JdBA%26hash%3D4c710b1d446dd4fd301c0efbf7c31627eca193a2e657754c9e0612cb1eb71d90&tgWebAppVersion=8.0&tgWebAppPlatform=tdesktop&tgWebAppThemeParams=%7B%22accent_text_color%22%3A%22%236ab3f2%22%2C%22bg_color%22%3A%22%2317212b%22%2C%22bottom_bar_bg_color%22%3A%22%2317212b%22%2C%22button_color%22%3A%22%235289c1%22%2C%22button_text_color%22%3A%22%23ffffff%22%2C%22destructive_text_color%22%3A%22%23ec3942%22%2C%22header_bg_color%22%3A%22%2317212b%22%2C%22hint_color%22%3A%22%23708599%22%2C%22link_color%22%3A%22%236ab3f3%22%2C%22secondary_bg_color%22%3A%22%23232e3c%22%2C%22section_bg_color%22%3A%22%2317212b%22%2C%22section_header_text_color%22%3A%22%236ab3f3%22%2C%22section_separator_color%22%3A%22%23111921%22%2C%22subtitle_text_color%22%3A%22%23708599%22%2C%22text_color%22%3A%22%23f5f5f5%22%7D",
});
Upvotes: 1