@xbibzlibrary/telebibz 3.1.1 → 3.1.3
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 +7 -0
- package/LICENSE +1 -1
- package/NOTICE.md +15 -8
- package/README.id.md +85 -16
- package/README.md +84 -16
- package/examples/08-rich-message.js +34 -0
- package/index.d.ts +300 -96
- package/index.js +8 -2
- package/lib/api.js +20 -6
- package/lib/composer.js +14 -3
- package/lib/context.js +85 -25
- package/lib/file.js +8 -1
- package/lib/inline-query.js +6 -1
- package/lib/logger.js +44 -14
- package/lib/ratelimit.js +16 -3
- package/lib/rich.js +170 -0
- package/lib/runner.js +14 -5
- package/lib/session.js +12 -4
- package/lib/telebibz.js +40 -24
- package/lib/telegram-methods.js +192 -0
- package/package.json +14 -10
- package/test/audit.test.js +320 -0
- package/test/types.test.ts +40 -0
- package/types/telegram-bot-api/LICENSE +21 -0
- package/types/telegram-bot-api/api.d.ts +22 -0
- package/types/telegram-bot-api/checklist.d.ts +72 -0
- package/types/telegram-bot-api/inline.d.ts +692 -0
- package/types/telegram-bot-api/langs.d.ts +193 -0
- package/types/telegram-bot-api/manage.d.ts +1153 -0
- package/types/telegram-bot-api/markup.d.ts +278 -0
- package/types/telegram-bot-api/message.d.ts +1557 -0
- package/types/telegram-bot-api/methods.d.ts +2860 -0
- package/types/telegram-bot-api/mod.d.ts +14 -0
- package/types/telegram-bot-api/passport.d.ts +163 -0
- package/types/telegram-bot-api/payment.d.ts +576 -0
- package/types/telegram-bot-api/rich.d.ts +1198 -0
- package/types/telegram-bot-api/settings.d.ts +120 -0
- package/types/telegram-bot-api/story.d.ts +89 -0
- package/types/telegram-bot-api/update.d.ts +86 -0
package/lib/telebibz.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// lib/telebibz.js —
|
|
1
|
+
// lib/telebibz.js — lifecycle bot, komposisi middleware, polling, dan webhook.
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const { makeApi } = require('./api');
|
|
@@ -13,10 +13,14 @@ const log = require('./logger');
|
|
|
13
13
|
const { humanize } = require('./errors');
|
|
14
14
|
const { broadcast } = require('./broadcast');
|
|
15
15
|
|
|
16
|
+
// Semua tipe Update di Bot API 10.3 (2026-08-24), termasuk tipe baru.
|
|
16
17
|
const DEFAULT_UPDATES = [
|
|
17
|
-
'message', 'edited_message', '
|
|
18
|
-
'
|
|
19
|
-
'
|
|
18
|
+
'message', 'edited_message', 'channel_post', 'edited_channel_post',
|
|
19
|
+
'business_connection', 'business_message', 'edited_business_message', 'deleted_business_messages',
|
|
20
|
+
'guest_message', 'message_reaction', 'message_reaction_count', 'inline_query',
|
|
21
|
+
'chosen_inline_result', 'callback_query', 'shipping_query', 'pre_checkout_query',
|
|
22
|
+
'purchased_paid_media', 'poll', 'poll_answer', 'my_chat_member', 'chat_member',
|
|
23
|
+
'chat_join_request', 'chat_boost', 'removed_chat_boost', 'stopped_message_generation',
|
|
20
24
|
];
|
|
21
25
|
|
|
22
26
|
class TeleBibz {
|
|
@@ -33,7 +37,7 @@ class TeleBibz {
|
|
|
33
37
|
}
|
|
34
38
|
this.opts = opts;
|
|
35
39
|
this.token = token;
|
|
36
|
-
this.api = makeApi(token, opts.transport);
|
|
40
|
+
this.api = makeApi(token, opts.transport, opts);
|
|
37
41
|
this.botInfo = undefined;
|
|
38
42
|
|
|
39
43
|
this._handlers = new Composer(); // composer publik (use/on/cmd/dll)
|
|
@@ -44,11 +48,11 @@ class TeleBibz {
|
|
|
44
48
|
this.printError(err, ctx);
|
|
45
49
|
};
|
|
46
50
|
|
|
47
|
-
// Pohon eksekusi: session → wizard → user handlers
|
|
51
|
+
// Pohon eksekusi: session → wizard → user handlers di dalam error boundary.
|
|
48
52
|
this._root = new Composer()
|
|
49
53
|
.use(session(opts.session || {}))
|
|
50
54
|
.use(wizard.middleware());
|
|
51
|
-
this._safe = this._root.errorBoundary(this._report);
|
|
55
|
+
this._safe = this._root.errorBoundary(this._report, this._handlers.middleware());
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
/* ---------- shortcut publik ---------- */
|
|
@@ -104,18 +108,11 @@ class TeleBibz {
|
|
|
104
108
|
|
|
105
109
|
/** Tangani SATU update mentah (webhook/serverless/test). */
|
|
106
110
|
async handleUpdate(update) {
|
|
107
|
-
if (this._wired !== true) this._wire();
|
|
108
111
|
const ctx = new Context(update, this.api, this.botInfo);
|
|
109
112
|
try { await this._root.run(ctx); }
|
|
110
113
|
catch (err) { await this._report({ error: err, ctx }); }
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
_wire() {
|
|
114
|
-
this._wired = true;
|
|
115
|
-
// Pasang handler publik SETELAH boundary agar semuanya terlindungi
|
|
116
|
-
this._root.use(this._handlers.middleware());
|
|
117
|
-
}
|
|
118
|
-
|
|
119
116
|
/** Nyalakan long polling (dengan retry 409 & backoff jaringan). */
|
|
120
117
|
async launch(launchOpts = {}) {
|
|
121
118
|
await this.init();
|
|
@@ -124,8 +121,7 @@ class TeleBibz {
|
|
|
124
121
|
log.banner('🤖 TeleBibz ON', [
|
|
125
122
|
`bot : @${me.username} (id ${me.id})`,
|
|
126
123
|
'mode : long-polling',
|
|
127
|
-
`library : telebibz ${require('../package.json').version} (
|
|
128
|
-
'brand : //—Xbibz Official—//',
|
|
124
|
+
`library : telebibz ${require('../package.json').version} (Node.js)`,
|
|
129
125
|
]);
|
|
130
126
|
log.ok('menunggu update… (Ctrl+C untuk berhenti)');
|
|
131
127
|
}
|
|
@@ -134,9 +130,9 @@ class TeleBibz {
|
|
|
134
130
|
api: this.api,
|
|
135
131
|
handleUpdate: (u) => this.handleUpdate(u),
|
|
136
132
|
allowedUpdates: this.opts.allowedUpdates || DEFAULT_UPDATES,
|
|
137
|
-
dropPending:
|
|
133
|
+
dropPending: launchOpts.dropPending ?? this.opts.dropPending ?? false,
|
|
138
134
|
shouldStop: () => this._stopping,
|
|
139
|
-
conflictDelay: launchOpts.conflictDelay
|
|
135
|
+
conflictDelay: launchOpts.conflictDelay ?? 5000,
|
|
140
136
|
onConflict: () => { if (!this.opts.silent) log.warn('bot lain masih polling (409) — coba lagi 5 detik…'); },
|
|
141
137
|
onFatal: (err) => this._report({ error: err }),
|
|
142
138
|
});
|
|
@@ -154,17 +150,37 @@ class TeleBibz {
|
|
|
154
150
|
get runPromise() { return this._runPromise; }
|
|
155
151
|
|
|
156
152
|
/**
|
|
157
|
-
* Handler webhook gaya Node/Express:
|
|
158
|
-
* const
|
|
159
|
-
*
|
|
160
|
-
* — framework mana pun: (req, res) pasangan Request/Response Node.
|
|
153
|
+
* Handler webhook gaya Node/Express. Secret token (disarankan Telegram) opsional:
|
|
154
|
+
* const handler = bot.webhook({ secretToken: process.env.TG_WEBHOOK_SECRET });
|
|
155
|
+
* Terima (req, res) Node murni; body dibatasi agar endpoint tidak menerima payload tak terbatas.
|
|
161
156
|
*/
|
|
162
|
-
webhook() {
|
|
157
|
+
webhook(webhookOpts = {}) {
|
|
158
|
+
const secretToken = webhookOpts.secretToken;
|
|
159
|
+
const maxBodyBytes = webhookOpts.maxBodyBytes ?? 1024 * 1024;
|
|
160
|
+
if (!Number.isSafeInteger(maxBodyBytes) || maxBodyBytes <= 0) throw new RangeError('webhook: maxBodyBytes harus > 0');
|
|
161
|
+
if (secretToken !== undefined && (typeof secretToken !== 'string' || !/^[A-Za-z0-9_-]{1,256}$/.test(secretToken))) {
|
|
162
|
+
throw new TypeError('webhook: secretToken harus 1–256 karakter A-Z, a-z, 0-9, _ atau -');
|
|
163
|
+
}
|
|
163
164
|
return async (req, res) => {
|
|
165
|
+
if (req.method && req.method !== 'POST') { res.statusCode = 405; res.end('method not allowed'); return; }
|
|
166
|
+
if (secretToken !== undefined) {
|
|
167
|
+
const received = req.headers && req.headers['x-telegram-bot-api-secret-token'];
|
|
168
|
+
const expectedBuf = Buffer.from(String(secretToken));
|
|
169
|
+
const receivedBuf = Buffer.from(typeof received === 'string' ? received : '');
|
|
170
|
+
const valid = expectedBuf.length === receivedBuf.length && require('crypto').timingSafeEqual(expectedBuf, receivedBuf);
|
|
171
|
+
if (!valid) { res.statusCode = 401; res.end('unauthorized'); return; }
|
|
172
|
+
}
|
|
164
173
|
try {
|
|
165
174
|
const chunks = [];
|
|
166
|
-
|
|
175
|
+
let size = 0;
|
|
176
|
+
for await (const c of req) {
|
|
177
|
+
const chunk = Buffer.from(c);
|
|
178
|
+
size += chunk.length;
|
|
179
|
+
if (size > maxBodyBytes) { res.statusCode = 413; res.end('payload too large'); return; }
|
|
180
|
+
chunks.push(chunk);
|
|
181
|
+
}
|
|
167
182
|
const update = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
183
|
+
if (!update || typeof update !== 'object' || Array.isArray(update)) throw new Error('invalid update');
|
|
168
184
|
await this.handleUpdate(update);
|
|
169
185
|
res.statusCode = 200; res.setHeader('Content-Type', 'application/json'); res.end('{}');
|
|
170
186
|
} catch (e) { res.statusCode = 400; res.end('bad request'); }
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Telegram Bot API method names, synchronized with @grammyjs/types v5.0.0 (Bot API 10.3).
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const TELEGRAM_API_METHODS = Object.freeze([
|
|
5
|
+
'getUpdates',
|
|
6
|
+
'setWebhook',
|
|
7
|
+
'deleteWebhook',
|
|
8
|
+
'sendMessage',
|
|
9
|
+
'sendRichMessage',
|
|
10
|
+
'forwardMessage',
|
|
11
|
+
'forwardMessages',
|
|
12
|
+
'copyMessage',
|
|
13
|
+
'copyMessages',
|
|
14
|
+
'sendPhoto',
|
|
15
|
+
'sendLivePhoto',
|
|
16
|
+
'sendAudio',
|
|
17
|
+
'sendDocument',
|
|
18
|
+
'sendVideo',
|
|
19
|
+
'sendAnimation',
|
|
20
|
+
'sendVoice',
|
|
21
|
+
'sendVideoNote',
|
|
22
|
+
'sendPaidMedia',
|
|
23
|
+
'sendMediaGroup',
|
|
24
|
+
'sendLocation',
|
|
25
|
+
'editMessageLiveLocation',
|
|
26
|
+
'stopMessageLiveLocation',
|
|
27
|
+
'sendVenue',
|
|
28
|
+
'sendContact',
|
|
29
|
+
'sendPoll',
|
|
30
|
+
'sendChecklist',
|
|
31
|
+
'editMessageChecklist',
|
|
32
|
+
'sendDice',
|
|
33
|
+
'sendMessageDraft',
|
|
34
|
+
'sendRichMessageDraft',
|
|
35
|
+
'sendChatAction',
|
|
36
|
+
'setMessageReaction',
|
|
37
|
+
'getUserProfilePhotos',
|
|
38
|
+
'getUserProfileAudios',
|
|
39
|
+
'setUserEmojiStatus',
|
|
40
|
+
'getFile',
|
|
41
|
+
'banChatMember',
|
|
42
|
+
'unbanChatMember',
|
|
43
|
+
'restrictChatMember',
|
|
44
|
+
'promoteChatMember',
|
|
45
|
+
'setChatAdministratorCustomTitle',
|
|
46
|
+
'setChatMemberTag',
|
|
47
|
+
'banChatSenderChat',
|
|
48
|
+
'unbanChatSenderChat',
|
|
49
|
+
'setChatPermissions',
|
|
50
|
+
'exportChatInviteLink',
|
|
51
|
+
'createChatInviteLink',
|
|
52
|
+
'editChatInviteLink',
|
|
53
|
+
'createChatSubscriptionInviteLink',
|
|
54
|
+
'editChatSubscriptionInviteLink',
|
|
55
|
+
'revokeChatInviteLink',
|
|
56
|
+
'approveChatJoinRequest',
|
|
57
|
+
'declineChatJoinRequest',
|
|
58
|
+
'answerChatJoinRequestQuery',
|
|
59
|
+
'sendChatJoinRequestWebApp',
|
|
60
|
+
'approveSuggestedPost',
|
|
61
|
+
'declineSuggestedPost',
|
|
62
|
+
'setChatPhoto',
|
|
63
|
+
'deleteChatPhoto',
|
|
64
|
+
'setChatTitle',
|
|
65
|
+
'setChatDescription',
|
|
66
|
+
'pinChatMessage',
|
|
67
|
+
'unpinChatMessage',
|
|
68
|
+
'unpinAllChatMessages',
|
|
69
|
+
'leaveChat',
|
|
70
|
+
'getChat',
|
|
71
|
+
'getChatAdministrators',
|
|
72
|
+
'getChatMemberCount',
|
|
73
|
+
'getChatMember',
|
|
74
|
+
'getUserPersonalChatMessages',
|
|
75
|
+
'setChatStickerSet',
|
|
76
|
+
'deleteChatStickerSet',
|
|
77
|
+
'createForumTopic',
|
|
78
|
+
'editForumTopic',
|
|
79
|
+
'closeForumTopic',
|
|
80
|
+
'reopenForumTopic',
|
|
81
|
+
'deleteForumTopic',
|
|
82
|
+
'unpinAllForumTopicMessages',
|
|
83
|
+
'editGeneralForumTopic',
|
|
84
|
+
'closeGeneralForumTopic',
|
|
85
|
+
'reopenGeneralForumTopic',
|
|
86
|
+
'hideGeneralForumTopic',
|
|
87
|
+
'unhideGeneralForumTopic',
|
|
88
|
+
'unpinAllGeneralForumTopicMessages',
|
|
89
|
+
'answerCallbackQuery',
|
|
90
|
+
'answerGuestQuery',
|
|
91
|
+
'getUserChatBoosts',
|
|
92
|
+
'getUserGifts',
|
|
93
|
+
'getChatGifts',
|
|
94
|
+
'getBusinessConnection',
|
|
95
|
+
'getManagedBotToken',
|
|
96
|
+
'replaceManagedBotToken',
|
|
97
|
+
'getManagedBotAccessSettings',
|
|
98
|
+
'setManagedBotAccessSettings',
|
|
99
|
+
'setMyCommands',
|
|
100
|
+
'deleteMyCommands',
|
|
101
|
+
'getMyCommands',
|
|
102
|
+
'setMyName',
|
|
103
|
+
'getMyName',
|
|
104
|
+
'setMyDescription',
|
|
105
|
+
'getMyDescription',
|
|
106
|
+
'setMyShortDescription',
|
|
107
|
+
'getMyShortDescription',
|
|
108
|
+
'setMyProfilePhoto',
|
|
109
|
+
'setChatMenuButton',
|
|
110
|
+
'getChatMenuButton',
|
|
111
|
+
'setMyDefaultAdministratorRights',
|
|
112
|
+
'getMyDefaultAdministratorRights',
|
|
113
|
+
'editMessageText',
|
|
114
|
+
'editMessageCaption',
|
|
115
|
+
'editMessageMedia',
|
|
116
|
+
'editMessageReplyMarkup',
|
|
117
|
+
'stopPoll',
|
|
118
|
+
'editEphemeralMessageText',
|
|
119
|
+
'editEphemeralMessageMedia',
|
|
120
|
+
'editEphemeralMessageCaption',
|
|
121
|
+
'editEphemeralMessageReplyMarkup',
|
|
122
|
+
'deleteMessage',
|
|
123
|
+
'deleteMessages',
|
|
124
|
+
'deleteEphemeralMessage',
|
|
125
|
+
'deleteMessageReaction',
|
|
126
|
+
'deleteAllMessageReactions',
|
|
127
|
+
'deleteBusinessMessages',
|
|
128
|
+
'setBusinessAccountName',
|
|
129
|
+
'setBusinessAccountUsername',
|
|
130
|
+
'setBusinessAccountBio',
|
|
131
|
+
'setBusinessAccountProfilePhoto',
|
|
132
|
+
'removeBusinessAccountProfilePhoto',
|
|
133
|
+
'setBusinessAccountGiftSettings',
|
|
134
|
+
'getBusinessAccountStarBalance',
|
|
135
|
+
'transferBusinessAccountStars',
|
|
136
|
+
'getBusinessAccountGifts',
|
|
137
|
+
'convertGiftToStars',
|
|
138
|
+
'upgradeGift',
|
|
139
|
+
'transferGift',
|
|
140
|
+
'postStory',
|
|
141
|
+
'repostStory',
|
|
142
|
+
'editStory',
|
|
143
|
+
'deleteStory',
|
|
144
|
+
'sendSticker',
|
|
145
|
+
'getStickerSet',
|
|
146
|
+
'getCustomEmojiStickers',
|
|
147
|
+
'uploadStickerFile',
|
|
148
|
+
'createNewStickerSet',
|
|
149
|
+
'addStickerToSet',
|
|
150
|
+
'setStickerPositionInSet',
|
|
151
|
+
'deleteStickerFromSet',
|
|
152
|
+
'replaceStickerInSet',
|
|
153
|
+
'setStickerEmojiList',
|
|
154
|
+
'setStickerKeywords',
|
|
155
|
+
'setStickerMaskPosition',
|
|
156
|
+
'setStickerSetTitle',
|
|
157
|
+
'deleteStickerSet',
|
|
158
|
+
'setStickerSetThumbnail',
|
|
159
|
+
'setCustomEmojiStickerSetThumbnail',
|
|
160
|
+
'sendGift',
|
|
161
|
+
'giftPremiumSubscription',
|
|
162
|
+
'answerInlineQuery',
|
|
163
|
+
'answerWebAppQuery',
|
|
164
|
+
'savePreparedInlineMessage',
|
|
165
|
+
'savePreparedKeyboardButton',
|
|
166
|
+
'sendInvoice',
|
|
167
|
+
'createInvoiceLink',
|
|
168
|
+
'answerShippingQuery',
|
|
169
|
+
'answerPreCheckoutQuery',
|
|
170
|
+
'getStarTransactions',
|
|
171
|
+
'refundStarPayment',
|
|
172
|
+
'editUserStarSubscription',
|
|
173
|
+
'verifyUser',
|
|
174
|
+
'verifyChat',
|
|
175
|
+
'removeUserVerification',
|
|
176
|
+
'removeChatVerification',
|
|
177
|
+
'readBusinessMessage',
|
|
178
|
+
'setPassportDataErrors',
|
|
179
|
+
'sendGame',
|
|
180
|
+
'setGameScore',
|
|
181
|
+
'getGameHighScores',
|
|
182
|
+
'getWebhookInfo',
|
|
183
|
+
'getMe',
|
|
184
|
+
'logOut',
|
|
185
|
+
'close',
|
|
186
|
+
'getForumTopicIconStickers',
|
|
187
|
+
'removeMyProfilePhoto',
|
|
188
|
+
'getMyStarBalance',
|
|
189
|
+
'getAvailableGifts',
|
|
190
|
+
]);
|
|
191
|
+
|
|
192
|
+
module.exports = { TELEGRAM_API_METHODS };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xbibzlibrary/telebibz",
|
|
3
|
-
"version": "3.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.1.3",
|
|
4
|
+
"description": "Telegram Bot API 10.3 framework: all 185 methods with typed payloads, rich messages, live photos, drafts, ephemeral messages, inline queries, sessions, webhooks, menus and wizards. Xbibz Technology ID",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"license": "MIT",
|
|
9
|
-
"author": "Xbibz
|
|
9
|
+
"author": "Xbibz Technology ID",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/XbibzOfficial777/telebibz.git"
|
|
12
|
+
"url": "git+https://github.com/XbibzOfficial777/telebibz.git"
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/XbibzOfficial777/telebibz#readme",
|
|
15
15
|
"keywords": [
|
|
@@ -23,30 +23,34 @@
|
|
|
23
23
|
"broadcast",
|
|
24
24
|
"indonesia",
|
|
25
25
|
"nodejs",
|
|
26
|
-
"
|
|
27
|
-
"tanpa-dependency"
|
|
26
|
+
"telegram-bot-library"
|
|
28
27
|
],
|
|
29
28
|
"engines": {
|
|
30
29
|
"node": ">=18"
|
|
31
30
|
},
|
|
32
31
|
"dependencies": {
|
|
33
32
|
"axios": "^1.20.0",
|
|
34
|
-
"
|
|
33
|
+
"debug": "^4.4.3",
|
|
35
34
|
"https-proxy-agent": "^9.1.0",
|
|
36
|
-
"
|
|
35
|
+
"mime-types": "^3.0.2"
|
|
37
36
|
},
|
|
38
37
|
"scripts": {
|
|
39
|
-
"test": "node test/all.test.js"
|
|
38
|
+
"test": "node test/all.test.js && node test/audit.test.js",
|
|
39
|
+
"typecheck": "tsc --project tsconfig.types.json"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"index.js",
|
|
43
43
|
"index.d.ts",
|
|
44
44
|
"lib/",
|
|
45
|
+
"types/telegram-bot-api/",
|
|
45
46
|
"examples/",
|
|
46
47
|
"test/",
|
|
47
48
|
"README.md",
|
|
48
49
|
"LICENSE",
|
|
49
50
|
"NOTICE.md",
|
|
50
51
|
"CHANGELOG.md"
|
|
51
|
-
]
|
|
52
|
+
],
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"typescript": "^7.0.2"
|
|
55
|
+
}
|
|
52
56
|
}
|