You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vanilla TS + Vite环境下@telegram-apps/sdk v3.4.0的mockEnvironment配置问题求助

Vanilla TS + Vite环境下@telegram-apps/sdk v3.4.0的mockEnvironment配置问题求助

大家好,我目前在Vanilla TS + Vite环境中使用@telegram-apps/sdk的v3.4.0版本,想要通过mock环境来模拟Telegram小程序的运行场景,但试了好几种方法都没成功,而且翻遍了新版本的官方文档也没找到关于mock配置的相关说明,实在不知道该怎么解决这个问题了。

我已经尝试了以下两种方案,但都没有效果:

第一种尝试:调用mockTelegramEnv方法

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"
});

第二种尝试:直接挂载window.Telegram对象

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;

备注:内容来源于stack exchange,提问作者Sajjad Ostadebrahim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 09:58:04