初始化 正如 @telegram-apps/bridge 文档 中所述,必须手动定义 事件处理程序,才能开始监听 Telegram 迷你应用程序事件。 此外,在我们的代码中,我们希望确保在调用某个方法时,该方法要么有效,要么我们 会收到该方法无效的通知。 为此,有必要了解当前使用的 Telegram Mini Apps 版本。 为满足这些要求,软件包提供了 init 函数,该函数接受具有以下结构的对象 : - interface Options {
" K+ g+ `9 J* F - /**3 Y9 l+ U9 k) `3 h5 e
- * True if the SDK should accept styles sent from the Telegram; @! r! ]4 I; w; e/ ]: i7 x, E2 G
- * application.
- j1 s2 j0 u, ^( @% q4 a) p - * @default true& D4 i$ l- V- B. q1 Z+ `2 c4 A
- */
3 e. e }0 g* j3 S& j3 i - acceptCustomStyles?: boolean;
5 s4 q a) M9 d - /**
$ u: V* {4 [- N) H - * The maximum supported Mini Apps version.+ Y8 F% z9 K. Q% X9 l, I
- * @default Extracted using the `retrieveLaunchParams`
2 h6 V0 P) G. ]' Z* D - * function." V" P' A+ y! K( n
- * @see retrieveLaunchParams
: o. Z( h% v7 O - */
4 \2 a4 C7 n Q; m$ S - version?: Version;
8 K8 ^# ~; z/ N' k ` - /**
7 M* L8 @8 [& j, w) ?% J - * Custom postEvent function.
, a1 m* b% {2 H9 `6 {' r/ }3 s - *- J3 z1 ~8 z1 F! n" l( {# ^0 v
- * Passing the "strict" value creates a function that always
: O {1 d5 j% L - * checks if the specified call is supported by the current Mini
1 j+ S1 S8 l: P( a' _ h8 J - * Apps version. If the method is unsupported, an error
1 Z0 G; M V+ P/ c2 S4 v$ ?5 b: g& j - * will be thrown.7 j$ G9 g5 b, L. c, e7 j
- *
3 C$ v0 g+ P# @ Z: @4 y9 x - * Passing the "non-strict" value creates a postEvent function
0 ]! n# q; ] N* O; T+ b - * that doesn't throw errors but warns about missing method
! K+ @: t( [, `4 K2 f. g - * support.
1 Z0 S5 }, x: `! b - *
. y, ]) [0 H: { - * @default 'strict'
3 S! M& p+ N& T. t! E) G - * @see createPostEvent
1 b# |! @" _- A$ s# v$ C; b - */
9 b, W$ E& P- N( ^; [ - postEvent?: PostEventFn | 'strict' | 'non-strict';
0 x& s [2 U9 Z- g' {& M. A8 Q - }
复制代码在大多数情况下,开发人员不需要使用这些选项。 调用该函数后,将配置软件包的全局依赖关系,并创建 Telegram Mini Apps 事件处理程序。 - import { init } from '@telegram-apps/sdk';. k% i; Q& ~( c
# g/ A; d# @8 b: l- init();
复制代码 ) p2 L) g, b* u$ \( d9 y
! S5 b* V# R& j- }, t. Q; Z |