@xbibzlibrary/telebibz 0.4.4 → 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/CHANGELOG.md +35 -138
- package/LICENSE +1 -1
- package/NOTICE.md +9 -4
- package/README.md +173 -242
- package/examples/01-quickstart.js +13 -0
- package/examples/02-menu-tombol.js +22 -0
- package/examples/03-wizard.js +29 -0
- package/examples/04-broadcast.js +25 -0
- package/examples/05-kirim-file.js +19 -0
- package/examples/06-menu.js +35 -0
- package/examples/07-inline-query.js +18 -0
- package/index.d.ts +81 -0
- package/index.js +42 -0
- package/lib/api.js +154 -0
- package/lib/broadcast.js +35 -0
- package/lib/composer.js +174 -0
- package/lib/context.js +190 -0
- package/lib/errors.js +35 -0
- package/lib/file.js +41 -0
- package/lib/inline-query.js +28 -0
- package/lib/keyboard.js +83 -0
- package/lib/logger.js +38 -0
- package/lib/menus.js +90 -0
- package/lib/net.js +115 -0
- package/lib/ratelimit.js +61 -0
- package/lib/runner.js +45 -0
- package/lib/session.js +36 -0
- package/lib/telebibz.js +190 -0
- package/lib/wizard.js +81 -0
- package/package.json +35 -97
- package/test/all.test.js +334 -0
- package/CODE_OF_CONDUCT.md +0 -37
- package/CONTRIBUTING.md +0 -59
- package/CONTRIBUTION_RULES.md +0 -41
- package/GOVERNANCE.md +0 -47
- package/README.id.md +0 -292
- package/README.zh-CN.md +0 -292
- package/RELEASE_AUTOMATION.md +0 -78
- package/RELEASE_POLICY.md +0 -32
- package/SECURITY.md +0 -47
- package/SHOWCASE.md +0 -29
- package/SUPPORT.md +0 -30
- package/assets/readme-preview.html +0 -75
- package/assets/telebibz-logo.png +0 -0
- package/assets/telebibz-readme-preview.png +0 -0
- package/bin/telebibz.mjs +0 -3
- package/dist/generated/api.d.ts +0 -13
- package/dist/generated/api.d.ts.map +0 -1
- package/dist/generated/api.js +0 -192
- package/dist/generated/api.js.map +0 -1
- package/dist/src/api/client.d.ts +0 -62
- package/dist/src/api/client.d.ts.map +0 -1
- package/dist/src/api/client.js +0 -104
- package/dist/src/api/client.js.map +0 -1
- package/dist/src/api/errors.d.ts +0 -45
- package/dist/src/api/errors.d.ts.map +0 -1
- package/dist/src/api/errors.js +0 -65
- package/dist/src/api/errors.js.map +0 -1
- package/dist/src/api/index.d.ts +0 -6
- package/dist/src/api/index.d.ts.map +0 -1
- package/dist/src/api/index.js +0 -6
- package/dist/src/api/index.js.map +0 -1
- package/dist/src/api/telegram-types/LICENSE +0 -21
- package/dist/src/api/telegram-types/api.d.ts +0 -22
- package/dist/src/api/telegram-types/checklist.d.ts +0 -72
- package/dist/src/api/telegram-types/inline.d.ts +0 -692
- package/dist/src/api/telegram-types/langs.d.ts +0 -193
- package/dist/src/api/telegram-types/manage.d.ts +0 -1144
- package/dist/src/api/telegram-types/markup.d.ts +0 -268
- package/dist/src/api/telegram-types/message.d.ts +0 -1537
- package/dist/src/api/telegram-types/methods.d.ts +0 -2870
- package/dist/src/api/telegram-types/mod.d.ts +0 -14
- package/dist/src/api/telegram-types/passport.d.ts +0 -163
- package/dist/src/api/telegram-types/payment.d.ts +0 -570
- package/dist/src/api/telegram-types/rich.d.ts +0 -1010
- package/dist/src/api/telegram-types/settings.d.ts +0 -120
- package/dist/src/api/telegram-types/story.d.ts +0 -89
- package/dist/src/api/telegram-types/update.d.ts +0 -84
- package/dist/src/api/telegram.d.ts +0 -7
- package/dist/src/api/telegram.d.ts.map +0 -1
- package/dist/src/api/telegram.js +0 -2
- package/dist/src/api/telegram.js.map +0 -1
- package/dist/src/api/transport.d.ts +0 -68
- package/dist/src/api/transport.d.ts.map +0 -1
- package/dist/src/api/transport.js +0 -264
- package/dist/src/api/transport.js.map +0 -1
- package/dist/src/api/types.d.ts +0 -466
- package/dist/src/api/types.d.ts.map +0 -1
- package/dist/src/api/types.js +0 -2
- package/dist/src/api/types.js.map +0 -1
- package/dist/src/branding/terminal.d.ts +0 -77
- package/dist/src/branding/terminal.d.ts.map +0 -1
- package/dist/src/branding/terminal.js +0 -328
- package/dist/src/branding/terminal.js.map +0 -1
- package/dist/src/broadcast/broadcast.d.ts +0 -50
- package/dist/src/broadcast/broadcast.d.ts.map +0 -1
- package/dist/src/broadcast/broadcast.js +0 -56
- package/dist/src/broadcast/broadcast.js.map +0 -1
- package/dist/src/cache/cache.d.ts +0 -34
- package/dist/src/cache/cache.d.ts.map +0 -1
- package/dist/src/cache/cache.js +0 -41
- package/dist/src/cache/cache.js.map +0 -1
- package/dist/src/cli.d.ts +0 -2
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -84
- package/dist/src/cli.js.map +0 -1
- package/dist/src/context/context.d.ts +0 -124
- package/dist/src/context/context.d.ts.map +0 -1
- package/dist/src/context/context.js +0 -302
- package/dist/src/context/context.js.map +0 -1
- package/dist/src/core/bot.d.ts +0 -204
- package/dist/src/core/bot.d.ts.map +0 -1
- package/dist/src/core/bot.js +0 -506
- package/dist/src/core/bot.js.map +0 -1
- package/dist/src/core/events.d.ts +0 -75
- package/dist/src/core/events.d.ts.map +0 -1
- package/dist/src/core/events.js +0 -35
- package/dist/src/core/events.js.map +0 -1
- package/dist/src/core/webhook-reply.d.ts +0 -34
- package/dist/src/core/webhook-reply.d.ts.map +0 -1
- package/dist/src/core/webhook-reply.js +0 -37
- package/dist/src/core/webhook-reply.js.map +0 -1
- package/dist/src/index.d.ts +0 -24
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -24
- package/dist/src/index.js.map +0 -1
- package/dist/src/keyboard/index.d.ts +0 -46
- package/dist/src/keyboard/index.d.ts.map +0 -1
- package/dist/src/keyboard/index.js +0 -55
- package/dist/src/keyboard/index.js.map +0 -1
- package/dist/src/middleware/compose.d.ts +0 -5
- package/dist/src/middleware/compose.d.ts.map +0 -1
- package/dist/src/middleware/compose.js +0 -17
- package/dist/src/middleware/compose.js.map +0 -1
- package/dist/src/observability/logger.d.ts +0 -78
- package/dist/src/observability/logger.d.ts.map +0 -1
- package/dist/src/observability/logger.js +0 -285
- package/dist/src/observability/logger.js.map +0 -1
- package/dist/src/plugins/plugin.d.ts +0 -38
- package/dist/src/plugins/plugin.d.ts.map +0 -1
- package/dist/src/plugins/plugin.js +0 -59
- package/dist/src/plugins/plugin.js.map +0 -1
- package/dist/src/queue/queue.d.ts +0 -77
- package/dist/src/queue/queue.d.ts.map +0 -1
- package/dist/src/queue/queue.js +0 -213
- package/dist/src/queue/queue.js.map +0 -1
- package/dist/src/router/router.d.ts +0 -61
- package/dist/src/router/router.d.ts.map +0 -1
- package/dist/src/router/router.js +0 -183
- package/dist/src/router/router.js.map +0 -1
- package/dist/src/state/conversation.d.ts +0 -56
- package/dist/src/state/conversation.d.ts.map +0 -1
- package/dist/src/state/conversation.js +0 -133
- package/dist/src/state/conversation.js.map +0 -1
- package/dist/src/state/forms.d.ts +0 -34
- package/dist/src/state/forms.d.ts.map +0 -1
- package/dist/src/state/forms.js +0 -44
- package/dist/src/state/forms.js.map +0 -1
- package/dist/src/state/menu.d.ts +0 -78
- package/dist/src/state/menu.d.ts.map +0 -1
- package/dist/src/state/menu.js +0 -127
- package/dist/src/state/menu.js.map +0 -1
- package/dist/src/storage/storage.d.ts +0 -146
- package/dist/src/storage/storage.d.ts.map +0 -1
- package/dist/src/storage/storage.js +0 -195
- package/dist/src/storage/storage.js.map +0 -1
- package/dist/src/telegram-features.d.ts +0 -33
- package/dist/src/telegram-features.d.ts.map +0 -1
- package/dist/src/telegram-features.js +0 -71
- package/dist/src/telegram-features.js.map +0 -1
- package/dist/src/testing.d.ts +0 -24
- package/dist/src/testing.d.ts.map +0 -1
- package/dist/src/testing.js +0 -38
- package/dist/src/testing.js.map +0 -1
- package/dist/src/utils/concurrency.d.ts +0 -25
- package/dist/src/utils/concurrency.d.ts.map +0 -1
- package/dist/src/utils/concurrency.js +0 -52
- package/dist/src/utils/concurrency.js.map +0 -1
- package/dist/src/utils/files.d.ts +0 -45
- package/dist/src/utils/files.d.ts.map +0 -1
- package/dist/src/utils/files.js +0 -53
- package/dist/src/utils/files.js.map +0 -1
- package/dist/src/utils/text.d.ts +0 -39
- package/dist/src/utils/text.d.ts.map +0 -1
- package/dist/src/utils/text.js +0 -56
- package/dist/src/utils/text.js.map +0 -1
- package/dist/src/webhook/handler.d.ts +0 -19
- package/dist/src/webhook/handler.d.ts.map +0 -1
- package/dist/src/webhook/handler.js +0 -141
- package/dist/src/webhook/handler.js.map +0 -1
- package/dist-cjs/generated/api.js +0 -194
- package/dist-cjs/package.json +0 -3
- package/dist-cjs/src/api/client.js +0 -107
- package/dist-cjs/src/api/errors.js +0 -74
- package/dist-cjs/src/api/index.js +0 -21
- package/dist-cjs/src/api/telegram-types/LICENSE +0 -21
- package/dist-cjs/src/api/telegram-types/api.d.ts +0 -22
- package/dist-cjs/src/api/telegram-types/checklist.d.ts +0 -72
- package/dist-cjs/src/api/telegram-types/inline.d.ts +0 -692
- package/dist-cjs/src/api/telegram-types/langs.d.ts +0 -193
- package/dist-cjs/src/api/telegram-types/manage.d.ts +0 -1144
- package/dist-cjs/src/api/telegram-types/markup.d.ts +0 -268
- package/dist-cjs/src/api/telegram-types/message.d.ts +0 -1537
- package/dist-cjs/src/api/telegram-types/methods.d.ts +0 -2870
- package/dist-cjs/src/api/telegram-types/mod.d.ts +0 -14
- package/dist-cjs/src/api/telegram-types/passport.d.ts +0 -163
- package/dist-cjs/src/api/telegram-types/payment.d.ts +0 -570
- package/dist-cjs/src/api/telegram-types/rich.d.ts +0 -1010
- package/dist-cjs/src/api/telegram-types/settings.d.ts +0 -120
- package/dist-cjs/src/api/telegram-types/story.d.ts +0 -89
- package/dist-cjs/src/api/telegram-types/update.d.ts +0 -84
- package/dist-cjs/src/api/telegram.js +0 -2
- package/dist-cjs/src/api/transport.js +0 -267
- package/dist-cjs/src/api/types.js +0 -2
- package/dist-cjs/src/branding/terminal.js +0 -338
- package/dist-cjs/src/broadcast/broadcast.js +0 -58
- package/dist-cjs/src/cache/cache.js +0 -45
- package/dist-cjs/src/cli.js +0 -86
- package/dist-cjs/src/context/context.js +0 -305
- package/dist-cjs/src/core/bot.js +0 -510
- package/dist-cjs/src/core/events.js +0 -38
- package/dist-cjs/src/core/webhook-reply.js +0 -42
- package/dist-cjs/src/index.js +0 -47
- package/dist-cjs/src/keyboard/index.js +0 -61
- package/dist-cjs/src/middleware/compose.js +0 -20
- package/dist-cjs/src/observability/logger.js +0 -293
- package/dist-cjs/src/plugins/plugin.js +0 -63
- package/dist-cjs/src/queue/queue.js +0 -219
- package/dist-cjs/src/router/router.js +0 -186
- package/dist-cjs/src/state/conversation.js +0 -139
- package/dist-cjs/src/state/forms.js +0 -47
- package/dist-cjs/src/state/menu.js +0 -133
- package/dist-cjs/src/storage/storage.js +0 -202
- package/dist-cjs/src/telegram-features.js +0 -76
- package/dist-cjs/src/testing.js +0 -45
- package/dist-cjs/src/utils/concurrency.js +0 -57
- package/dist-cjs/src/utils/files.js +0 -58
- package/dist-cjs/src/utils/text.js +0 -63
- package/dist-cjs/src/webhook/handler.js +0 -144
- package/docs/API.id.md +0 -1935
- package/docs/API.md +0 -1969
- package/docs/API.zh-CN.md +0 -1929
- package/docs/GETTING_STARTED.id.md +0 -85
- package/docs/GETTING_STARTED.md +0 -85
- package/docs/GETTING_STARTED.zh-CN.md +0 -85
- package/docs/GITHUB_PACKAGES.id.md +0 -82
- package/docs/GITHUB_PACKAGES.md +0 -82
- package/docs/GITHUB_PACKAGES.zh-CN.md +0 -82
- package/docs/README.md +0 -48
- package/docs/STORAGE.id.md +0 -105
- package/docs/STORAGE.md +0 -105
- package/docs/STORAGE.zh-CN.md +0 -105
- package/examples/README.md +0 -37
- package/examples/files.ts +0 -35
- package/examples/minimal.ts +0 -12
- package/examples/tsconfig.json +0 -9
- package/examples/webhook.ts +0 -42
- package/examples/wizard-registration.ts +0 -42
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Context = void 0;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
class Context {
|
|
6
|
-
update;
|
|
7
|
-
api;
|
|
8
|
-
session;
|
|
9
|
-
state = Object.create(null);
|
|
10
|
-
services;
|
|
11
|
-
params = Object.create(null);
|
|
12
|
-
me;
|
|
13
|
-
match;
|
|
14
|
-
args;
|
|
15
|
-
constructor(options) {
|
|
16
|
-
this.update = options.update;
|
|
17
|
-
this.api = options.api;
|
|
18
|
-
this.session = options.session;
|
|
19
|
-
this.services = options.services;
|
|
20
|
-
this.me = options.me;
|
|
21
|
-
}
|
|
22
|
-
get message() {
|
|
23
|
-
return this.update.message
|
|
24
|
-
?? this.update.edited_message
|
|
25
|
-
?? this.update.channel_post
|
|
26
|
-
?? this.update.edited_channel_post
|
|
27
|
-
?? this.update.business_message
|
|
28
|
-
?? this.update.edited_business_message
|
|
29
|
-
?? this.update.guest_message
|
|
30
|
-
?? this.callbackQuery?.message;
|
|
31
|
-
}
|
|
32
|
-
get chat() {
|
|
33
|
-
return this.message?.chat
|
|
34
|
-
?? this.update.chat_member?.chat
|
|
35
|
-
?? this.update.my_chat_member?.chat
|
|
36
|
-
?? this.update.chat_join_request?.chat
|
|
37
|
-
?? this.pollAnswer?.voter_chat;
|
|
38
|
-
}
|
|
39
|
-
get from() {
|
|
40
|
-
return this.callbackQuery?.from
|
|
41
|
-
?? this.inlineQuery?.from
|
|
42
|
-
?? this.update.chosen_inline_result?.from
|
|
43
|
-
?? this.update.message?.from
|
|
44
|
-
?? this.update.edited_message?.from
|
|
45
|
-
?? this.update.channel_post?.from
|
|
46
|
-
?? this.update.edited_channel_post?.from
|
|
47
|
-
?? this.update.business_message?.from
|
|
48
|
-
?? this.update.edited_business_message?.from
|
|
49
|
-
?? this.update.guest_message?.from
|
|
50
|
-
?? this.update.chat_member?.from
|
|
51
|
-
?? this.update.my_chat_member?.from
|
|
52
|
-
?? this.update.chat_join_request?.from
|
|
53
|
-
?? this.pollAnswer?.user
|
|
54
|
-
?? this.message?.from;
|
|
55
|
-
}
|
|
56
|
-
get sender() { return this.from; }
|
|
57
|
-
get callbackQuery() { return this.update.callback_query; }
|
|
58
|
-
get inlineQuery() { return this.update.inline_query; }
|
|
59
|
-
get poll() { return this.update.poll; }
|
|
60
|
-
get pollAnswer() { return this.update.poll_answer; }
|
|
61
|
-
get chatMember() { return this.update.chat_member; }
|
|
62
|
-
get myChatMember() { return this.update.my_chat_member; }
|
|
63
|
-
get chatJoinRequest() { return this.update.chat_join_request; }
|
|
64
|
-
get reaction() { return this.update.message_reaction; }
|
|
65
|
-
get boost() { return this.update.chat_boost ?? this.update.removed_chat_boost; }
|
|
66
|
-
replyExtras(extra) {
|
|
67
|
-
const { reply_parameters, reply_markup, ...rest } = extra;
|
|
68
|
-
const quoted = this.message?.message_id !== undefined ? { message_id: this.message.message_id } : undefined;
|
|
69
|
-
const replyParameters = quoted === undefined && reply_parameters === undefined ? undefined : { ...(quoted ?? {}), ...(reply_parameters ?? {}) };
|
|
70
|
-
return { replyParameters, replyMarkup: reply_markup ?? this.state.reply_markup, rest };
|
|
71
|
-
}
|
|
72
|
-
sendMethod(method, payload, extra = {}) {
|
|
73
|
-
if (!this.chat)
|
|
74
|
-
throw new Error(`Cannot send ${method} without a chat in this update.`);
|
|
75
|
-
const { replyParameters, replyMarkup, rest } = this.replyExtras(extra);
|
|
76
|
-
return this.api.call(method, {
|
|
77
|
-
chat_id: this.chat.id,
|
|
78
|
-
...payload,
|
|
79
|
-
...rest,
|
|
80
|
-
...(replyParameters ? { reply_parameters: replyParameters } : {}),
|
|
81
|
-
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
async reply(text, extra = {}) {
|
|
85
|
-
return this.sendMethod("sendMessage", { text }, extra);
|
|
86
|
-
}
|
|
87
|
-
async send(text, extra = {}) {
|
|
88
|
-
if (!this.chat)
|
|
89
|
-
throw new Error("Cannot send without a chat in this update.");
|
|
90
|
-
const { replyMarkup, rest } = this.replyExtras(extra);
|
|
91
|
-
return this.api.methods.sendMessage({
|
|
92
|
-
chat_id: this.chat.id,
|
|
93
|
-
text,
|
|
94
|
-
...rest,
|
|
95
|
-
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
async edit(text, extra = {}) {
|
|
99
|
-
if (!this.chat || !this.message)
|
|
100
|
-
throw new Error("Cannot edit without a chat and message in this update.");
|
|
101
|
-
const { replyMarkup, rest } = this.replyExtras(extra);
|
|
102
|
-
return this.api.methods.editMessageText({
|
|
103
|
-
chat_id: this.chat.id,
|
|
104
|
-
message_id: this.message.message_id,
|
|
105
|
-
text,
|
|
106
|
-
...rest,
|
|
107
|
-
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
async replyWithHTML(text, extra = {}) {
|
|
111
|
-
return this.reply(text, { parse_mode: "HTML", ...extra });
|
|
112
|
-
}
|
|
113
|
-
async replyWithMarkdown(text, extra = {}) {
|
|
114
|
-
return this.reply(text, { parse_mode: "MarkdownV2", ...extra });
|
|
115
|
-
}
|
|
116
|
-
async replyWithPhoto(photo, extra = {}) {
|
|
117
|
-
return this.sendMethod("sendPhoto", { photo }, extra);
|
|
118
|
-
}
|
|
119
|
-
async replyWithDocument(document, extra = {}) {
|
|
120
|
-
return this.sendMethod("sendDocument", { document }, extra);
|
|
121
|
-
}
|
|
122
|
-
async replyWithAudio(audio, extra = {}) {
|
|
123
|
-
return this.sendMethod("sendAudio", { audio }, extra);
|
|
124
|
-
}
|
|
125
|
-
async replyWithVideo(video, extra = {}) {
|
|
126
|
-
return this.sendMethod("sendVideo", { video }, extra);
|
|
127
|
-
}
|
|
128
|
-
async replyWithVoice(voice, extra = {}) {
|
|
129
|
-
return this.sendMethod("sendVoice", { voice }, extra);
|
|
130
|
-
}
|
|
131
|
-
async replyWithAnimation(animation, extra = {}) {
|
|
132
|
-
return this.sendMethod("sendAnimation", { animation }, extra);
|
|
133
|
-
}
|
|
134
|
-
async replyWithVideoNote(videoNote, extra = {}) {
|
|
135
|
-
return this.sendMethod("sendVideoNote", { video_note: videoNote }, extra);
|
|
136
|
-
}
|
|
137
|
-
async replyWithSticker(sticker, extra = {}) {
|
|
138
|
-
return this.sendMethod("sendSticker", { sticker }, extra);
|
|
139
|
-
}
|
|
140
|
-
async replyWithMediaGroup(media, extra = {}) {
|
|
141
|
-
return this.sendMethod("sendMediaGroup", { media }, extra);
|
|
142
|
-
}
|
|
143
|
-
async replyWithLocation(latitude, longitude, extra = {}) {
|
|
144
|
-
return this.sendMethod("sendLocation", { latitude, longitude }, extra);
|
|
145
|
-
}
|
|
146
|
-
async replyWithVenue(latitude, longitude, title, address, extra = {}) {
|
|
147
|
-
return this.sendMethod("sendVenue", { latitude, longitude, title, address }, extra);
|
|
148
|
-
}
|
|
149
|
-
async replyWithContact(phoneNumber, firstName, extra = {}) {
|
|
150
|
-
return this.sendMethod("sendContact", { phone_number: phoneNumber, first_name: firstName }, extra);
|
|
151
|
-
}
|
|
152
|
-
async replyWithPoll(question, options, extra = {}) {
|
|
153
|
-
return this.sendMethod("sendPoll", { question, options }, extra);
|
|
154
|
-
}
|
|
155
|
-
async replyWithDice(emoji, extra = {}) {
|
|
156
|
-
return this.sendMethod("sendDice", emoji === undefined ? {} : { emoji }, extra);
|
|
157
|
-
}
|
|
158
|
-
async sendChatAction(action, extra = {}) {
|
|
159
|
-
if (!this.chat)
|
|
160
|
-
throw new Error("Cannot send chat action without a chat in this update.");
|
|
161
|
-
return this.api.call("sendChatAction", { chat_id: this.chat.id, action, ...extra });
|
|
162
|
-
}
|
|
163
|
-
async delete() {
|
|
164
|
-
if (!this.chat || !this.message)
|
|
165
|
-
throw new Error("Cannot delete without a chat and message in this update.");
|
|
166
|
-
return this.api.methods.deleteMessage({ chat_id: this.chat.id, message_id: this.message.message_id });
|
|
167
|
-
}
|
|
168
|
-
async copy(fromChatId, messageId, extra = {}) { return this.api.call("copyMessage", { chat_id: this.chat?.id, from_chat_id: fromChatId, message_id: messageId, ...extra }); }
|
|
169
|
-
async forward(fromChatId, messageId, extra = {}) { return this.api.call("forwardMessage", { chat_id: this.chat?.id, from_chat_id: fromChatId, message_id: messageId, ...extra }); }
|
|
170
|
-
async pin(messageId = this.message?.message_id, extra = {}) { return this.api.call("pinChatMessage", { chat_id: this.chat?.id, message_id: messageId, ...extra }); }
|
|
171
|
-
async unpin(messageId = this.message?.message_id, extra = {}) { return this.api.call("unpinChatMessage", { chat_id: this.chat?.id, message_id: messageId, ...extra }); }
|
|
172
|
-
async react(reaction, extra = {}) { return this.api.call("setMessageReaction", { chat_id: this.chat?.id, message_id: this.message?.message_id, reaction, ...extra }); }
|
|
173
|
-
async answerCallbackQuery(text, extra = {}) { if (!this.callbackQuery)
|
|
174
|
-
throw new Error("No callback query in this update."); return this.api.methods.answerCallbackQuery({ callback_query_id: this.callbackQuery.id, text, ...extra }); }
|
|
175
|
-
async answerInlineQuery(results, extra = {}) { if (!this.inlineQuery)
|
|
176
|
-
throw new Error("No inline query in this update."); return this.api.call("answerInlineQuery", { inline_query_id: this.inlineQuery.id, results, ...extra }); }
|
|
177
|
-
async getChat() { if (!this.chat)
|
|
178
|
-
throw new Error("No chat in this update."); return this.api.methods.getChat({ chat_id: this.chat.id }); }
|
|
179
|
-
async getUserProfilePhotos(userId = this.from?.id, extra = {}) { if (!userId)
|
|
180
|
-
throw new Error("No user in this update."); return this.api.call("getUserProfilePhotos", { user_id: userId, ...extra }); }
|
|
181
|
-
async getFile(fileId) { return this.api.methods.getFile({ file_id: fileId }); }
|
|
182
|
-
/**
|
|
183
|
-
* Resolves `fileId` with `getFile` and downloads the raw bytes (see
|
|
184
|
-
* `Bot.downloadFile`). Pass `destination` to persist the bytes to a local
|
|
185
|
-
* file path. Prefer this over reading `file_path` manually — it throws
|
|
186
|
-
* precise `TelegramError`s when Telegram returns no path.
|
|
187
|
-
*/
|
|
188
|
-
async downloadFile(fileId, options = {}) {
|
|
189
|
-
const downloaded = await this.api.downloadFile(fileId, options.signal !== undefined ? { signal: options.signal } : {});
|
|
190
|
-
if (options.destination !== undefined) {
|
|
191
|
-
await (0, promises_1.writeFile)(options.destination, downloaded.bytes);
|
|
192
|
-
return { ...downloaded, savedTo: options.destination };
|
|
193
|
-
}
|
|
194
|
-
return downloaded;
|
|
195
|
-
}
|
|
196
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
197
|
-
// Admin & moderation (full Telegraf-parity surface; chat defaults to ctx.chat)
|
|
198
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
199
|
-
requireChatId() { if (this.chat?.id === undefined)
|
|
200
|
-
throw new Error("This update has no chat to act on."); return this.chat.id; }
|
|
201
|
-
async banChatMember(userId, untilDate, extra = {}) {
|
|
202
|
-
return this.api.call("banChatMember", { chat_id: this.requireChatId(), user_id: userId, ...(untilDate !== undefined ? { until_date: untilDate } : {}), ...extra });
|
|
203
|
-
}
|
|
204
|
-
async unbanChatMember(userId, onlyIfBanned, extra = {}) {
|
|
205
|
-
return this.api.call("unbanChatMember", { chat_id: this.requireChatId(), user_id: userId, ...(onlyIfBanned !== undefined ? { only_if_banned: onlyIfBanned } : {}), ...extra });
|
|
206
|
-
}
|
|
207
|
-
async restrictChatMember(userId, permissions, untilDate, extra = {}) {
|
|
208
|
-
return this.api.call("restrictChatMember", { chat_id: this.requireChatId(), user_id: userId, permissions, ...(untilDate !== undefined ? { until_date: untilDate } : {}), ...extra });
|
|
209
|
-
}
|
|
210
|
-
async promoteChatMember(userId, extra = {}) {
|
|
211
|
-
return this.api.call("promoteChatMember", { chat_id: this.requireChatId(), user_id: userId, ...extra });
|
|
212
|
-
}
|
|
213
|
-
async banChatSenderChat(senderChatId, extra = {}) {
|
|
214
|
-
return this.api.call("banChatSenderChat", { chat_id: this.requireChatId(), sender_chat_id: senderChatId, ...extra });
|
|
215
|
-
}
|
|
216
|
-
async unbanChatSenderChat(senderChatId, extra = {}) {
|
|
217
|
-
return this.api.call("unbanChatSenderChat", { chat_id: this.requireChatId(), sender_chat_id: senderChatId, ...extra });
|
|
218
|
-
}
|
|
219
|
-
// ── Chat management ──
|
|
220
|
-
async setChatTitle(title) { return this.api.call("setChatTitle", { chat_id: this.requireChatId(), title }); }
|
|
221
|
-
async setChatDescription(description) { return this.api.call("setChatDescription", { chat_id: this.requireChatId(), description }); }
|
|
222
|
-
async setChatPhoto(photo) { return this.api.call("setChatPhoto", { chat_id: this.requireChatId(), photo }); }
|
|
223
|
-
async deleteChatPhoto() { return this.api.call("deleteChatPhoto", { chat_id: this.requireChatId() }); }
|
|
224
|
-
async setChatPermissions(permissions, extra = {}) {
|
|
225
|
-
return this.api.call("setChatPermissions", { chat_id: this.requireChatId(), permissions, ...extra });
|
|
226
|
-
}
|
|
227
|
-
async leaveChat() { return this.api.call("leaveChat", { chat_id: this.requireChatId() }); }
|
|
228
|
-
async unpinAllChatMessages(extra = {}) { return this.api.call("unpinAllChatMessages", { chat_id: this.requireChatId(), ...extra }); }
|
|
229
|
-
async setChatStickerSet(stickerSetName) { return this.api.call("setChatStickerSet", { chat_id: this.requireChatId(), sticker_set_name: stickerSetName }); }
|
|
230
|
-
async deleteChatStickerSet() { return this.api.call("deleteChatStickerSet", { chat_id: this.requireChatId() }); }
|
|
231
|
-
// ── Chat & member info ──
|
|
232
|
-
async getChatAdministrators() { return this.api.call("getChatAdministrators", { chat_id: this.requireChatId() }); }
|
|
233
|
-
async getChatMemberCount() { return this.api.call("getChatMemberCount", { chat_id: this.requireChatId() }); }
|
|
234
|
-
async getChatMember(userId) { return this.api.call("getChatMember", { chat_id: this.requireChatId(), user_id: userId }); }
|
|
235
|
-
// ── Invite links ──
|
|
236
|
-
async exportChatInviteLink() { return this.api.call("exportChatInviteLink", { chat_id: this.requireChatId() }); }
|
|
237
|
-
async createChatInviteLink(extra = {}) { return this.api.call("createChatInviteLink", { chat_id: this.requireChatId(), ...extra }); }
|
|
238
|
-
async editChatInviteLink(inviteLink, extra = {}) { return this.api.call("editChatInviteLink", { chat_id: this.requireChatId(), invite_link: inviteLink, ...extra }); }
|
|
239
|
-
async revokeChatInviteLink(inviteLink) { return this.api.call("revokeChatInviteLink", { chat_id: this.requireChatId(), invite_link: inviteLink }); }
|
|
240
|
-
// ── Join requests ──
|
|
241
|
-
async approveChatJoinRequest(userId) { return this.api.call("approveChatJoinRequest", { chat_id: this.requireChatId(), user_id: userId }); }
|
|
242
|
-
async declineChatJoinRequest(userId) { return this.api.call("declineChatJoinRequest", { chat_id: this.requireChatId(), user_id: userId }); }
|
|
243
|
-
// ── Polls, live location, games, invoices ──
|
|
244
|
-
async replyWithQuiz(question, options, extra = {}) {
|
|
245
|
-
return this.sendMethod("sendPoll", { question, options, type: "quiz" }, extra);
|
|
246
|
-
}
|
|
247
|
-
async stopPoll(messageId = this.message?.message_id, extra = {}) {
|
|
248
|
-
if (messageId === undefined)
|
|
249
|
-
throw new Error("Cannot stop a poll without a message id.");
|
|
250
|
-
return this.api.call("stopPoll", { chat_id: this.requireChatId(), message_id: messageId, ...extra });
|
|
251
|
-
}
|
|
252
|
-
async editMessageLiveLocation(latitude, longitude, extra = {}) {
|
|
253
|
-
return this.api.call("editMessageLiveLocation", { chat_id: this.chat?.id, message_id: this.message?.message_id, latitude, longitude, ...extra });
|
|
254
|
-
}
|
|
255
|
-
async stopMessageLiveLocation(extra = {}) {
|
|
256
|
-
return this.api.call("stopMessageLiveLocation", { chat_id: this.chat?.id, message_id: this.message?.message_id, ...extra });
|
|
257
|
-
}
|
|
258
|
-
async replyWithGame(gameShortName, extra = {}) {
|
|
259
|
-
return this.sendMethod("sendGame", { game_short_name: gameShortName }, extra);
|
|
260
|
-
}
|
|
261
|
-
async setGameScore(userId, score, extra = {}) {
|
|
262
|
-
return this.api.call("setGameScore", { chat_id: this.chat?.id, message_id: this.message?.message_id, user_id: userId, score, ...extra });
|
|
263
|
-
}
|
|
264
|
-
async getGameHighScores(userId = this.from?.id, extra = {}) {
|
|
265
|
-
if (userId === undefined)
|
|
266
|
-
throw new Error("No user in this update; pass a user_id explicitly.");
|
|
267
|
-
return this.api.call("getGameHighScores", { chat_id: this.chat?.id, message_id: this.message?.message_id, user_id: userId, ...extra });
|
|
268
|
-
}
|
|
269
|
-
async replyWithInvoice(title, description, payload, providerToken, currency, prices, extra = {}) {
|
|
270
|
-
return this.sendMethod("sendInvoice", { title, description, payload, provider_token: providerToken, currency, prices }, extra);
|
|
271
|
-
}
|
|
272
|
-
// ── Forum topics ──
|
|
273
|
-
async createForumTopic(name, extra = {}) { return this.api.call("createForumTopic", { chat_id: this.requireChatId(), name, ...extra }); }
|
|
274
|
-
async editForumTopic(extra = {}) {
|
|
275
|
-
return this.api.call("editForumTopic", { chat_id: this.requireChatId(), message_thread_id: this.message?.message_thread_id, ...extra });
|
|
276
|
-
}
|
|
277
|
-
async closeForumTopic(messageThreadId = this.message?.message_thread_id) {
|
|
278
|
-
if (messageThreadId === undefined)
|
|
279
|
-
throw new Error("Cannot act on a forum topic without a message_thread_id.");
|
|
280
|
-
return this.api.call("closeForumTopic", { chat_id: this.requireChatId(), message_thread_id: messageThreadId });
|
|
281
|
-
}
|
|
282
|
-
async reopenForumTopic(messageThreadId = this.message?.message_thread_id) {
|
|
283
|
-
if (messageThreadId === undefined)
|
|
284
|
-
throw new Error("Cannot act on a forum topic without a message_thread_id.");
|
|
285
|
-
return this.api.call("reopenForumTopic", { chat_id: this.requireChatId(), message_thread_id: messageThreadId });
|
|
286
|
-
}
|
|
287
|
-
async deleteForumTopic(messageThreadId = this.message?.message_thread_id) {
|
|
288
|
-
if (messageThreadId === undefined)
|
|
289
|
-
throw new Error("Cannot act on a forum topic without a message_thread_id.");
|
|
290
|
-
return this.api.call("deleteForumTopic", { chat_id: this.requireChatId(), message_thread_id: messageThreadId });
|
|
291
|
-
}
|
|
292
|
-
async unpinAllForumTopicMessages(messageThreadId = this.message?.message_thread_id) {
|
|
293
|
-
if (messageThreadId === undefined)
|
|
294
|
-
throw new Error("Cannot act on a forum topic without a message_thread_id.");
|
|
295
|
-
return this.api.call("unpinAllForumTopicMessages", { chat_id: this.requireChatId(), message_thread_id: messageThreadId });
|
|
296
|
-
}
|
|
297
|
-
async getForumTopicIconStickers() { return this.api.call("getForumTopicIconStickers", {}); }
|
|
298
|
-
async editGeneralForumTopic(name) { return this.api.call("editGeneralForumTopic", { chat_id: this.requireChatId(), name }); }
|
|
299
|
-
async closeGeneralForumTopic() { return this.api.call("closeGeneralForumTopic", { chat_id: this.requireChatId() }); }
|
|
300
|
-
async reopenGeneralForumTopic() { return this.api.call("reopenGeneralForumTopic", { chat_id: this.requireChatId() }); }
|
|
301
|
-
async hideGeneralForumTopic() { return this.api.call("hideGeneralForumTopic", { chat_id: this.requireChatId() }); }
|
|
302
|
-
async unhideGeneralForumTopic() { return this.api.call("unhideGeneralForumTopic", { chat_id: this.requireChatId() }); }
|
|
303
|
-
withReplyMarkup(markup) { this.state.reply_markup = markup; return this; }
|
|
304
|
-
}
|
|
305
|
-
exports.Context = Context;
|