telegix 1.1.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 +1534 -0
- package/index.d.ts +539 -0
- package/index.js +38 -0
- package/lib/album.js +57 -0
- package/lib/api.js +1840 -0
- package/lib/chataction.js +40 -0
- package/lib/cluster.js +68 -0
- package/lib/composer.js +419 -0
- package/lib/context.js +970 -0
- package/lib/errors.js +67 -0
- package/lib/format.js +115 -0
- package/lib/i18n.js +158 -0
- package/lib/inline-debounce.js +49 -0
- package/lib/inline.js +79 -0
- package/lib/markdownv2.js +29 -0
- package/lib/markup.js +321 -0
- package/lib/payment.js +91 -0
- package/lib/polling.js +101 -0
- package/lib/prompt.js +62 -0
- package/lib/ratelimit.js +59 -0
- package/lib/rich.js +609 -0
- package/lib/scenes.js +206 -0
- package/lib/serialize.js +141 -0
- package/lib/session.js +145 -0
- package/lib/telegix.js +176 -0
- package/lib/webapp.js +65 -0
- package/lib/webhook.js +86 -0
- package/package.json +42 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript definitions for Telegix
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface User {
|
|
6
|
+
id: number;
|
|
7
|
+
is_bot: boolean;
|
|
8
|
+
first_name: string;
|
|
9
|
+
last_name?: string;
|
|
10
|
+
username?: string;
|
|
11
|
+
language_code?: string;
|
|
12
|
+
is_premium?: boolean;
|
|
13
|
+
added_to_attachment_menu?: boolean;
|
|
14
|
+
can_join_groups?: boolean;
|
|
15
|
+
can_read_all_group_messages?: boolean;
|
|
16
|
+
supports_inline_queries?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Chat {
|
|
20
|
+
id: number;
|
|
21
|
+
type: 'private' | 'group' | 'supergroup' | 'channel';
|
|
22
|
+
title?: string;
|
|
23
|
+
username?: string;
|
|
24
|
+
first_name?: string;
|
|
25
|
+
last_name?: string;
|
|
26
|
+
is_forum?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Message {
|
|
30
|
+
message_id: number;
|
|
31
|
+
message_thread_id?: number;
|
|
32
|
+
from?: User;
|
|
33
|
+
sender_chat?: Chat;
|
|
34
|
+
date: number;
|
|
35
|
+
chat: Chat;
|
|
36
|
+
text?: string;
|
|
37
|
+
caption?: string;
|
|
38
|
+
entities?: any[];
|
|
39
|
+
caption_entities?: any[];
|
|
40
|
+
photo?: any[];
|
|
41
|
+
audio?: any;
|
|
42
|
+
document?: any;
|
|
43
|
+
video?: any;
|
|
44
|
+
voice?: any;
|
|
45
|
+
sticker?: any;
|
|
46
|
+
poll?: any;
|
|
47
|
+
dice?: any;
|
|
48
|
+
reply_to_message?: Message;
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface Update {
|
|
53
|
+
update_id: number;
|
|
54
|
+
message?: Message;
|
|
55
|
+
edited_message?: Message;
|
|
56
|
+
channel_post?: Message;
|
|
57
|
+
edited_channel_post?: Message;
|
|
58
|
+
inline_query?: any;
|
|
59
|
+
chosen_inline_result?: any;
|
|
60
|
+
callback_query?: any;
|
|
61
|
+
shipping_query?: any;
|
|
62
|
+
pre_checkout_query?: any;
|
|
63
|
+
poll?: any;
|
|
64
|
+
poll_answer?: any;
|
|
65
|
+
my_chat_member?: any;
|
|
66
|
+
chat_member?: any;
|
|
67
|
+
chat_join_request?: any;
|
|
68
|
+
message_reaction?: any;
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type Middleware<C extends Context = Context> = (
|
|
73
|
+
ctx: C,
|
|
74
|
+
next: () => Promise<void>
|
|
75
|
+
) => any;
|
|
76
|
+
|
|
77
|
+
export class KeyboardBuilder {
|
|
78
|
+
resize(resize?: boolean): this;
|
|
79
|
+
persistent(persistent?: boolean): this;
|
|
80
|
+
oneTime(oneTime?: boolean): this;
|
|
81
|
+
placeholder(placeholder: string): this;
|
|
82
|
+
selectiveTarget(selective?: boolean): this;
|
|
83
|
+
toJSON(): object;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export class Markup {
|
|
87
|
+
static keyboard(buttons: any[], options?: any): KeyboardBuilder;
|
|
88
|
+
static inlineKeyboard(buttons: any[]): { inline_keyboard: any[][] };
|
|
89
|
+
static removeKeyboard(selective?: boolean): { remove_keyboard: true; selective: boolean };
|
|
90
|
+
static forceReply(selective?: boolean, placeholder?: string): { force_reply: true; selective: boolean; input_field_placeholder?: string };
|
|
91
|
+
static button: {
|
|
92
|
+
text(text: string): object;
|
|
93
|
+
callback(text: string, data: string): object;
|
|
94
|
+
url(text: string, url: string): object;
|
|
95
|
+
webApp(text: string, url: string): object;
|
|
96
|
+
contactRequest(text: string): object;
|
|
97
|
+
locationRequest(text: string): object;
|
|
98
|
+
pollRequest(text: string, type?: string): object;
|
|
99
|
+
switchToChat(text: string, query?: string): object;
|
|
100
|
+
switchToCurrentChat(text: string, query?: string): object;
|
|
101
|
+
login(text: string, url: string, options?: object): object;
|
|
102
|
+
pay(text?: string): object;
|
|
103
|
+
copyText(text: string, copyText: string): object;
|
|
104
|
+
requestUsers(text: string, requestId: number, options?: object): object;
|
|
105
|
+
requestChat(text: string, requestId: number, chatIsChannel?: boolean, options?: object): object;
|
|
106
|
+
switchInlineQueryChosenChat(text: string, query?: string, options?: object): object;
|
|
107
|
+
game(text?: string): object;
|
|
108
|
+
disabled(text: string): object;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface SceneContextScene {
|
|
113
|
+
session: any;
|
|
114
|
+
current: any;
|
|
115
|
+
state: any;
|
|
116
|
+
enter(sceneId: string, initialState?: object): Promise<void>;
|
|
117
|
+
reenter(): Promise<void>;
|
|
118
|
+
leave(): Promise<void>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface SceneContextWizard {
|
|
122
|
+
cursor: number;
|
|
123
|
+
state: any;
|
|
124
|
+
selectStep(index: number): void;
|
|
125
|
+
next(): void;
|
|
126
|
+
back(): void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export class Context {
|
|
130
|
+
update: Update;
|
|
131
|
+
telegram: Telegram;
|
|
132
|
+
api: Telegram;
|
|
133
|
+
botInfo: User | null;
|
|
134
|
+
state: Record<string, any>;
|
|
135
|
+
session?: any;
|
|
136
|
+
scene?: SceneContextScene;
|
|
137
|
+
wizard?: SceneContextWizard;
|
|
138
|
+
i18n?: { locale: string; t(key: string, params?: Record<string, any>): string };
|
|
139
|
+
match: RegExpMatchArray | string[] | null;
|
|
140
|
+
command: string | null;
|
|
141
|
+
payload: string | null;
|
|
142
|
+
matchedEntities?: any[];
|
|
143
|
+
|
|
144
|
+
constructor(update: Update, telegram: Telegram, botInfo?: User | null);
|
|
145
|
+
|
|
146
|
+
get updateType(): string;
|
|
147
|
+
get message(): Message | undefined;
|
|
148
|
+
get editedMessage(): Message | undefined;
|
|
149
|
+
get channelPost(): Message | undefined;
|
|
150
|
+
get editedChannelPost(): Message | undefined;
|
|
151
|
+
get businessConnection(): any | undefined;
|
|
152
|
+
get businessMessage(): Message | undefined;
|
|
153
|
+
get editedBusinessMessage(): Message | undefined;
|
|
154
|
+
get deletedBusinessMessages(): any | undefined;
|
|
155
|
+
get messageReaction(): any | undefined;
|
|
156
|
+
get messageReactionCount(): any | undefined;
|
|
157
|
+
get purchasedPaidMedia(): any | undefined;
|
|
158
|
+
get chatBoost(): any | undefined;
|
|
159
|
+
get removedChatBoost(): any | undefined;
|
|
160
|
+
get paidMessagePriceChanged(): any | undefined;
|
|
161
|
+
get stoppedMessageGeneration(): any | undefined;
|
|
162
|
+
get communityChatJoined(): any | undefined;
|
|
163
|
+
get callbackQuery(): any | undefined;
|
|
164
|
+
get inlineQuery(): any | undefined;
|
|
165
|
+
get chosenInlineResult(): any | undefined;
|
|
166
|
+
get shippingQuery(): any | undefined;
|
|
167
|
+
get preCheckoutQuery(): any | undefined;
|
|
168
|
+
get poll(): any | undefined;
|
|
169
|
+
get pollAnswer(): any | undefined;
|
|
170
|
+
get msg(): any;
|
|
171
|
+
get quoted(): any;
|
|
172
|
+
serialize(): any;
|
|
173
|
+
get from(): User | undefined;
|
|
174
|
+
get senderChat(): Chat | undefined;
|
|
175
|
+
get chat(): Chat | undefined;
|
|
176
|
+
get isForum(): boolean;
|
|
177
|
+
get chatId(): number | string | null;
|
|
178
|
+
get userId(): number | null;
|
|
179
|
+
get topicId(): number | null;
|
|
180
|
+
get messageThreadId(): number | null;
|
|
181
|
+
get text(): string | null;
|
|
182
|
+
get entities(): any[];
|
|
183
|
+
|
|
184
|
+
t(key: string, params?: Record<string, any>): string;
|
|
185
|
+
prompt(question: string | object, options?: { timeoutMs?: number; cancelOnCommand?: boolean }): Promise<Context>;
|
|
186
|
+
getMe(): Promise<User>;
|
|
187
|
+
getManagedBotAccessSettings(userId?: number): Promise<any>;
|
|
188
|
+
setManagedBotAccessSettings(settings: object, userId?: number): Promise<boolean>;
|
|
189
|
+
|
|
190
|
+
reply(text: string, extra?: object): Promise<Message>;
|
|
191
|
+
replyWithHTML(html: string, extra?: object): Promise<Message>;
|
|
192
|
+
replyWithMarkdown(markdown: string, extra?: object): Promise<Message>;
|
|
193
|
+
replyWithPhoto(photo: any, extra?: object): Promise<Message>;
|
|
194
|
+
replyWithAudio(audio: any, extra?: object): Promise<Message>;
|
|
195
|
+
replyWithDocument(document: any, extra?: object): Promise<Message>;
|
|
196
|
+
replyWithVideo(video: any, extra?: object): Promise<Message>;
|
|
197
|
+
replyWithAnimation(animation: any, extra?: object): Promise<Message>;
|
|
198
|
+
replyWithVoice(voice: any, extra?: object): Promise<Message>;
|
|
199
|
+
replyWithVideoNote(videoNote: any, extra?: object): Promise<Message>;
|
|
200
|
+
replyWithMediaGroup(media: any[], extra?: object): Promise<Message[]>;
|
|
201
|
+
replyWithLocation(latitude: number, longitude: number, extra?: object): Promise<Message>;
|
|
202
|
+
replyWithVenue(latitude: number, longitude: number, title: string, address: string, extra?: object): Promise<Message>;
|
|
203
|
+
replyWithContact(phoneNumber: string, firstName: string, extra?: object): Promise<Message>;
|
|
204
|
+
replyWithPoll(question: string, options: string[], extra?: object): Promise<Message>;
|
|
205
|
+
replyWithDice(extra?: object): Promise<Message>;
|
|
206
|
+
replyWithChatAction(action: string, extra?: object): Promise<boolean>;
|
|
207
|
+
replyWithInvoice(title: string, description: string, payload: string, currency: string, prices: Array<{label: string; amount: number}>, extra?: object): Promise<Message>;
|
|
208
|
+
replyWithPaidMedia(starCount: number, media: any[], extra?: object): Promise<Message>;
|
|
209
|
+
replyWithSticker(sticker: any, extra?: object): Promise<Message>;
|
|
210
|
+
replyWithGame(gameShortName: string, extra?: object): Promise<Message>;
|
|
211
|
+
createForumTopic(name: string, extra?: object): Promise<any>;
|
|
212
|
+
editForumTopic(messageThreadId?: number, extra?: object): Promise<boolean>;
|
|
213
|
+
closeForumTopic(messageThreadId?: number): Promise<boolean>;
|
|
214
|
+
reopenForumTopic(messageThreadId?: number): Promise<boolean>;
|
|
215
|
+
deleteForumTopic(messageThreadId?: number): Promise<boolean>;
|
|
216
|
+
unpinAllForumTopicMessages(messageThreadId?: number): Promise<boolean>;
|
|
217
|
+
sendGift(giftId: string, extra?: object): Promise<boolean>;
|
|
218
|
+
verifyUser(customDescription?: string): Promise<boolean>;
|
|
219
|
+
verifyChat(customDescription?: string): Promise<boolean>;
|
|
220
|
+
getUserChatBoosts(userId?: number): Promise<any>;
|
|
221
|
+
getBusinessConnection(): Promise<any>;
|
|
222
|
+
replyWithRichMessage(richMessage: any, extra?: object): Promise<Message>;
|
|
223
|
+
editRichMessageText(richMessage: any, extra?: object): Promise<Message | boolean>;
|
|
224
|
+
editRichMessageCaption(caption: string, extra?: object): Promise<Message | boolean>;
|
|
225
|
+
sendEphemeralMessage(text: string, ephemeralParameters: object, extra?: object): Promise<Message>;
|
|
226
|
+
getUserPersonalChatMessages(userId?: number, extra?: object): Promise<any>;
|
|
227
|
+
sendMessageDraft(text: string, extra?: object): Promise<boolean>;
|
|
228
|
+
sendRichMessageDraft(draft: any, extra?: object): Promise<boolean>;
|
|
229
|
+
react(emoji: string | any[]): Promise<boolean>;
|
|
230
|
+
answerCallbackQuery(text?: string, options?: object): Promise<boolean>;
|
|
231
|
+
answerInlineQuery(results: any[], options?: object): Promise<boolean>;
|
|
232
|
+
editMessageText(text: string, extra?: object): Promise<Message | boolean>;
|
|
233
|
+
editMessageCaption(caption: string, extra?: object): Promise<Message | boolean>;
|
|
234
|
+
editMessageMedia(media: object, extra?: object): Promise<Message | boolean>;
|
|
235
|
+
editMessageReplyMarkup(replyMarkup: object, extra?: object): Promise<Message | boolean>;
|
|
236
|
+
deleteMessage(messageId?: number): Promise<boolean>;
|
|
237
|
+
forwardMessage(toChatId: number | string, extra?: object): Promise<Message>;
|
|
238
|
+
copyMessage(toChatId: number | string, extra?: object): Promise<any>;
|
|
239
|
+
pinChatMessage(messageId?: number, extra?: object): Promise<boolean>;
|
|
240
|
+
unpinChatMessage(messageId?: number): Promise<boolean>;
|
|
241
|
+
unpinAllChatMessages(): Promise<boolean>;
|
|
242
|
+
leaveChat(): Promise<boolean>;
|
|
243
|
+
getChat(): Promise<Chat>;
|
|
244
|
+
getChatAdministrators(): Promise<any[]>;
|
|
245
|
+
getChatMember(userId?: number): Promise<any>;
|
|
246
|
+
banChatMember(userId: number, extra?: object): Promise<boolean>;
|
|
247
|
+
unbanChatMember(userId: number, extra?: object): Promise<boolean>;
|
|
248
|
+
restrictChatMember(userId: number, permissions: object, extra?: object): Promise<boolean>;
|
|
249
|
+
promoteChatMember(userId: number, rights?: object): Promise<boolean>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export class Composer<C extends Context = Context> {
|
|
253
|
+
use(...middlewares: Middleware<C>[]): this;
|
|
254
|
+
on(updateTypes: string | string[], ...middlewares: Middleware<C>[]): this;
|
|
255
|
+
command(commands: string | RegExp | (string | RegExp)[], ...middlewares: Middleware<C>[]): this;
|
|
256
|
+
hears(triggers: string | RegExp | Function | (string | RegExp)[], ...middlewares: Middleware<C>[]): this;
|
|
257
|
+
action(triggers: string | RegExp | Function | (string | RegExp)[], ...middlewares: Middleware<C>[]): this;
|
|
258
|
+
inlineQuery(triggers: string | RegExp | Function | (string | RegExp)[], ...middlewares: Middleware<C>[]): this;
|
|
259
|
+
chatType(types: string | string[], ...middlewares: Middleware<C>[]): this;
|
|
260
|
+
business(...middlewares: Middleware<C>[]): this;
|
|
261
|
+
reaction(...middlewares: Middleware<C>[]): this;
|
|
262
|
+
boost(...middlewares: Middleware<C>[]): this;
|
|
263
|
+
forumTopic(...middlewares: Middleware<C>[]): this;
|
|
264
|
+
paidMedia(...middlewares: Middleware<C>[]): this;
|
|
265
|
+
entity(entityTypes: string | string[], ...middlewares: Middleware<C>[]): this;
|
|
266
|
+
filter(predicate: (ctx: C) => boolean | Promise<boolean>, ...middlewares: Middleware<C>[]): this;
|
|
267
|
+
drop(predicate: (ctx: C) => boolean | Promise<boolean>, ...middlewares: Middleware<C>[]): this;
|
|
268
|
+
branch(predicate: (ctx: C) => boolean | Promise<boolean>, trueMiddleware: Middleware<C>, falseMiddleware?: Middleware<C>): this;
|
|
269
|
+
middleware(): (ctx: C, next: () => Promise<void>) => Promise<any>;
|
|
270
|
+
static compose<C extends Context = Context>(middlewares: Middleware<C>[]): Middleware<C>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export class BaseScene<C extends Context = Context> extends Composer<C> {
|
|
274
|
+
id: string;
|
|
275
|
+
constructor(id: string);
|
|
276
|
+
enter(...handlers: Middleware<C>[]): this;
|
|
277
|
+
leave(...handlers: Middleware<C>[]): this;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export class WizardScene<C extends Context = Context> extends BaseScene<C> {
|
|
281
|
+
constructor(id: string, ...steps: Middleware<C>[]);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export class Stage<C extends Context = Context> extends Composer<C> {
|
|
285
|
+
constructor(scenes?: BaseScene<C>[], options?: { defaultScene?: string });
|
|
286
|
+
register(scene: BaseScene<C>): this;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export const Scene: typeof BaseScene;
|
|
290
|
+
|
|
291
|
+
export function escapeHtml(text: string): string;
|
|
292
|
+
export function escapeMarkdown(text: string): string;
|
|
293
|
+
|
|
294
|
+
export interface FormatHelpers {
|
|
295
|
+
escape(text: string): string;
|
|
296
|
+
bold(text: string): string;
|
|
297
|
+
italic(text: string): string;
|
|
298
|
+
underline(text: string): string;
|
|
299
|
+
strikethrough(text: string): string;
|
|
300
|
+
spoiler(text: string): string;
|
|
301
|
+
code(text: string): string;
|
|
302
|
+
pre(codeText: string, language?: string): string;
|
|
303
|
+
link(text: string, url: string): string;
|
|
304
|
+
mention(text: string, userId: number): string;
|
|
305
|
+
customEmoji(text: string, customEmojiId: string): string;
|
|
306
|
+
quote(text: string): string;
|
|
307
|
+
expandableBlockquote(text: string): string;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export interface FmtFunction extends FormatHelpers {
|
|
311
|
+
(strings: TemplateStringsArray, ...values: any[]): string;
|
|
312
|
+
html: FormatHelpers;
|
|
313
|
+
markdown: FormatHelpers;
|
|
314
|
+
raw(str: string): { rawHtml: string };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export const fmt: FmtFunction;
|
|
318
|
+
export const Format: FmtFunction;
|
|
319
|
+
export const html: FormatHelpers;
|
|
320
|
+
export const markdown: FormatHelpers;
|
|
321
|
+
|
|
322
|
+
export class RichMessageBuilder {
|
|
323
|
+
constructor(initialText?: string);
|
|
324
|
+
parseMode(mode: string): this;
|
|
325
|
+
text(text: string): this;
|
|
326
|
+
header(text: string, emoji?: string): this;
|
|
327
|
+
paragraph(text: string): this;
|
|
328
|
+
bold(text: string): this;
|
|
329
|
+
italic(text: string): this;
|
|
330
|
+
underline(text: string): this;
|
|
331
|
+
strikethrough(text: string): this;
|
|
332
|
+
code(codeText: string, language?: string): this;
|
|
333
|
+
quote(text: string, expandable?: boolean): this;
|
|
334
|
+
expandableQuote(text: string): this;
|
|
335
|
+
spoiler(text: string): this;
|
|
336
|
+
link(text: string, url: string): this;
|
|
337
|
+
mention(text: string, userId: number | string): this;
|
|
338
|
+
list(items: string[], bullet?: string): this;
|
|
339
|
+
numberedList(items: string[]): this;
|
|
340
|
+
badge(label: string, value: string | number, icon?: string): this;
|
|
341
|
+
divider(): this;
|
|
342
|
+
photo(url: string, caption?: string): this;
|
|
343
|
+
ephemeral(lifetimeSecondsOrParams?: number | object): this;
|
|
344
|
+
draftId(draftId?: number): this;
|
|
345
|
+
asDraft(): this;
|
|
346
|
+
button(buttons: object | object[]): this;
|
|
347
|
+
row(...buttons: object[]): this;
|
|
348
|
+
callback(text: string, data: string): this;
|
|
349
|
+
url(text: string, url: string): this;
|
|
350
|
+
disabled(text: string): this;
|
|
351
|
+
webApp(text: string, webAppUrl: string): this;
|
|
352
|
+
copyText(text: string, textToCopy: string): this;
|
|
353
|
+
keyboard(matrix: object[][]): this;
|
|
354
|
+
replyMarkup(markup: object): this;
|
|
355
|
+
extra(extra: object): this;
|
|
356
|
+
compileHtml(): string;
|
|
357
|
+
compile(): object;
|
|
358
|
+
build(): object;
|
|
359
|
+
toJSON(): object;
|
|
360
|
+
send(ctx: Context, chatId?: number | string, extra?: object): Promise<Message>;
|
|
361
|
+
sendDraft(ctx: Context, chatId?: number | string, extra?: object): Promise<boolean>;
|
|
362
|
+
edit(ctx: Context, messageId?: number, extra?: object): Promise<Message | boolean>;
|
|
363
|
+
|
|
364
|
+
static create(initialText?: string): RichMessageBuilder;
|
|
365
|
+
static card(title: string, description?: string, buttons?: object[]): RichMessageBuilder;
|
|
366
|
+
static draft(text: string, draftId?: number): RichMessageBuilder;
|
|
367
|
+
static ephemeral(text: string, lifetimeSeconds?: number): RichMessageBuilder;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export const RichMessage: typeof RichMessageBuilder;
|
|
371
|
+
|
|
372
|
+
export class Telegram {
|
|
373
|
+
token: string;
|
|
374
|
+
apiRoot: string;
|
|
375
|
+
testEnv: boolean;
|
|
376
|
+
timeout: number;
|
|
377
|
+
|
|
378
|
+
constructor(token: string, options?: { apiRoot?: string; testEnv?: boolean; timeout?: number });
|
|
379
|
+
call(method: string, payload?: object, options?: object): Promise<any>;
|
|
380
|
+
getMe(): Promise<User>;
|
|
381
|
+
sendMessage(chatId: number | string, text: string, extra?: object): Promise<Message>;
|
|
382
|
+
sendPhoto(chatId: number | string, photo: any, extra?: object): Promise<Message>;
|
|
383
|
+
sendAudio(chatId: number | string, audio: any, extra?: object): Promise<Message>;
|
|
384
|
+
sendDocument(chatId: number | string, document: any, extra?: object): Promise<Message>;
|
|
385
|
+
sendVideo(chatId: number | string, video: any, extra?: object): Promise<Message>;
|
|
386
|
+
sendAnimation(chatId: number | string, animation: any, extra?: object): Promise<Message>;
|
|
387
|
+
sendVoice(chatId: number | string, voice: any, extra?: object): Promise<Message>;
|
|
388
|
+
sendLocation(chatId: number | string, latitude: number, longitude: number, extra?: object): Promise<Message>;
|
|
389
|
+
sendPoll(chatId: number | string, question: string, options: string[], extra?: object): Promise<Message>;
|
|
390
|
+
deleteMessage(chatId: number | string, messageId: number): Promise<boolean>;
|
|
391
|
+
getUpdates(offset?: number, limit?: number, timeout?: number, allowedUpdates?: string[]): Promise<Update[]>;
|
|
392
|
+
sendRichMessage(chatId: number | string, richMessage: any, extra?: object): Promise<Message>;
|
|
393
|
+
sendRichMessageDraft(chatId: number | string, draft: any, extra?: object): Promise<boolean>;
|
|
394
|
+
editRichMessageText(chatId: number | string, messageId: number, richMessage: any, extra?: object): Promise<Message | boolean>;
|
|
395
|
+
editRichMessageCaption(chatId: number | string, messageId: number, caption: string, extra?: object): Promise<Message | boolean>;
|
|
396
|
+
sendEphemeralMessage(chatId: number | string, text: string, ephemeralParameters: object, extra?: object): Promise<Message>;
|
|
397
|
+
editEphemeralMessageText(chatId: number | string, messageId: number, text: string, extra?: object): Promise<Message | boolean>;
|
|
398
|
+
editEphemeralMessageMedia(chatId: number | string, messageId: number, media: object, extra?: object): Promise<Message | boolean>;
|
|
399
|
+
editEphemeralMessageCaption(chatId: number | string, messageId: number, caption: string, extra?: object): Promise<Message | boolean>;
|
|
400
|
+
deleteEphemeralMessage(chatId: number | string, messageId: number): Promise<boolean>;
|
|
401
|
+
getManagedBotAccessSettings(userId: number, extra?: object): Promise<any>;
|
|
402
|
+
setManagedBotAccessSettings(userId: number, settings?: object, extra?: object): Promise<boolean>;
|
|
403
|
+
getUserPersonalChatMessages(userId: number, extra?: object): Promise<any>;
|
|
404
|
+
sendMessageDraft(chatId: number | string, text: string, extra?: object): Promise<boolean>;
|
|
405
|
+
setWebhook(url: string, extra?: object): Promise<boolean>;
|
|
406
|
+
deleteWebhook(extra?: object): Promise<boolean>;
|
|
407
|
+
getWebhookInfo(): Promise<any>;
|
|
408
|
+
[key: string]: any;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export class Telegix extends Composer {
|
|
412
|
+
token: string;
|
|
413
|
+
telegram: Telegram;
|
|
414
|
+
api: Telegram;
|
|
415
|
+
botInfo: User | null;
|
|
416
|
+
|
|
417
|
+
constructor(token: string, options?: object);
|
|
418
|
+
catch(handler: (err: Error, ctx?: Context) => void): this;
|
|
419
|
+
handleUpdate(update: Update): Promise<void>;
|
|
420
|
+
startPolling(options?: object): Promise<void>;
|
|
421
|
+
stop(reason?: string): Promise<void>;
|
|
422
|
+
launch(options?: { polling?: boolean | object; webhook?: object; dropPendingUpdates?: boolean }): Promise<User>;
|
|
423
|
+
webhookCallback(path?: string, options?: object): (req: any, res: any, next?: Function) => Promise<void>;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export class MemorySessionStore {
|
|
427
|
+
constructor(ttl?: number);
|
|
428
|
+
get(key: string): Promise<any>;
|
|
429
|
+
set(key: string, value: any): Promise<void>;
|
|
430
|
+
delete(key: string): Promise<void>;
|
|
431
|
+
clear(): Promise<void>;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export class FileSessionStore {
|
|
435
|
+
constructor(filePath?: string, ttl?: number);
|
|
436
|
+
get(key: string): Promise<any>;
|
|
437
|
+
set(key: string, value: any): Promise<void>;
|
|
438
|
+
delete(key: string): Promise<void>;
|
|
439
|
+
clear(): Promise<void>;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export class I18n {
|
|
443
|
+
defaultLocale: string;
|
|
444
|
+
translations: Record<string, any>;
|
|
445
|
+
constructor(options?: {
|
|
446
|
+
defaultLocale?: string;
|
|
447
|
+
translations?: Record<string, any>;
|
|
448
|
+
localeFn?: (ctx: Context) => string;
|
|
449
|
+
useSession?: boolean;
|
|
450
|
+
});
|
|
451
|
+
addTranslation(locale: string, dict: Record<string, any>): this;
|
|
452
|
+
addTranslations(translations: Record<string, Record<string, any>>): this;
|
|
453
|
+
t(locale: string, key: string, params?: Record<string, any>): string;
|
|
454
|
+
middleware(): Middleware;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export class RateLimiter {
|
|
458
|
+
constructor(options?: { windowMs?: number; limit?: number; keyFn?: (ctx: Context) => string | number; handler?: Middleware });
|
|
459
|
+
middleware(): Middleware;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function rateLimit(options?: { windowMs?: number; limit?: number; keyFn?: (ctx: Context) => string | number; handler?: Middleware }): Middleware;
|
|
463
|
+
|
|
464
|
+
export function session(options?: {
|
|
465
|
+
getSessionKey?: (ctx: Context) => string | null;
|
|
466
|
+
store?: any;
|
|
467
|
+
initial?: (ctx: Context) => any;
|
|
468
|
+
ttl?: number;
|
|
469
|
+
}): Middleware;
|
|
470
|
+
|
|
471
|
+
export function serializeMessage(msg: any): any;
|
|
472
|
+
export function serializeUpdate(update: any): any;
|
|
473
|
+
|
|
474
|
+
export class InlineQueryResultBuilder {
|
|
475
|
+
static article(id: string | number, title: string, messageText: string, options?: any): any;
|
|
476
|
+
static photo(id: string | number, photoUrl: string, options?: any): any;
|
|
477
|
+
static document(id: string | number, documentUrl: string, title: string, options?: any): any;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export function paginateInlineQuery(ctx: Context, items: any[], formatterFn: (item: any, index: number) => any, options?: any): Promise<boolean>;
|
|
481
|
+
|
|
482
|
+
export function albumMiddleware(options?: { windowMs?: number }): Middleware;
|
|
483
|
+
|
|
484
|
+
export function validateWebAppInitData(initDataStr: string, botToken: string, options?: { maxAgeSeconds?: number }): any;
|
|
485
|
+
|
|
486
|
+
export function promptMiddleware(): Middleware;
|
|
487
|
+
|
|
488
|
+
export function escapeMarkdownV2(str: string): string;
|
|
489
|
+
export const mdv2: {
|
|
490
|
+
escape(str: string): string;
|
|
491
|
+
bold(text: string): string;
|
|
492
|
+
italic(text: string): string;
|
|
493
|
+
underline(text: string): string;
|
|
494
|
+
strikethrough(text: string): string;
|
|
495
|
+
spoiler(text: string): string;
|
|
496
|
+
code(text: string): string;
|
|
497
|
+
pre(text: string, language?: string): string;
|
|
498
|
+
link(text: string, url: string): string;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
export function inlineDebounceMiddleware(options?: { windowMs?: number; cacheTtlMs?: number }): Middleware;
|
|
502
|
+
export function chatActionMiddleware(action?: string, options?: { intervalMs?: number }): Middleware;
|
|
503
|
+
|
|
504
|
+
export class InvoiceBuilder {
|
|
505
|
+
constructor(title: string, description: string, payload: string, currency?: string, prices?: any[]);
|
|
506
|
+
providerToken(token: string): this;
|
|
507
|
+
addPrice(label: string, amount: number): this;
|
|
508
|
+
maxTipAmount(amount: number): this;
|
|
509
|
+
suggestedTipAmounts(amounts: number[]): this;
|
|
510
|
+
photo(url: string, width?: number, height?: number, size?: number): this;
|
|
511
|
+
need(options: { name?: boolean; phoneNumber?: boolean; email?: boolean; shippingAddress?: boolean }): this;
|
|
512
|
+
send(ctx: Context, chatId?: number | string): Promise<any>;
|
|
513
|
+
build(): any;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export function answerShippingQuery(ctx: Context, ok: boolean, options?: any): Promise<any>;
|
|
517
|
+
export function answerPreCheckoutQuery(ctx: Context, ok: boolean, options?: any): Promise<any>;
|
|
518
|
+
|
|
519
|
+
export class TelegixManager {
|
|
520
|
+
constructor();
|
|
521
|
+
add(name: string, tokenOrOptions: string | any): Telegix;
|
|
522
|
+
get(name: string): Telegix | undefined;
|
|
523
|
+
remove(name: string): void;
|
|
524
|
+
launchAll(options?: any): Promise<any>;
|
|
525
|
+
stopAll(): void;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export class TelegixError extends Error {}
|
|
529
|
+
export class TelegramError extends TelegixError {
|
|
530
|
+
errorCode: number;
|
|
531
|
+
description: string;
|
|
532
|
+
parameters: any;
|
|
533
|
+
retryAfter?: number;
|
|
534
|
+
migrateToChatId?: number;
|
|
535
|
+
}
|
|
536
|
+
export class NetworkError extends TelegixError {}
|
|
537
|
+
export class PollingError extends TelegixError {}
|
|
538
|
+
|
|
539
|
+
export default Telegix;
|
package/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegix - Lightweight Telegram Bot API Framework
|
|
3
|
+
* @author KazeDevID
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { Telegix } from './lib/telegix.js';
|
|
8
|
+
export { Telegram, normalizeTelegramPayload } from './lib/api.js';
|
|
9
|
+
export { Context } from './lib/context.js';
|
|
10
|
+
export { Composer, compose } from './lib/composer.js';
|
|
11
|
+
export { Markup, KeyboardBuilder } from './lib/markup.js';
|
|
12
|
+
export { session, MemorySessionStore, FileSessionStore } from './lib/session.js';
|
|
13
|
+
export { Polling } from './lib/polling.js';
|
|
14
|
+
export { createWebhookCallback } from './lib/webhook.js';
|
|
15
|
+
export { fmt, Format, escapeHtml, escapeMarkdown, html, markdown } from './lib/format.js';
|
|
16
|
+
export { RichMessage, RichMessageBuilder } from './lib/rich.js';
|
|
17
|
+
export { Scene, BaseScene, WizardScene, Stage } from './lib/scenes.js';
|
|
18
|
+
export { I18n } from './lib/i18n.js';
|
|
19
|
+
export { RateLimiter, rateLimit } from './lib/ratelimit.js';
|
|
20
|
+
export { serializeMessage, serializeUpdate } from './lib/serialize.js';
|
|
21
|
+
export { InlineQueryResultBuilder, paginateInlineQuery } from './lib/inline.js';
|
|
22
|
+
export { albumMiddleware } from './lib/album.js';
|
|
23
|
+
export { validateWebAppInitData } from './lib/webapp.js';
|
|
24
|
+
export { promptMiddleware } from './lib/prompt.js';
|
|
25
|
+
export { escapeMarkdownV2, mdv2 } from './lib/markdownv2.js';
|
|
26
|
+
export { inlineDebounceMiddleware } from './lib/inline-debounce.js';
|
|
27
|
+
export { chatActionMiddleware } from './lib/chataction.js';
|
|
28
|
+
export { InvoiceBuilder, answerShippingQuery, answerPreCheckoutQuery } from './lib/payment.js';
|
|
29
|
+
export { TelegixManager } from './lib/cluster.js';
|
|
30
|
+
export {
|
|
31
|
+
TelegixError,
|
|
32
|
+
TelegramError,
|
|
33
|
+
NetworkError,
|
|
34
|
+
PollingError,
|
|
35
|
+
} from './lib/errors.js';
|
|
36
|
+
|
|
37
|
+
import { Telegix } from './lib/telegix.js';
|
|
38
|
+
export default Telegix;
|
package/lib/album.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegix - Media Group (Album) Collector Middleware
|
|
3
|
+
* Automatically batches multiple photos/videos sent together as an album into ctx.album
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export function albumMiddleware(options = {}) {
|
|
7
|
+
const windowMs = options.windowMs || 400;
|
|
8
|
+
const pendingAlbums = new Map();
|
|
9
|
+
|
|
10
|
+
return async (ctx, next) => {
|
|
11
|
+
const msg = ctx.msg || ctx.message;
|
|
12
|
+
const mediaGroupId = msg?.raw?.media_group_id || msg?.media_group_id;
|
|
13
|
+
|
|
14
|
+
if (!mediaGroupId) {
|
|
15
|
+
return next();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (pendingAlbums.has(mediaGroupId)) {
|
|
19
|
+
const albumEntry = pendingAlbums.get(mediaGroupId);
|
|
20
|
+
albumEntry.messages.push(msg);
|
|
21
|
+
albumEntry.contexts.push(ctx);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const albumEntry = {
|
|
26
|
+
messages: [msg],
|
|
27
|
+
contexts: [ctx],
|
|
28
|
+
timer: null,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
albumEntry.timer = setTimeout(async () => {
|
|
33
|
+
pendingAlbums.delete(mediaGroupId);
|
|
34
|
+
|
|
35
|
+
const albumData = {
|
|
36
|
+
mediaGroupId,
|
|
37
|
+
messages: albumEntry.messages,
|
|
38
|
+
count: albumEntry.messages.length,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
for (const c of albumEntry.contexts) {
|
|
42
|
+
c.album = albumData;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
await next();
|
|
47
|
+
resolve();
|
|
48
|
+
} catch (err) {
|
|
49
|
+
resolve();
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
}, windowMs);
|
|
53
|
+
|
|
54
|
+
pendingAlbums.set(mediaGroupId, albumEntry);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
}
|