@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/dist/index.mjs
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { getWebApp, isInTelegram, expand, disableVerticalSwipes, enableClosingConfirmation, ready, setHeaderColor, setBackgroundColor, setBottomBarColor } from './chunk-B3PWALX5.mjs';
|
|
3
|
+
export { addToHomeScreen, biometric, bootstrapTelegramWebApp, checkHomeScreenStatus, close, cloudStorage, deviceStorage, dialog, disableClosingConfirmation, disableVerticalSwipes, downloadFile, enableClosingConfirmation, enableVerticalSwipes, expand, fullscreen, getRawUserData, getTheme, getUserAvatarUrl, getUserDisplayName, getUserIdentifier, getUserInfoWithAvatar, getViewport, getWebApp, haptic, hideKeyboard, invokeCustomMethod, isInTelegram, isVersionAtLeast, location, openExternalLink, openInvoice, openTelegramLink, orientation, readClipboard, ready, requestChat, requestContact, requestEmojiStatusAccess, requestWriteAccess, safeInvoke, scanQr, sdk_exports as sdk, secureStorage, setBackgroundColor, setBottomBarColor, setEmojiStatus, setHeaderColor, shareMessage, shareToStory, switchInlineQuery, useAccelerometer, useBiometric, useCloudStorage, useDeviceOrientation, useDeviceStorage, useDownloadFile, useGyroscope, useHapticFeedback, useHideKeyboard, useHomeScreen, useInitData, useInvokeCustomMethod, useIsActive, useLocation, useOrientationLock, useReadTextFromClipboard, useReady, useRequestChat, useRequestContact, useRequestEmojiStatusAccess, useRequestWriteAccess, useSafeArea, useScanQrPopup, useSecureStorage, useSetEmojiStatus, useShareMessage, useShareToStory, useShowAlert, useShowConfirm, useShowPopup, useSwitchInlineQuery, useTelegramBackButton, useTelegramEvent, useTelegramFullscreen, useTelegramMainButton, useTelegramSecondaryButton, useTelegramSettingsButton, useTelegramStartParam, useTelegramTheme, useTelegramUser, useTelegramViewport, useTelegramWebApp } from './chunk-B3PWALX5.mjs';
|
|
4
|
+
import { __spreadProps, __spreadValues } from './chunk-PXO36YTU.mjs';
|
|
5
|
+
import { createContext, useContext, useRef, useEffect, useState, useLayoutEffect } from 'react';
|
|
6
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
// src/core/dev.ts
|
|
9
|
+
function isDevMode() {
|
|
10
|
+
var _a;
|
|
11
|
+
if (typeof window === "undefined") return false;
|
|
12
|
+
return typeof process !== "undefined" && ((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "development" || new URLSearchParams(window.location.search).has("tg_dev");
|
|
13
|
+
}
|
|
14
|
+
var defaultCtx = {
|
|
15
|
+
ready: false,
|
|
16
|
+
inTelegram: false,
|
|
17
|
+
isDevBypass: false,
|
|
18
|
+
webApp: null,
|
|
19
|
+
user: null,
|
|
20
|
+
colorScheme: "dark",
|
|
21
|
+
startParam: null
|
|
22
|
+
};
|
|
23
|
+
var TelegramContext = createContext(defaultCtx);
|
|
24
|
+
function useTelegram() {
|
|
25
|
+
return useContext(TelegramContext);
|
|
26
|
+
}
|
|
27
|
+
function applyColorScheme(scheme) {
|
|
28
|
+
if (typeof document === "undefined") return;
|
|
29
|
+
if (scheme === "dark") {
|
|
30
|
+
document.documentElement.classList.add("dark");
|
|
31
|
+
} else {
|
|
32
|
+
document.documentElement.classList.remove("dark");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function TelegramProvider({
|
|
36
|
+
children,
|
|
37
|
+
options = {}
|
|
38
|
+
}) {
|
|
39
|
+
const {
|
|
40
|
+
onUserReady,
|
|
41
|
+
onReady,
|
|
42
|
+
loadingComponent = null,
|
|
43
|
+
notInTelegramComponent = null,
|
|
44
|
+
allowOutsideTelegram = false,
|
|
45
|
+
autoExpand = true,
|
|
46
|
+
autoDisableVerticalSwipes = true,
|
|
47
|
+
autoEnableClosingConfirmation = false,
|
|
48
|
+
headerColor,
|
|
49
|
+
backgroundColor,
|
|
50
|
+
bottomBarColor
|
|
51
|
+
} = options;
|
|
52
|
+
const onUserReadyRef = useRef(onUserReady);
|
|
53
|
+
const onReadyRef = useRef(onReady);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
onUserReadyRef.current = onUserReady;
|
|
56
|
+
});
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
onReadyRef.current = onReady;
|
|
59
|
+
});
|
|
60
|
+
const [isInitialized, setIsInitialized] = useState(false);
|
|
61
|
+
const [ctx, setCtx] = useState(defaultCtx);
|
|
62
|
+
useLayoutEffect(() => {
|
|
63
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
64
|
+
const wa = getWebApp();
|
|
65
|
+
const inTg = isInTelegram();
|
|
66
|
+
const devBypass = !inTg && isDevMode();
|
|
67
|
+
let user = null;
|
|
68
|
+
let startParam = null;
|
|
69
|
+
let colorScheme = "dark";
|
|
70
|
+
if (wa) {
|
|
71
|
+
if (autoExpand) expand();
|
|
72
|
+
if (autoDisableVerticalSwipes) disableVerticalSwipes();
|
|
73
|
+
if (autoEnableClosingConfirmation) enableClosingConfirmation();
|
|
74
|
+
colorScheme = (_a = wa.colorScheme) != null ? _a : "dark";
|
|
75
|
+
user = (_c = (_b = wa.initDataUnsafe) == null ? void 0 : _b.user) != null ? _c : null;
|
|
76
|
+
startParam = (_e = (_d = wa.initDataUnsafe) == null ? void 0 : _d.start_param) != null ? _e : null;
|
|
77
|
+
if (user) (_f = onUserReadyRef.current) == null ? void 0 : _f.call(onUserReadyRef, user);
|
|
78
|
+
(_g = onReadyRef.current) == null ? void 0 : _g.call(onReadyRef, wa);
|
|
79
|
+
}
|
|
80
|
+
applyColorScheme(colorScheme);
|
|
81
|
+
setCtx({
|
|
82
|
+
ready: true,
|
|
83
|
+
inTelegram: inTg,
|
|
84
|
+
isDevBypass: devBypass,
|
|
85
|
+
webApp: wa,
|
|
86
|
+
user,
|
|
87
|
+
colorScheme,
|
|
88
|
+
startParam
|
|
89
|
+
});
|
|
90
|
+
setIsInitialized(true);
|
|
91
|
+
ready();
|
|
92
|
+
}, [autoExpand, autoDisableVerticalSwipes, autoEnableClosingConfirmation]);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!ctx.ready) return;
|
|
95
|
+
if (headerColor) setHeaderColor(headerColor);
|
|
96
|
+
if (backgroundColor) setBackgroundColor(backgroundColor);
|
|
97
|
+
if (bottomBarColor) setBottomBarColor(bottomBarColor);
|
|
98
|
+
}, [ctx.ready, headerColor, backgroundColor, bottomBarColor]);
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
const wa = ctx.webApp;
|
|
101
|
+
if (!wa) return;
|
|
102
|
+
const handleThemeChanged = () => {
|
|
103
|
+
var _a;
|
|
104
|
+
const scheme = (_a = wa.colorScheme) != null ? _a : "dark";
|
|
105
|
+
applyColorScheme(scheme);
|
|
106
|
+
setCtx((prev) => prev.colorScheme === scheme ? prev : __spreadProps(__spreadValues({}, prev), { colorScheme: scheme }));
|
|
107
|
+
};
|
|
108
|
+
wa.onEvent("themeChanged", handleThemeChanged);
|
|
109
|
+
return () => wa.offEvent("themeChanged", handleThemeChanged);
|
|
110
|
+
}, [ctx.webApp]);
|
|
111
|
+
if (!isInitialized) return /* @__PURE__ */ jsx(Fragment, { children: loadingComponent });
|
|
112
|
+
if (ctx.ready && !ctx.inTelegram && !ctx.isDevBypass && !allowOutsideTelegram) {
|
|
113
|
+
return /* @__PURE__ */ jsx(Fragment, { children: notInTelegramComponent });
|
|
114
|
+
}
|
|
115
|
+
return /* @__PURE__ */ jsx(TelegramContext.Provider, { value: ctx, children });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/utils/format.ts
|
|
119
|
+
var TelegramFormattedText = class {
|
|
120
|
+
constructor(raw) {
|
|
121
|
+
this.raw = raw;
|
|
122
|
+
}
|
|
123
|
+
toString() {
|
|
124
|
+
return this.raw;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
function isFragment(part) {
|
|
128
|
+
return part instanceof TelegramFormattedText;
|
|
129
|
+
}
|
|
130
|
+
function joinParts(parts, escape) {
|
|
131
|
+
return parts.map((part) => isFragment(part) ? part.raw : escape(part)).join("");
|
|
132
|
+
}
|
|
133
|
+
var MARKDOWN_V2_RESERVED = /[_*[\]()~`>#+\-=|{}.!\\]/g;
|
|
134
|
+
var MARKDOWN_V2_CODE_RESERVED = /[`\\]/g;
|
|
135
|
+
var MARKDOWN_V2_LINK_URL_RESERVED = /[)\\]/g;
|
|
136
|
+
function escapeMarkdownV2(text) {
|
|
137
|
+
return text.replace(MARKDOWN_V2_RESERVED, (ch) => `\\${ch}`);
|
|
138
|
+
}
|
|
139
|
+
function escapeMarkdownV2Code(text) {
|
|
140
|
+
return text.replace(MARKDOWN_V2_CODE_RESERVED, (ch) => `\\${ch}`);
|
|
141
|
+
}
|
|
142
|
+
function escapeMarkdownV2LinkUrl(url) {
|
|
143
|
+
return url.replace(MARKDOWN_V2_LINK_URL_RESERVED, (ch) => `\\${ch}`);
|
|
144
|
+
}
|
|
145
|
+
function createMarkdownV2Formatter() {
|
|
146
|
+
const wrap = (raw) => new TelegramFormattedText(raw);
|
|
147
|
+
const t = (parts) => joinParts(parts, escapeMarkdownV2);
|
|
148
|
+
return {
|
|
149
|
+
escape: escapeMarkdownV2,
|
|
150
|
+
escapeCode: escapeMarkdownV2Code,
|
|
151
|
+
escapeLinkUrl: escapeMarkdownV2LinkUrl,
|
|
152
|
+
text: (...parts) => wrap(t(parts)),
|
|
153
|
+
bold: (...parts) => wrap(`*${t(parts)}*`),
|
|
154
|
+
italic: (...parts) => wrap(`_${t(parts)}_`),
|
|
155
|
+
underline: (...parts) => wrap(`__${t(parts)}__`),
|
|
156
|
+
strikethrough: (...parts) => wrap(`~${t(parts)}~`),
|
|
157
|
+
spoiler: (...parts) => wrap(`||${t(parts)}||`),
|
|
158
|
+
code: (text) => wrap(`\`${escapeMarkdownV2Code(text)}\``),
|
|
159
|
+
pre: (text, language) => wrap(`\`\`\`${language != null ? language : ""}
|
|
160
|
+
${escapeMarkdownV2Code(text)}
|
|
161
|
+
\`\`\``),
|
|
162
|
+
link: (url, ...parts) => wrap(`[${t(parts)}](${escapeMarkdownV2LinkUrl(url)})`),
|
|
163
|
+
mentionUser: (userId, ...parts) => wrap(`[${t(parts)}](tg://user?id=${userId})`),
|
|
164
|
+
customEmoji: (emojiId, fallbackEmoji) => wrap(``),
|
|
165
|
+
raw: (raw) => wrap(raw)
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function escapeHTML(text) {
|
|
169
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
170
|
+
}
|
|
171
|
+
function escapeHTMLAttribute(text) {
|
|
172
|
+
return escapeHTML(text).replace(/"/g, """);
|
|
173
|
+
}
|
|
174
|
+
function createHtmlFormatter() {
|
|
175
|
+
const wrap = (raw) => new TelegramFormattedText(raw);
|
|
176
|
+
const t = (parts) => joinParts(parts, escapeHTML);
|
|
177
|
+
return {
|
|
178
|
+
escape: escapeHTML,
|
|
179
|
+
escapeAttribute: escapeHTMLAttribute,
|
|
180
|
+
text: (...parts) => wrap(t(parts)),
|
|
181
|
+
bold: (...parts) => wrap(`<b>${t(parts)}</b>`),
|
|
182
|
+
italic: (...parts) => wrap(`<i>${t(parts)}</i>`),
|
|
183
|
+
underline: (...parts) => wrap(`<u>${t(parts)}</u>`),
|
|
184
|
+
strikethrough: (...parts) => wrap(`<s>${t(parts)}</s>`),
|
|
185
|
+
spoiler: (...parts) => wrap(`<tg-spoiler>${t(parts)}</tg-spoiler>`),
|
|
186
|
+
code: (text) => wrap(`<code>${escapeHTML(text)}</code>`),
|
|
187
|
+
pre: (text, language) => wrap(
|
|
188
|
+
language ? `<pre><code class="language-${escapeHTMLAttribute(language)}">${escapeHTML(text)}</code></pre>` : `<pre>${escapeHTML(text)}</pre>`
|
|
189
|
+
),
|
|
190
|
+
link: (url, ...parts) => wrap(`<a href="${escapeHTMLAttribute(url)}">${t(parts)}</a>`),
|
|
191
|
+
mentionUser: (userId, ...parts) => wrap(`<a href="tg://user?id=${userId}">${t(parts)}</a>`),
|
|
192
|
+
blockquote: (...parts) => wrap(`<blockquote>${t(parts)}</blockquote>`),
|
|
193
|
+
expandableBlockquote: (...parts) => wrap(`<blockquote expandable>${t(parts)}</blockquote>`),
|
|
194
|
+
customEmoji: (emojiId, fallbackEmoji) => wrap(`<tg-emoji emoji-id="${escapeHTMLAttribute(emojiId)}">${escapeHTML(fallbackEmoji)}</tg-emoji>`),
|
|
195
|
+
raw: (rawHtml) => wrap(rawHtml)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
var md = createMarkdownV2Formatter();
|
|
199
|
+
var html = createHtmlFormatter();
|
|
200
|
+
var TELEGRAM_TEXT_LIMITS = {
|
|
201
|
+
MESSAGE: 4096,
|
|
202
|
+
CAPTION: 1024,
|
|
203
|
+
BUTTON_TEXT: 64,
|
|
204
|
+
CALLBACK_DATA: 64,
|
|
205
|
+
START_PARAMETER: 64,
|
|
206
|
+
BOT_DESCRIPTION: 512,
|
|
207
|
+
BOT_SHORT_DESCRIPTION: 120,
|
|
208
|
+
CHAT_TITLE: 128,
|
|
209
|
+
POLL_QUESTION: 300,
|
|
210
|
+
POLL_OPTION: 100
|
|
211
|
+
};
|
|
212
|
+
function isHighSurrogate(code) {
|
|
213
|
+
return code >= 55296 && code <= 56319;
|
|
214
|
+
}
|
|
215
|
+
function isLowSurrogate(code) {
|
|
216
|
+
return code >= 56320 && code <= 57343;
|
|
217
|
+
}
|
|
218
|
+
function truncateText(text, maxLength, ellipsis = "\u2026") {
|
|
219
|
+
if (text.length <= maxLength) return text;
|
|
220
|
+
let cut = Math.max(0, maxLength - ellipsis.length);
|
|
221
|
+
if (cut > 0 && isHighSurrogate(text.charCodeAt(cut - 1)) && isLowSurrogate(text.charCodeAt(cut))) {
|
|
222
|
+
cut -= 1;
|
|
223
|
+
}
|
|
224
|
+
return text.slice(0, cut) + ellipsis;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/utils/links.ts
|
|
228
|
+
function bytesToBase64Url(bytes) {
|
|
229
|
+
let binary = "";
|
|
230
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
231
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
232
|
+
}
|
|
233
|
+
function base64UrlToBytes(base64url) {
|
|
234
|
+
const base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
235
|
+
const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
|
|
236
|
+
const binary = atob(padded);
|
|
237
|
+
const bytes = new Uint8Array(binary.length);
|
|
238
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
239
|
+
return bytes;
|
|
240
|
+
}
|
|
241
|
+
var START_PARAM_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
242
|
+
function isValidStartParam(param) {
|
|
243
|
+
return START_PARAM_PATTERN.test(param);
|
|
244
|
+
}
|
|
245
|
+
function encodeStartParam(value) {
|
|
246
|
+
const encoded = bytesToBase64Url(new TextEncoder().encode(value));
|
|
247
|
+
if (encoded.length > 64) {
|
|
248
|
+
throw new Error(
|
|
249
|
+
`[@core-ease/telegram-kit] encodeStartParam: the encoded value is ${encoded.length} characters, exceeding Telegram's 64-character limit for start parameters. Pass a shorter payload (e.g. a numeric/short ID you look up server-side, instead of embedding full data).`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
return encoded;
|
|
253
|
+
}
|
|
254
|
+
function decodeStartParam(param) {
|
|
255
|
+
return new TextDecoder().decode(base64UrlToBytes(param));
|
|
256
|
+
}
|
|
257
|
+
function resolveStartParam(options) {
|
|
258
|
+
if (options.startParam !== void 0 && options.data !== void 0) {
|
|
259
|
+
throw new Error("[@core-ease/telegram-kit] Provide either `startParam` or `data`, not both.");
|
|
260
|
+
}
|
|
261
|
+
if (options.data !== void 0) return encodeStartParam(options.data);
|
|
262
|
+
if (options.startParam !== void 0) {
|
|
263
|
+
if (!isValidStartParam(options.startParam)) {
|
|
264
|
+
throw new Error(
|
|
265
|
+
`[@core-ease/telegram-kit] "${options.startParam}" is not a valid Telegram start parameter (allowed characters: A-Z a-z 0-9 _ -, max 64 chars). Use \`data\` instead to auto-encode arbitrary text.`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
return options.startParam;
|
|
269
|
+
}
|
|
270
|
+
return void 0;
|
|
271
|
+
}
|
|
272
|
+
function buildStartLink(options) {
|
|
273
|
+
const param = resolveStartParam(options);
|
|
274
|
+
const base = `https://t.me/${options.botUsername}`;
|
|
275
|
+
return param ? `${base}?start=${param}` : base;
|
|
276
|
+
}
|
|
277
|
+
function buildStartAppLink(options) {
|
|
278
|
+
const param = resolveStartParam(options);
|
|
279
|
+
const base = options.appName ? `https://t.me/${options.botUsername}/${options.appName}` : `https://t.me/${options.botUsername}`;
|
|
280
|
+
const query = new URLSearchParams();
|
|
281
|
+
if (param) query.set("startapp", param);
|
|
282
|
+
if (options.mode) query.set("mode", options.mode);
|
|
283
|
+
const queryString = query.toString();
|
|
284
|
+
return queryString ? `${base}?${queryString}` : base;
|
|
285
|
+
}
|
|
286
|
+
function buildShareLink(options) {
|
|
287
|
+
const query = new URLSearchParams({ url: options.url });
|
|
288
|
+
if (options.text) query.set("text", options.text);
|
|
289
|
+
return `https://t.me/share/url?${query.toString()}`;
|
|
290
|
+
}
|
|
291
|
+
var TME_HOSTNAMES = /* @__PURE__ */ new Set(["t.me", "telegram.me", "telegram.dog"]);
|
|
292
|
+
function parseTelegramLink(link) {
|
|
293
|
+
var _a, _b, _c, _d;
|
|
294
|
+
let url;
|
|
295
|
+
try {
|
|
296
|
+
url = new URL(link);
|
|
297
|
+
} catch (e) {
|
|
298
|
+
return { type: "unknown", url: link };
|
|
299
|
+
}
|
|
300
|
+
if (url.protocol === "tg:") {
|
|
301
|
+
const action = url.hostname || url.pathname.replace(/^\/+/, "");
|
|
302
|
+
if (action === "resolve") {
|
|
303
|
+
const domain = url.searchParams.get("domain");
|
|
304
|
+
const start2 = url.searchParams.get("start");
|
|
305
|
+
const startapp2 = url.searchParams.get("startapp");
|
|
306
|
+
const mode2 = (_a = url.searchParams.get("mode")) != null ? _a : void 0;
|
|
307
|
+
if (domain && start2) return { type: "bot-start", username: domain, startParam: start2 };
|
|
308
|
+
if (domain && startapp2 !== null) {
|
|
309
|
+
return { type: "mini-app", username: domain, startParam: startapp2 || void 0, mode: mode2 };
|
|
310
|
+
}
|
|
311
|
+
if (domain) return { type: "profile", username: domain };
|
|
312
|
+
}
|
|
313
|
+
if (action === "join") {
|
|
314
|
+
const invite = url.searchParams.get("invite");
|
|
315
|
+
if (invite) return { type: "join-chat", inviteHash: invite };
|
|
316
|
+
}
|
|
317
|
+
return { type: "unknown", url: link };
|
|
318
|
+
}
|
|
319
|
+
if (!TME_HOSTNAMES.has(url.hostname)) {
|
|
320
|
+
return { type: "unknown", url: link };
|
|
321
|
+
}
|
|
322
|
+
const segments = url.pathname.split("/").filter(Boolean);
|
|
323
|
+
if (segments.length === 0) return { type: "unknown", url: link };
|
|
324
|
+
if (segments[0].startsWith("+")) {
|
|
325
|
+
return { type: "join-chat", inviteHash: segments[0].slice(1) };
|
|
326
|
+
}
|
|
327
|
+
if (segments[0] === "joinchat" && segments[1]) {
|
|
328
|
+
return { type: "join-chat", inviteHash: segments[1] };
|
|
329
|
+
}
|
|
330
|
+
if (segments[0] === "share" && segments[1] === "url") {
|
|
331
|
+
return {
|
|
332
|
+
type: "share",
|
|
333
|
+
url: (_b = url.searchParams.get("url")) != null ? _b : void 0,
|
|
334
|
+
text: (_c = url.searchParams.get("text")) != null ? _c : void 0
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (segments[0] === "c" && segments[1] && segments[2]) {
|
|
338
|
+
const messageId = Number(segments[2]);
|
|
339
|
+
return { type: "private-channel-post", internalChatId: segments[1], messageId };
|
|
340
|
+
}
|
|
341
|
+
const username = segments[0];
|
|
342
|
+
const startapp = url.searchParams.get("startapp");
|
|
343
|
+
const start = url.searchParams.get("start");
|
|
344
|
+
const mode = (_d = url.searchParams.get("mode")) != null ? _d : void 0;
|
|
345
|
+
if (segments.length >= 2) {
|
|
346
|
+
return { type: "mini-app", username, appName: segments[1], startParam: startapp != null ? startapp : void 0, mode };
|
|
347
|
+
}
|
|
348
|
+
if (startapp !== null) {
|
|
349
|
+
return { type: "mini-app", username, startParam: startapp || void 0, mode };
|
|
350
|
+
}
|
|
351
|
+
if (start !== null) {
|
|
352
|
+
return { type: "bot-start", username, startParam: start };
|
|
353
|
+
}
|
|
354
|
+
return { type: "profile", username };
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// src/utils/keyboards.ts
|
|
358
|
+
var InlineKeyboardBuilder = class _InlineKeyboardBuilder {
|
|
359
|
+
constructor() {
|
|
360
|
+
this.rows = [[]];
|
|
361
|
+
}
|
|
362
|
+
currentRow() {
|
|
363
|
+
return this.rows[this.rows.length - 1];
|
|
364
|
+
}
|
|
365
|
+
add(button) {
|
|
366
|
+
this.currentRow().push(button);
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
text(text, callbackData) {
|
|
370
|
+
return this.add({ text, callback_data: callbackData });
|
|
371
|
+
}
|
|
372
|
+
url(text, url) {
|
|
373
|
+
return this.add({ text, url });
|
|
374
|
+
}
|
|
375
|
+
webApp(text, url) {
|
|
376
|
+
return this.add({ text, web_app: { url } });
|
|
377
|
+
}
|
|
378
|
+
login(text, loginUrl) {
|
|
379
|
+
return this.add({ text, login_url: typeof loginUrl === "string" ? { url: loginUrl } : loginUrl });
|
|
380
|
+
}
|
|
381
|
+
switchInline(text, query = "") {
|
|
382
|
+
return this.add({ text, switch_inline_query: query });
|
|
383
|
+
}
|
|
384
|
+
switchInlineCurrentChat(text, query = "") {
|
|
385
|
+
return this.add({ text, switch_inline_query_current_chat: query });
|
|
386
|
+
}
|
|
387
|
+
switchInlineChosenChat(text, query) {
|
|
388
|
+
return this.add({ text, switch_inline_query_chosen_chat: query != null ? query : {} });
|
|
389
|
+
}
|
|
390
|
+
copyText(text, copyText) {
|
|
391
|
+
return this.add({ text, copy_text: typeof copyText === "string" ? { text: copyText } : copyText });
|
|
392
|
+
}
|
|
393
|
+
pay(text = "Pay") {
|
|
394
|
+
return this.add({ text, pay: true });
|
|
395
|
+
}
|
|
396
|
+
callbackGame(text) {
|
|
397
|
+
return this.add({ text, callback_game: {} });
|
|
398
|
+
}
|
|
399
|
+
button(button) {
|
|
400
|
+
return this.add(button);
|
|
401
|
+
}
|
|
402
|
+
row() {
|
|
403
|
+
if (this.currentRow().length > 0) this.rows.push([]);
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
static columns(buttons, perRow) {
|
|
407
|
+
const builder = new _InlineKeyboardBuilder();
|
|
408
|
+
buttons.forEach((button, i) => {
|
|
409
|
+
if (i > 0 && i % perRow === 0) builder.row();
|
|
410
|
+
builder.button(button);
|
|
411
|
+
});
|
|
412
|
+
return builder;
|
|
413
|
+
}
|
|
414
|
+
build() {
|
|
415
|
+
const rows = this.rows.filter((row) => row.length > 0);
|
|
416
|
+
return { inline_keyboard: rows };
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
var ReplyKeyboardBuilder = class {
|
|
420
|
+
constructor() {
|
|
421
|
+
this.rows = [[]];
|
|
422
|
+
}
|
|
423
|
+
currentRow() {
|
|
424
|
+
return this.rows[this.rows.length - 1];
|
|
425
|
+
}
|
|
426
|
+
add(button) {
|
|
427
|
+
this.currentRow().push(button);
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
text(label) {
|
|
431
|
+
return this.add({ text: label });
|
|
432
|
+
}
|
|
433
|
+
requestContact(label) {
|
|
434
|
+
return this.add({ text: label, request_contact: true });
|
|
435
|
+
}
|
|
436
|
+
requestLocation(label) {
|
|
437
|
+
return this.add({ text: label, request_location: true });
|
|
438
|
+
}
|
|
439
|
+
requestPoll(label, type) {
|
|
440
|
+
return this.add({ text: label, request_poll: { type } });
|
|
441
|
+
}
|
|
442
|
+
webApp(label, url) {
|
|
443
|
+
return this.add({ text: label, web_app: { url } });
|
|
444
|
+
}
|
|
445
|
+
requestUsers(label, params) {
|
|
446
|
+
return this.add({ text: label, request_users: params });
|
|
447
|
+
}
|
|
448
|
+
requestChat(label, params) {
|
|
449
|
+
return this.add({ text: label, request_chat: params });
|
|
450
|
+
}
|
|
451
|
+
button(button) {
|
|
452
|
+
return this.add(button);
|
|
453
|
+
}
|
|
454
|
+
row() {
|
|
455
|
+
if (this.currentRow().length > 0) this.rows.push([]);
|
|
456
|
+
return this;
|
|
457
|
+
}
|
|
458
|
+
build(options = {}) {
|
|
459
|
+
var _a;
|
|
460
|
+
const rows = this.rows.filter((row) => row.length > 0);
|
|
461
|
+
return {
|
|
462
|
+
keyboard: rows,
|
|
463
|
+
resize_keyboard: (_a = options.resize) != null ? _a : true,
|
|
464
|
+
one_time_keyboard: options.oneTime,
|
|
465
|
+
selective: options.selective,
|
|
466
|
+
input_field_placeholder: options.placeholder,
|
|
467
|
+
is_persistent: options.persistent
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
function removeKeyboard(selective) {
|
|
472
|
+
return { remove_keyboard: true, selective };
|
|
473
|
+
}
|
|
474
|
+
function forceReply(options) {
|
|
475
|
+
return { force_reply: true, input_field_placeholder: options == null ? void 0 : options.placeholder, selective: options == null ? void 0 : options.selective };
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export { InlineKeyboardBuilder, ReplyKeyboardBuilder, TELEGRAM_TEXT_LIMITS, TelegramFormattedText, TelegramProvider, buildShareLink, buildStartAppLink, buildStartLink, decodeStartParam, encodeStartParam, escapeHTML, escapeHTMLAttribute, escapeMarkdownV2, escapeMarkdownV2Code, escapeMarkdownV2LinkUrl, forceReply, html, isValidStartParam, md, parseTelegramLink, removeKeyboard, truncateText, useTelegram };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { bS as LoginUrl, ct as SwitchInlineQueryChosenChat, cu as CopyTextButton, bG as InlineKeyboardButton, bH as InlineKeyboardMarkup, cv as KeyboardButtonPollType, cw as KeyboardButtonRequestUsers, cx as KeyboardButtonRequestChat, bO as KeyboardButton, c2 as ReplyKeyboardMarkup, bt as ForceReply, c3 as ReplyKeyboardRemove } from '../bot-D8BnLWIi.mjs';
|
|
2
|
+
|
|
3
|
+
declare class InlineKeyboardBuilder {
|
|
4
|
+
private rows;
|
|
5
|
+
private currentRow;
|
|
6
|
+
private add;
|
|
7
|
+
text(text: string, callbackData: string): this;
|
|
8
|
+
url(text: string, url: string): this;
|
|
9
|
+
webApp(text: string, url: string): this;
|
|
10
|
+
login(text: string, loginUrl: string | LoginUrl): this;
|
|
11
|
+
switchInline(text: string, query?: string): this;
|
|
12
|
+
switchInlineCurrentChat(text: string, query?: string): this;
|
|
13
|
+
switchInlineChosenChat(text: string, query?: SwitchInlineQueryChosenChat): this;
|
|
14
|
+
copyText(text: string, copyText: string | CopyTextButton): this;
|
|
15
|
+
pay(text?: string): this;
|
|
16
|
+
callbackGame(text: string): this;
|
|
17
|
+
button(button: InlineKeyboardButton): this;
|
|
18
|
+
row(): this;
|
|
19
|
+
static columns(buttons: InlineKeyboardButton[], perRow: number): InlineKeyboardBuilder;
|
|
20
|
+
build(): InlineKeyboardMarkup;
|
|
21
|
+
}
|
|
22
|
+
interface ReplyKeyboardBuildOptions {
|
|
23
|
+
resize?: boolean;
|
|
24
|
+
oneTime?: boolean;
|
|
25
|
+
selective?: boolean;
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
persistent?: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare class ReplyKeyboardBuilder {
|
|
30
|
+
private rows;
|
|
31
|
+
private currentRow;
|
|
32
|
+
private add;
|
|
33
|
+
text(label: string): this;
|
|
34
|
+
requestContact(label: string): this;
|
|
35
|
+
requestLocation(label: string): this;
|
|
36
|
+
requestPoll(label: string, type?: KeyboardButtonPollType['type']): this;
|
|
37
|
+
webApp(label: string, url: string): this;
|
|
38
|
+
requestUsers(label: string, params: KeyboardButtonRequestUsers): this;
|
|
39
|
+
requestChat(label: string, params: KeyboardButtonRequestChat): this;
|
|
40
|
+
button(button: KeyboardButton): this;
|
|
41
|
+
row(): this;
|
|
42
|
+
build(options?: ReplyKeyboardBuildOptions): ReplyKeyboardMarkup;
|
|
43
|
+
}
|
|
44
|
+
declare function removeKeyboard(selective?: boolean): ReplyKeyboardRemove;
|
|
45
|
+
declare function forceReply(options?: {
|
|
46
|
+
placeholder?: string;
|
|
47
|
+
selective?: boolean;
|
|
48
|
+
}): ForceReply;
|
|
49
|
+
|
|
50
|
+
export { InlineKeyboardBuilder, type ReplyKeyboardBuildOptions, ReplyKeyboardBuilder, forceReply, removeKeyboard };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { bS as LoginUrl, ct as SwitchInlineQueryChosenChat, cu as CopyTextButton, bG as InlineKeyboardButton, bH as InlineKeyboardMarkup, cv as KeyboardButtonPollType, cw as KeyboardButtonRequestUsers, cx as KeyboardButtonRequestChat, bO as KeyboardButton, c2 as ReplyKeyboardMarkup, bt as ForceReply, c3 as ReplyKeyboardRemove } from '../bot-D8BnLWIi.js';
|
|
2
|
+
|
|
3
|
+
declare class InlineKeyboardBuilder {
|
|
4
|
+
private rows;
|
|
5
|
+
private currentRow;
|
|
6
|
+
private add;
|
|
7
|
+
text(text: string, callbackData: string): this;
|
|
8
|
+
url(text: string, url: string): this;
|
|
9
|
+
webApp(text: string, url: string): this;
|
|
10
|
+
login(text: string, loginUrl: string | LoginUrl): this;
|
|
11
|
+
switchInline(text: string, query?: string): this;
|
|
12
|
+
switchInlineCurrentChat(text: string, query?: string): this;
|
|
13
|
+
switchInlineChosenChat(text: string, query?: SwitchInlineQueryChosenChat): this;
|
|
14
|
+
copyText(text: string, copyText: string | CopyTextButton): this;
|
|
15
|
+
pay(text?: string): this;
|
|
16
|
+
callbackGame(text: string): this;
|
|
17
|
+
button(button: InlineKeyboardButton): this;
|
|
18
|
+
row(): this;
|
|
19
|
+
static columns(buttons: InlineKeyboardButton[], perRow: number): InlineKeyboardBuilder;
|
|
20
|
+
build(): InlineKeyboardMarkup;
|
|
21
|
+
}
|
|
22
|
+
interface ReplyKeyboardBuildOptions {
|
|
23
|
+
resize?: boolean;
|
|
24
|
+
oneTime?: boolean;
|
|
25
|
+
selective?: boolean;
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
persistent?: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare class ReplyKeyboardBuilder {
|
|
30
|
+
private rows;
|
|
31
|
+
private currentRow;
|
|
32
|
+
private add;
|
|
33
|
+
text(label: string): this;
|
|
34
|
+
requestContact(label: string): this;
|
|
35
|
+
requestLocation(label: string): this;
|
|
36
|
+
requestPoll(label: string, type?: KeyboardButtonPollType['type']): this;
|
|
37
|
+
webApp(label: string, url: string): this;
|
|
38
|
+
requestUsers(label: string, params: KeyboardButtonRequestUsers): this;
|
|
39
|
+
requestChat(label: string, params: KeyboardButtonRequestChat): this;
|
|
40
|
+
button(button: KeyboardButton): this;
|
|
41
|
+
row(): this;
|
|
42
|
+
build(options?: ReplyKeyboardBuildOptions): ReplyKeyboardMarkup;
|
|
43
|
+
}
|
|
44
|
+
declare function removeKeyboard(selective?: boolean): ReplyKeyboardRemove;
|
|
45
|
+
declare function forceReply(options?: {
|
|
46
|
+
placeholder?: string;
|
|
47
|
+
selective?: boolean;
|
|
48
|
+
}): ForceReply;
|
|
49
|
+
|
|
50
|
+
export { InlineKeyboardBuilder, type ReplyKeyboardBuildOptions, ReplyKeyboardBuilder, forceReply, removeKeyboard };
|