@core-ease/telegram-kit 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +299 -0
- package/dist/animation/index.d.mts +4 -0
- package/dist/animation/index.d.ts +4 -0
- package/dist/animation/index.js +2413 -0
- package/dist/animation/index.mjs +5 -0
- package/dist/animation/lottie/index.d.mts +10 -0
- package/dist/animation/lottie/index.d.ts +10 -0
- package/dist/animation/lottie/index.js +2313 -0
- package/dist/animation/lottie/index.mjs +4 -0
- package/dist/animation/tgs/index.d.mts +18 -0
- package/dist/animation/tgs/index.d.ts +18 -0
- package/dist/animation/tgs/index.js +2402 -0
- package/dist/animation/tgs/index.mjs +4 -0
- package/dist/bot/index.d.mts +477 -0
- package/dist/bot/index.d.ts +477 -0
- package/dist/bot/index.js +870 -0
- package/dist/bot/index.mjs +847 -0
- package/dist/bot-D8BnLWIi.d.mts +2041 -0
- package/dist/bot-D8BnLWIi.d.ts +2041 -0
- package/dist/browser.global.js +23 -0
- package/dist/chunk-7AARTHNW.mjs +40 -0
- package/dist/chunk-7CVYPKAL.mjs +15 -0
- package/dist/chunk-B3PWALX5.mjs +4418 -0
- package/dist/chunk-BQEUEAVK.mjs +2262 -0
- package/dist/chunk-FPWYSKK2.mjs +3089 -0
- package/dist/chunk-JXK5HCDV.mjs +254 -0
- package/dist/chunk-OMH2JGOH.mjs +88 -0
- package/dist/chunk-PXO36YTU.mjs +38 -0
- package/dist/core/index.d.mts +151 -0
- package/dist/core/index.d.ts +151 -0
- package/dist/core/index.js +3837 -0
- package/dist/core/index.mjs +495 -0
- package/dist/dev/index.d.mts +77 -0
- package/dist/dev/index.d.ts +77 -0
- package/dist/dev/index.js +3214 -0
- package/dist/dev/index.mjs +151 -0
- package/dist/engine-BDm1_hzn.d.mts +382 -0
- package/dist/engine-BDm1_hzn.d.ts +382 -0
- package/dist/format/index.d.mts +61 -0
- package/dist/format/index.d.ts +61 -0
- package/dist/format/index.js +121 -0
- package/dist/format/index.mjs +112 -0
- package/dist/hooks/index.d.mts +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +4234 -0
- package/dist/hooks/index.mjs +3 -0
- package/dist/hooks-C5Per70R.d.mts +1066 -0
- package/dist/hooks-C5Per70R.d.ts +1066 -0
- package/dist/index.d.mts +849 -0
- package/dist/index.d.ts +849 -0
- package/dist/index.js +5026 -0
- package/dist/index.mjs +478 -0
- package/dist/keyboards/index.d.mts +50 -0
- package/dist/keyboards/index.d.ts +50 -0
- package/dist/keyboards/index.js +127 -0
- package/dist/keyboards/index.mjs +124 -0
- package/dist/links/index.d.mts +53 -0
- package/dist/links/index.d.ts +53 -0
- package/dist/links/index.js +139 -0
- package/dist/links/index.mjs +133 -0
- package/dist/lottie/index.d.mts +3 -0
- package/dist/lottie/index.d.ts +3 -0
- package/dist/lottie/index.js +2313 -0
- package/dist/lottie/index.mjs +4 -0
- package/dist/qr/index.d.mts +75 -0
- package/dist/qr/index.d.ts +75 -0
- package/dist/qr/index.js +983 -0
- package/dist/qr/index.mjs +946 -0
- package/dist/sdk/index.d.mts +322 -0
- package/dist/sdk/index.d.ts +322 -0
- package/dist/sdk/index.js +3138 -0
- package/dist/sdk/index.mjs +2 -0
- package/dist/server/index.d.mts +28 -0
- package/dist/server/index.d.ts +28 -0
- package/dist/server/index.js +254 -0
- package/dist/server/index.mjs +246 -0
- package/dist/tgs/index.d.mts +3 -0
- package/dist/tgs/index.d.ts +3 -0
- package/dist/tgs/index.js +2402 -0
- package/dist/tgs/index.mjs +4 -0
- package/dist/webapp-B-3_74nK.d.mts +842 -0
- package/dist/webapp-B-3_74nK.d.ts +842 -0
- package/dist/webapp-BDi9q3-a.d.mts +42 -0
- package/dist/webapp-YvmwFYUQ.d.ts +42 -0
- package/package.json +165 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Core Ease
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# @core-ease/telegram-kit
|
|
2
|
+
|
|
3
|
+
A complete toolkit for building on top of Telegram: Mini Apps SDK (React hooks + a provider), a Bot API client for the server, a zero-dependency `.tgs`/Lottie sticker player, a standards-compliant QR code encoder, and small utilities for Markdown/HTML formatting, deep links, and keyboards.
|
|
4
|
+
|
|
5
|
+
It's framework-agnostic where it can be — plain JS, Node, or a `<script>` tag all work — and gives you React bindings where that actually helps (Mini Apps hooks, the sticker player, the QR component).
|
|
6
|
+
|
|
7
|
+
## Why this exists
|
|
8
|
+
|
|
9
|
+
Telegram Mini Apps and Bot API projects usually end up gluing together the same handful of things: reading `window.Telegram.WebApp`, validating `initData` on the server, building inline keyboards by hand, escaping MarkdownV2, and so on. `@core-ease/telegram-kit` bundles all of that behind a typed, documented API - with a real, working fallback for every feature when your Mini App is opened outside Telegram - so you don't have to rebuild it for every project.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @core-ease/telegram-kit
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
React is an optional peer dependency — you only need it if you use the hooks, the provider, or the sticker/QR components. Everything else (bot client, QR encoding, formatting, links, server-side validation) works in plain Node or the browser with no React involved.
|
|
18
|
+
|
|
19
|
+
## Package structure
|
|
20
|
+
|
|
21
|
+
The source is organized by what the code *does*, not by which npm subpath exports it:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
src/
|
|
25
|
+
sdk/ The full Mini Apps SDK: a faithful, modular TypeScript port of
|
|
26
|
+
Telegram's official telegram-web-app.js (no CDN fetch, ever).
|
|
27
|
+
Public entry: sdk/index.ts. Everything else lives under
|
|
28
|
+
sdk/_internal/ (transport, kernel, theme, ui, features, sensors)
|
|
29
|
+
and is an implementation detail - see sdk/README.md.
|
|
30
|
+
core/ Telegram WebApp runtime access (getWebApp, haptics, storages,
|
|
31
|
+
dialogs, location, biometrics, ...) - every function here gets
|
|
32
|
+
the WebApp instance directly from ../sdk (never from
|
|
33
|
+
window.Telegram) and has a real browser-native fallback for
|
|
34
|
+
when the Mini App is opened outside Telegram. See
|
|
35
|
+
core/fallback.ts for the fallback implementations and
|
|
36
|
+
core/dev.ts for dev/local-testing mode.
|
|
37
|
+
react/ Hooks and the TelegramProvider for React-based Mini Apps -
|
|
38
|
+
every hook delegates to core/ rather than re-implementing
|
|
39
|
+
its own copy of the same logic
|
|
40
|
+
ui/ QR code generation/rendering and the Lottie/TGS sticker players
|
|
41
|
+
utils/ MarkdownV2/HTML formatting, deep links, inline & reply keyboards
|
|
42
|
+
bot/ The Bot API client, update dispatcher, and long-polling helper
|
|
43
|
+
types/ Shared TypeScript types for the WebApp and the Bot API - the
|
|
44
|
+
WebApp types are thin re-exports of the real ../sdk types
|
|
45
|
+
instead of a hand-maintained parallel copy
|
|
46
|
+
_internal/ Implementation details (QR encoding math, the Lottie rendering
|
|
47
|
+
engine, gzip inflate, HMAC verification, etc.) — not part of the
|
|
48
|
+
public API and can change without notice
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
None of this affects how you import the package — see the sections below for that. It's just how the codebase itself is laid out, in case you're browsing the source or opening a PR.
|
|
52
|
+
|
|
53
|
+
## Quick start — Mini App (React)
|
|
54
|
+
|
|
55
|
+
Wrap your app once:
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { TelegramProvider, useTelegram } from '@core-ease/telegram-kit';
|
|
60
|
+
|
|
61
|
+
function App() {
|
|
62
|
+
return (
|
|
63
|
+
<TelegramProvider options={{ autoExpand: true }}>
|
|
64
|
+
<Home />
|
|
65
|
+
</TelegramProvider>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function Home() {
|
|
70
|
+
const { user, colorScheme, inTelegram } = useTelegram();
|
|
71
|
+
|
|
72
|
+
if (!inTelegram) return <p>Open this from a Telegram chat.</p>;
|
|
73
|
+
|
|
74
|
+
return <p>Hey {user?.first_name}, you're on {colorScheme} mode.</p>;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`TelegramProvider` calls `WebApp.ready()`, expands the window, reads the current user, and tracks the color scheme for you. `options` also accepts `onReady`, `onUserReady`, `loadingComponent`, `notInTelegramComponent`, `allowOutsideTelegram`, `autoDisableVerticalSwipes`, and `autoEnableClosingConfirmation`.
|
|
79
|
+
|
|
80
|
+
From there, the hooks cover most of the WebApp surface:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import {
|
|
84
|
+
useTelegramMainButton,
|
|
85
|
+
useTelegramBackButton,
|
|
86
|
+
useHapticFeedback,
|
|
87
|
+
useShowConfirm,
|
|
88
|
+
useCloudStorage,
|
|
89
|
+
} from '@core-ease/telegram-kit';
|
|
90
|
+
|
|
91
|
+
function CheckoutButton() {
|
|
92
|
+
const haptic = useHapticFeedback();
|
|
93
|
+
const confirm = useShowConfirm();
|
|
94
|
+
|
|
95
|
+
useTelegramMainButton({
|
|
96
|
+
text: 'Confirm order',
|
|
97
|
+
onClick: async () => {
|
|
98
|
+
if (await confirm('Place this order?')) {
|
|
99
|
+
haptic.notification('success');
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
There are around 40 hooks in total — main/back/settings buttons, cloud/device/secure storage, biometrics, accelerometer/gyroscope, viewport and safe-area, fullscreen, theme, clipboard, QR scanning, and more. They're all exported from the package root, so your editor's autocomplete is the fastest way to browse them.
|
|
109
|
+
|
|
110
|
+
## Core (no React required)
|
|
111
|
+
|
|
112
|
+
Everything the hooks are built on is also available directly, for vanilla JS, Vue, or anywhere else:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { getWebApp, isInTelegram, haptic, cloudStorage, dialog } from '@core-ease/telegram-kit';
|
|
116
|
+
|
|
117
|
+
if (isInTelegram()) {
|
|
118
|
+
await dialog.showConfirm('Continue?');
|
|
119
|
+
await cloudStorage.setItem('draft', JSON.stringify(formState));
|
|
120
|
+
haptic.impact('medium');
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
This module also has `openTelegramLink`, `openInvoice`, `shareToStory`, `requestContact`, `scanQr`, `downloadFile`, `getUserDisplayName`, `getUserAvatarUrl`, and the rest of the WebApp surface as plain functions.
|
|
125
|
+
|
|
126
|
+
## Bot API (server-side)
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { TelegramBot, Dispatcher, TelegramPoller } from '@core-ease/telegram-kit/bot';
|
|
130
|
+
|
|
131
|
+
const bot = new TelegramBot({ token: process.env.BOT_TOKEN! });
|
|
132
|
+
|
|
133
|
+
const dispatcher = new Dispatcher()
|
|
134
|
+
.onCommand('start', (msg) => bot.sendMessage({ chat_id: msg.chat.id, text: 'Welcome!' }))
|
|
135
|
+
.onMessage((msg) => bot.sendMessage({ chat_id: msg.chat.id, text: `You said: ${msg.text}` }));
|
|
136
|
+
|
|
137
|
+
const poller = new TelegramPoller(
|
|
138
|
+
(params) => bot.getUpdates(params),
|
|
139
|
+
dispatcher.toHandler()
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
poller.start();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`TelegramBot` covers the Bot API methods (`sendMessage`, `sendPhoto`, `editMessageText`, `answerCallbackQuery`, `setWebhook`, and so on) with typed params and typed responses, and throws a `TelegramApiError` (with `errorCode` and `description`) when the API rejects a call. If you'd rather run a webhook than long polling, call `dispatcher.toHandler()(update)` from your HTTP handler instead of using `TelegramPoller`.
|
|
146
|
+
|
|
147
|
+
## Verifying `initData` on the server
|
|
148
|
+
|
|
149
|
+
Never trust `initData` on the client — always verify it server-side before treating it as an authenticated user:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import { validateInitData } from '@core-ease/telegram-kit/server';
|
|
153
|
+
|
|
154
|
+
const result = await validateInitData(initDataFromClient, process.env.BOT_TOKEN!, {
|
|
155
|
+
maxAgeSeconds: 3600,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
if (!result.valid) {
|
|
159
|
+
// result.reason: 'invalid_hash' | 'expired' | 'missing_hash' | 'malformed'
|
|
160
|
+
throw new Error('Invalid Telegram session');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// result.user, result.startParam, result.authDate are ready to use
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
There's also a synchronous `validateInitDataSync` if you're not in an async context — same options, same result shape.
|
|
167
|
+
|
|
168
|
+
## QR codes
|
|
169
|
+
|
|
170
|
+
A zero-dependency ISO/IEC 18004 encoder plus a styled React component:
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
import { QRCode, encodeQRCode, qrCodeToSVG } from '@core-ease/telegram-kit/qr';
|
|
174
|
+
|
|
175
|
+
// as a component
|
|
176
|
+
<QRCode value="https://t.me/your_bot" size={256} dotColor="#111" logo="/logo.png" />
|
|
177
|
+
|
|
178
|
+
// or just get raw SVG / matrix data, no React needed
|
|
179
|
+
const svg = qrCodeToSVG('https://t.me/your_bot', { size: 512, color: '#000' });
|
|
180
|
+
const { modules } = encodeQRCode('https://t.me/your_bot', { errorCorrectionLevel: 'M' });
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`QRCode` supports custom dot/corner shapes, a logo with automatic size clamping so it never breaks scannability, rounded corners, and a `downloadQRCode(svgRef.current, { format: 'png' | 'svg' })` helper for exporting it.
|
|
184
|
+
|
|
185
|
+
## Animated stickers (TGS / Lottie)
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
import { TgsPlayer } from '@core-ease/telegram-kit/tgs';
|
|
189
|
+
|
|
190
|
+
<TgsPlayer src="/stickers/wave.tgs" autoplay loop style={{ width: 128, height: 128 }} />
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`TgsPlayer` validates that the file is actually a Telegram-compliant animated sticker (set `strict={false}` to skip that check). If you're rendering a plain Lottie JSON animation instead of a `.tgs` file, use `LottiePlayer` from `@core-ease/telegram-kit/lottie` — same props, no TGS validation. Both are also reachable from `@core-ease/telegram-kit/animation`.
|
|
194
|
+
|
|
195
|
+
## Formatting messages (MarkdownV2 / HTML)
|
|
196
|
+
|
|
197
|
+
Hand-escaping MarkdownV2 is a common source of bugs (it has more reserved characters than people expect). This builds the string for you instead:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
import { md, html } from '@core-ease/telegram-kit/format';
|
|
201
|
+
|
|
202
|
+
const text = md.text('Hello ', md.bold(user.first_name), '! Your order ', md.code(orderId), ' is ready.');
|
|
203
|
+
await bot.sendMessage({ chat_id, text: text.toString(), parse_mode: 'MarkdownV2' });
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Both `md` and `html` support `bold`, `italic`, `underline`, `strikethrough`, `spoiler`, `code`, `pre`, `link`, `mentionUser`, and `customEmoji`; `html` additionally has `blockquote` and `expandableBlockquote`. Everything you pass in is escaped automatically unless it's already a formatted fragment, so nesting `md.bold(md.italic('x'))` works as expected. `TELEGRAM_TEXT_LIMITS` and `truncateText` are there for staying under Telegram's length limits (surrogate-pair-safe).
|
|
207
|
+
|
|
208
|
+
## Deep links
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { buildStartLink, buildStartAppLink, parseTelegramLink } from '@core-ease/telegram-kit/links';
|
|
212
|
+
|
|
213
|
+
buildStartLink({ botUsername: 'your_bot', data: 'ref_42' });
|
|
214
|
+
// -> https://t.me/your_bot?start=cmVmXzQy
|
|
215
|
+
|
|
216
|
+
buildStartAppLink({ botUsername: 'your_bot', appName: 'shop', startParam: 'sku_123' });
|
|
217
|
+
// -> https://t.me/your_bot/shop?startapp=sku_123
|
|
218
|
+
|
|
219
|
+
parseTelegramLink('https://t.me/your_bot/shop?startapp=sku_123');
|
|
220
|
+
// -> { type: 'mini-app', username: 'your_bot', appName: 'shop', startParam: 'sku_123' }
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
`start`/`startapp` parameters only allow `A-Z a-z 0-9 _ -` and 64 characters max — pass `data` and it gets base64url-encoded for you; pass `startParam` directly if it's already a valid short slug.
|
|
224
|
+
|
|
225
|
+
## Keyboards
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import { InlineKeyboardBuilder, ReplyKeyboardBuilder } from '@core-ease/telegram-kit/keyboards';
|
|
229
|
+
|
|
230
|
+
const keyboard = new InlineKeyboardBuilder()
|
|
231
|
+
.text('Yes', 'confirm:yes').text('No', 'confirm:no')
|
|
232
|
+
.row()
|
|
233
|
+
.url('Docs', 'https://example.com')
|
|
234
|
+
.build();
|
|
235
|
+
|
|
236
|
+
await bot.sendMessage({ chat_id, text: 'Confirm?', reply_markup: keyboard });
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
`InlineKeyboardBuilder.columns(buttons, perRow)` is a shortcut for grid layouts. `removeKeyboard()` and `forceReply()` cover the remaining reply-markup types.
|
|
240
|
+
|
|
241
|
+
## Developing outside Telegram
|
|
242
|
+
|
|
243
|
+
`WebApp` doesn't exist outside a Telegram client, which makes local development painful. Even without calling `installDevMode()`, every `@core-ease/telegram-kit` function already degrades to a real browser-native equivalent (see `core/fallback.ts`) - so hooks and core functions work in a regular browser tab out of the box. `installDevMode()` goes one step further and seeds a fake user/theme/session, so `getWebApp().initDataUnsafe.user`, the theme, and `isInTelegram()` all behave like a real launch too:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
import { installDevMode } from '@core-ease/telegram-kit/dev';
|
|
247
|
+
|
|
248
|
+
// Call this before anything else touches getWebApp() - hooks, <TelegramProvider>,
|
|
249
|
+
// or any core/index.ts function. It seeds a fake user/theme/session through the
|
|
250
|
+
// exact same code path a real Telegram launch uses, so every feature (storage,
|
|
251
|
+
// haptics, dialogs, location, ...) keeps working through its browser-native
|
|
252
|
+
// fallback instead of hanging or warning.
|
|
253
|
+
if (process.env.NODE_ENV === 'development') {
|
|
254
|
+
installDevMode({ user: { id: 1, first_name: 'Dev' } });
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Don't ship this in production — gate it behind an environment check like above.
|
|
259
|
+
|
|
260
|
+
## Using it without a bundler
|
|
261
|
+
|
|
262
|
+
There's also a plain browser build that exposes everything under a `TelegramKit` global. It bundles the full Mini Apps SDK itself, so **no external `telegram.org` script tag is needed**:
|
|
263
|
+
|
|
264
|
+
```html
|
|
265
|
+
<script src="https://unpkg.com/@core-ease/telegram-kit/dist/browser.global.js"></script>
|
|
266
|
+
<script>
|
|
267
|
+
const { encodeQRCode, buildStartLink, isInTelegram, getWebApp } = TelegramKit;
|
|
268
|
+
console.log(getWebApp()?.platform);
|
|
269
|
+
</script>
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
This build includes core, QR, formatting, links, keyboards, dev mode, and the bundled Mini Apps SDK - not the React-dependent pieces, since there's no React in a plain `<script>` context.
|
|
273
|
+
|
|
274
|
+
## The bundled Mini Apps SDK
|
|
275
|
+
|
|
276
|
+
`@core-ease/telegram-kit` used to be a thin *type* wrapper around Telegram's own `https://telegram.org/js/telegram-web-app.js`, which you had to load yourself via a `<script>` tag. That script is now vendored in full, as a faithful line-for-line behavioral TypeScript port, under `@core-ease/telegram-kit/sdk` (source: `src/sdk/`, public entry `src/sdk/index.ts`, implementation under `src/sdk/_internal/`).
|
|
277
|
+
|
|
278
|
+
Practically, this means:
|
|
279
|
+
|
|
280
|
+
- **No CDN dependency, ever.** Just `import '@core-ease/telegram-kit'` (or `/core`, or `/hooks`) and the first call to `getWebApp()` - which every hook and core function makes for you - sets up `window.Telegram.WebApp` locally. Nothing is fetched over the network, and nothing runs eagerly just from importing the package (SSR-safe).
|
|
281
|
+
- **`core/`, `react/hooks.ts`, and `<TelegramProvider>` all read the SDK directly** - `getWebApp()` in `core/index.ts` gets the `WebApp` instance from `../sdk`'s `bootstrapTelegramWebApp()`, never from `window.Telegram`. Every hook delegates to `core/` instead of re-implementing its own copy of the same call.
|
|
282
|
+
- **Every feature has a real browser fallback.** Opened outside Telegram (or in dev mode, or against an older client), storage falls back to `localStorage`, haptics to `navigator.vibrate`, location to `navigator.geolocation`, clipboard to `navigator.clipboard`, file downloads to a plain `<a download>`, dialogs to `window.alert/confirm/prompt`, fullscreen/orientation to the standard Fullscreen/Screen Orientation APIs, and sharing to the Web Share API - see `src/core/fallback.ts`. Calls that have no meaningful browser equivalent (biometrics, emoji status, Telegram-account actions, ...) resolve predictably instead of hanging or rejecting with a console warning.
|
|
283
|
+
- **Every native event, version gate, and validation rule** from the official script is preserved exactly in the SDK layer itself - see `src/sdk/README.md` for the module-by-module breakdown and fidelity notes.
|
|
284
|
+
- **Advanced use:** if you want the typed SDK classes directly instead of going through `core/`, import from `@core-ease/telegram-kit/sdk`:
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
import { bootstrapTelegramWebApp } from '@core-ease/telegram-kit/sdk';
|
|
288
|
+
|
|
289
|
+
const { webApp } = bootstrapTelegramWebApp();
|
|
290
|
+
webApp.MainButton.setText('Continue').show();
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## TypeScript
|
|
294
|
+
|
|
295
|
+
Everything is written in TypeScript and ships its own `.d.ts` files — no `@types` package needed. The full Bot API type surface (`Message`, `Update`, `InlineKeyboardMarkup`, every `SendXParams` type, etc.) is exported from `@core-ease/telegram-kit/bot` and `@core-ease/telegram-kit` directly.
|
|
296
|
+
|
|
297
|
+
## License
|
|
298
|
+
|
|
299
|
+
MIT
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { LottiePlayer, LottiePlayerHandle, LottiePlayerProps } from './lottie/index.mjs';
|
|
2
|
+
export { TgsPlayer, TgsPlayerHandle, TgsPlayerProps, checkTgsCompliance, gunzip, isGzip } from './tgs/index.mjs';
|
|
3
|
+
export { L as LottieAnimation, a as LottieAnimationController, T as LottieSource, P as PlayMode, b as PlayerState, L as TgsAnimation, a as TgsAnimationController, P as TgsPlayMode, b as TgsPlayerState, T as TgsSource, l as loadLottieSource, l as loadTgsSource, r as renderDocumentFrame, r as renderTgsDocumentFrame } from '../engine-BDm1_hzn.mjs';
|
|
4
|
+
import 'react';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { LottiePlayer, LottiePlayerHandle, LottiePlayerProps } from './lottie/index.js';
|
|
2
|
+
export { TgsPlayer, TgsPlayerHandle, TgsPlayerProps, checkTgsCompliance, gunzip, isGzip } from './tgs/index.js';
|
|
3
|
+
export { L as LottieAnimation, a as LottieAnimationController, T as LottieSource, P as PlayMode, b as PlayerState, L as TgsAnimation, a as TgsAnimationController, P as TgsPlayMode, b as TgsPlayerState, T as TgsSource, l as loadLottieSource, l as loadTgsSource, r as renderDocumentFrame, r as renderTgsDocumentFrame } from '../engine-BDm1_hzn.js';
|
|
4
|
+
import 'react';
|