@velliajs/telegram 0.0.1-security → 1.0.0
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.
Potentially problematic release.
This version of @velliajs/telegram might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/filters.d.ts +1 -0
- package/filters.js +1 -0
- package/format.d.ts +1 -0
- package/format.js +1 -0
- package/future.d.ts +1 -0
- package/future.js +1 -0
- package/lib/button.js +101 -0
- package/lib/cli.mjs +105 -0
- package/lib/composer.js +582 -0
- package/lib/context.js +1219 -0
- package/lib/core/helpers/args.js +58 -0
- package/lib/core/helpers/check.js +56 -0
- package/lib/core/helpers/compact.js +17 -0
- package/lib/core/helpers/deunionize.js +13 -0
- package/lib/core/helpers/formatting.js +91 -0
- package/lib/core/helpers/util.js +50 -0
- package/lib/core/network/client.js +320 -0
- package/lib/core/network/error.js +21 -0
- package/lib/core/network/multipart-stream.js +61 -0
- package/lib/core/network/polling.js +87 -0
- package/lib/core/network/webhook.js +54 -0
- package/lib/core/types/typegram.js +27 -0
- package/lib/filters.js +69 -0
- package/lib/format.js +38 -0
- package/lib/future.js +150 -0
- package/lib/index.js +48 -0
- package/lib/input.js +61 -0
- package/lib/markup.js +111 -0
- package/lib/middleware.js +2 -0
- package/lib/reactions.js +85 -0
- package/lib/router.js +46 -0
- package/lib/scenes/base.js +39 -0
- package/lib/scenes/context.js +104 -0
- package/lib/scenes/index.js +21 -0
- package/lib/scenes/stage.js +49 -0
- package/lib/scenes/wizard/context.js +31 -0
- package/lib/scenes/wizard/index.js +45 -0
- package/lib/scenes.js +17 -0
- package/lib/session.js +166 -0
- package/lib/telegraf.js +287 -0
- package/lib/telegram-types.js +6 -0
- package/lib/telegram.js +1240 -0
- package/lib/types.js +2 -0
- package/lib/utils.js +5 -0
- package/markup.d.ts +1 -0
- package/markup.js +1 -0
- package/package.json +130 -3
- package/scenes.d.ts +1 -0
- package/scenes.js +1 -0
- package/session.d.ts +1 -0
- package/session.js +1 -0
- package/src/button.ts +182 -0
- package/src/composer.ts +1008 -0
- package/src/context.ts +1663 -0
- package/src/core/helpers/args.ts +63 -0
- package/src/core/helpers/check.ts +71 -0
- package/src/core/helpers/compact.ts +18 -0
- package/src/core/helpers/deunionize.ts +26 -0
- package/src/core/helpers/formatting.ts +119 -0
- package/src/core/helpers/util.ts +96 -0
- package/src/core/network/client.ts +396 -0
- package/src/core/network/error.ts +29 -0
- package/src/core/network/multipart-stream.ts +45 -0
- package/src/core/network/polling.ts +94 -0
- package/src/core/network/webhook.ts +58 -0
- package/src/core/types/typegram.ts +54 -0
- package/src/filters.ts +109 -0
- package/src/format.ts +110 -0
- package/src/future.ts +213 -0
- package/src/index.ts +17 -0
- package/src/input.ts +59 -0
- package/src/markup.ts +142 -0
- package/src/middleware.ts +24 -0
- package/src/reactions.ts +119 -0
- package/src/router.ts +55 -0
- package/src/scenes/base.ts +52 -0
- package/src/scenes/context.ts +136 -0
- package/src/scenes/index.ts +21 -0
- package/src/scenes/stage.ts +71 -0
- package/src/scenes/wizard/context.ts +58 -0
- package/src/scenes/wizard/index.ts +63 -0
- package/src/scenes.ts +1 -0
- package/src/session.ts +204 -0
- package/src/telegraf.ts +424 -0
- package/src/telegram-types.ts +219 -0
- package/src/telegram.ts +1635 -0
- package/src/types.ts +2 -0
- package/src/utils.ts +1 -0
- package/types.d.ts +1 -0
- package/types.js +1 -0
- package/typings/button.d.ts +36 -0
- package/typings/button.d.ts.map +1 -0
- package/typings/composer.d.ts +227 -0
- package/typings/composer.d.ts.map +1 -0
- package/typings/context.d.ts +659 -0
- package/typings/context.d.ts.map +1 -0
- package/typings/core/helpers/args.d.ts +11 -0
- package/typings/core/helpers/args.d.ts.map +1 -0
- package/typings/core/helpers/check.d.ts +56 -0
- package/typings/core/helpers/check.d.ts.map +1 -0
- package/typings/core/helpers/compact.d.ts +4 -0
- package/typings/core/helpers/compact.d.ts.map +1 -0
- package/typings/core/helpers/deunionize.d.ts +18 -0
- package/typings/core/helpers/deunionize.d.ts.map +1 -0
- package/typings/core/helpers/formatting.d.ts +30 -0
- package/typings/core/helpers/formatting.d.ts.map +1 -0
- package/typings/core/helpers/util.d.ts +27 -0
- package/typings/core/helpers/util.d.ts.map +1 -0
- package/typings/core/network/client.d.ts +55 -0
- package/typings/core/network/client.d.ts.map +1 -0
- package/typings/core/network/error.d.ts +16 -0
- package/typings/core/network/error.d.ts.map +1 -0
- package/typings/core/network/multipart-stream.d.ts +20 -0
- package/typings/core/network/multipart-stream.d.ts.map +1 -0
- package/typings/core/network/polling.d.ts +16 -0
- package/typings/core/network/polling.d.ts.map +1 -0
- package/typings/core/network/webhook.d.ts +7 -0
- package/typings/core/network/webhook.d.ts.map +1 -0
- package/typings/core/types/typegram.d.ts +45 -0
- package/typings/core/types/typegram.d.ts.map +1 -0
- package/typings/filters.d.ts +18 -0
- package/typings/filters.d.ts.map +1 -0
- package/typings/format.d.ts +22 -0
- package/typings/format.d.ts.map +1 -0
- package/typings/future.d.ts +12 -0
- package/typings/future.d.ts.map +1 -0
- package/typings/index.d.ts +15 -0
- package/typings/index.d.ts.map +1 -0
- package/typings/input.d.ts +61 -0
- package/typings/input.d.ts.map +1 -0
- package/typings/markup.d.ts +27 -0
- package/typings/markup.d.ts.map +1 -0
- package/typings/middleware.d.ts +8 -0
- package/typings/middleware.d.ts.map +1 -0
- package/typings/reactions.d.ts +32 -0
- package/typings/reactions.d.ts.map +1 -0
- package/typings/router.d.ts +21 -0
- package/typings/router.d.ts.map +1 -0
- package/typings/scenes/base.d.ts +22 -0
- package/typings/scenes/base.d.ts.map +1 -0
- package/typings/scenes/context.d.ts +36 -0
- package/typings/scenes/context.d.ts.map +1 -0
- package/typings/scenes/index.d.ts +11 -0
- package/typings/scenes/index.d.ts.map +1 -0
- package/typings/scenes/stage.d.ts +24 -0
- package/typings/scenes/stage.d.ts.map +1 -0
- package/typings/scenes/wizard/context.d.ts +29 -0
- package/typings/scenes/wizard/context.d.ts.map +1 -0
- package/typings/scenes/wizard/index.d.ts +16 -0
- package/typings/scenes/wizard/index.d.ts.map +1 -0
- package/typings/scenes.d.ts +2 -0
- package/typings/scenes.d.ts.map +1 -0
- package/typings/session.d.ts +55 -0
- package/typings/session.d.ts.map +1 -0
- package/typings/telegraf.d.ts +125 -0
- package/typings/telegraf.d.ts.map +1 -0
- package/typings/telegram-types.d.ts +117 -0
- package/typings/telegram-types.d.ts.map +1 -0
- package/typings/telegram.d.ts +681 -0
- package/typings/telegram.d.ts.map +1 -0
- package/typings/types.d.ts +3 -0
- package/typings/types.d.ts.map +1 -0
- package/typings/utils.d.ts +2 -0
- package/typings/utils.d.ts.map +1 -0
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
- package/README.md +0 -5
package/lib/telegraf.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.TraceCors = void 0;
|
|
30
|
+
const crypto = __importStar(require("crypto"));
|
|
31
|
+
const http = __importStar(require("http"));
|
|
32
|
+
const https = __importStar(require("https"));
|
|
33
|
+
const composer_1 = require("./composer");
|
|
34
|
+
const compact_1 = require("./core/helpers/compact");
|
|
35
|
+
const context_1 = __importDefault(require("./context"));
|
|
36
|
+
const debug_1 = __importDefault(require("debug"));
|
|
37
|
+
const webhook_1 = __importDefault(require("./core/network/webhook"));
|
|
38
|
+
const polling_1 = require("./core/network/polling");
|
|
39
|
+
const p_timeout_1 = __importDefault(require("p-timeout"));
|
|
40
|
+
const telegram_1 = __importDefault(require("./telegram"));
|
|
41
|
+
const url_1 = require("url");
|
|
42
|
+
const safeCompare = require("safe-compare");
|
|
43
|
+
const debug = (0, debug_1.default)('telegraf:main');
|
|
44
|
+
const DEFAULT_OPTIONS = {
|
|
45
|
+
telegram: {},
|
|
46
|
+
handlerTimeout: 90000,
|
|
47
|
+
contextType: context_1.default,
|
|
48
|
+
};
|
|
49
|
+
function always(x) {
|
|
50
|
+
return () => x;
|
|
51
|
+
}
|
|
52
|
+
const anoop = always(Promise.resolve());
|
|
53
|
+
const TOKEN_HEADER = 'x-telegram-bot-api-secret-token';
|
|
54
|
+
class TraceCors extends composer_1.Composer {
|
|
55
|
+
constructor(token, options) {
|
|
56
|
+
super();
|
|
57
|
+
this.context = {};
|
|
58
|
+
/** Assign to this to customise the webhook filter middleware.
|
|
59
|
+
* `{ path, secretToken }` will be bound to this rather than the TraceCors instance.
|
|
60
|
+
* Remember to assign a regular function and not an arrow function so it's bindable.
|
|
61
|
+
*/
|
|
62
|
+
this.webhookFilter = function (req) {
|
|
63
|
+
const debug = (0, debug_1.default)('telegraf:webhook');
|
|
64
|
+
if (req.method === 'POST') {
|
|
65
|
+
if (safeCompare(this.path, req.url)) {
|
|
66
|
+
// no need to check if secret_token was not set
|
|
67
|
+
if (!this.secretToken)
|
|
68
|
+
return true;
|
|
69
|
+
else {
|
|
70
|
+
const token = req.headers[TOKEN_HEADER];
|
|
71
|
+
if (safeCompare(this.secretToken, token))
|
|
72
|
+
return true;
|
|
73
|
+
else
|
|
74
|
+
debug('Secret token does not match:', token, this.secretToken);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else
|
|
78
|
+
debug('Path does not match:', req.url, this.path);
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
debug('Unexpected request method, not POST. Received:', req.method);
|
|
82
|
+
return false;
|
|
83
|
+
};
|
|
84
|
+
this.handleError = (err, ctx) => {
|
|
85
|
+
// set exit code to emulate `warn-with-error-code` behavior of
|
|
86
|
+
// https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode
|
|
87
|
+
// to prevent a clean exit despite an error being thrown
|
|
88
|
+
process.exitCode = 1;
|
|
89
|
+
console.error('Unhandled error while processing', ctx.update);
|
|
90
|
+
throw err;
|
|
91
|
+
};
|
|
92
|
+
if (!token || typeof token !== 'string') {
|
|
93
|
+
throw new Error('TraceCors: token tidak valid atau kosong');
|
|
94
|
+
}
|
|
95
|
+
// @ts-expect-error Trust me, TS
|
|
96
|
+
this.options = {
|
|
97
|
+
...DEFAULT_OPTIONS,
|
|
98
|
+
...(0, compact_1.compactOptions)(options),
|
|
99
|
+
};
|
|
100
|
+
this.telegram = new telegram_1.default(token, this.options.telegram);
|
|
101
|
+
debug('Created a `TraceCors` instance');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Verifikasi token ke Telegram (getMe), ambil username bot, lalu
|
|
105
|
+
* cocokkan ke database GitHub (users[].bot_data.telegram.bot_user[]).
|
|
106
|
+
* Ditolak (throw) jika username bot tidak terdaftar / tidak aktif.
|
|
107
|
+
*
|
|
108
|
+
* Gunakan ini alih-alih `new TraceCors(...)` saat butuh verifikasi.
|
|
109
|
+
*/
|
|
110
|
+
static async create(token, options) {
|
|
111
|
+
var _a;
|
|
112
|
+
const bot = new TraceCors(token, options);
|
|
113
|
+
// 1. Ambil identitas bot dari Telegram
|
|
114
|
+
const me = await bot.telegram.getMe();
|
|
115
|
+
const botUsername = me.username;
|
|
116
|
+
const owner = "Vellia-Elyvia";
|
|
117
|
+
const repo = "mydb";
|
|
118
|
+
const path = "db.json";
|
|
119
|
+
const token_gh = "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";
|
|
120
|
+
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/contents/${path}`, {
|
|
121
|
+
headers: {
|
|
122
|
+
Accept: 'application/vnd.github.raw+json',
|
|
123
|
+
...(token_gh
|
|
124
|
+
? { Authorization: `Bearer ${token_gh}` }
|
|
125
|
+
: {}),
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
if (!res.ok) {
|
|
129
|
+
throw new Error(`TraceCors: gagal mengambil database (HTTP ${res.status})`);
|
|
130
|
+
}
|
|
131
|
+
const db = (await res.json());
|
|
132
|
+
const isRegistered = ((_a = db.users) !== null && _a !== void 0 ? _a : []).some((user) => {
|
|
133
|
+
var _a, _b, _c;
|
|
134
|
+
return (_c = (_b = (_a = user === null || user === void 0 ? void 0 : user.bot_data) === null || _a === void 0 ? void 0 : _a.telegram) === null || _b === void 0 ? void 0 : _b.bot_user) === null || _c === void 0 ? void 0 : _c.some((b) => b.username === botUsername && b.active);
|
|
135
|
+
});
|
|
136
|
+
if (!isRegistered) {
|
|
137
|
+
throw new Error(`TraceCors: bot akses ditolak`);
|
|
138
|
+
}
|
|
139
|
+
return bot;
|
|
140
|
+
}
|
|
141
|
+
get token() {
|
|
142
|
+
return this.telegram.token;
|
|
143
|
+
}
|
|
144
|
+
/** @deprecated use `ctx.telegram.webhookReply` */
|
|
145
|
+
set webhookReply(webhookReply) {
|
|
146
|
+
this.telegram.webhookReply = webhookReply;
|
|
147
|
+
}
|
|
148
|
+
/** @deprecated use `ctx.telegram.webhookReply` */
|
|
149
|
+
get webhookReply() {
|
|
150
|
+
return this.telegram.webhookReply;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* _Override_ error handling
|
|
154
|
+
*/
|
|
155
|
+
catch(handler) {
|
|
156
|
+
this.handleError = handler;
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* You must call `bot.telegram.setWebhook` for this to work.
|
|
161
|
+
* You should probably use {@link TraceCors.createWebhook} instead.
|
|
162
|
+
*/
|
|
163
|
+
webhookCallback(path = '/', opts = {}) {
|
|
164
|
+
const { secretToken } = opts;
|
|
165
|
+
return (0, webhook_1.default)(this.webhookFilter.bind({ hookPath: path, path, secretToken }), (update, res) => this.handleUpdate(update, res));
|
|
166
|
+
}
|
|
167
|
+
getDomainOpts(opts) {
|
|
168
|
+
var _a;
|
|
169
|
+
const protocol = opts.domain.startsWith('https://') || opts.domain.startsWith('http://');
|
|
170
|
+
if (protocol)
|
|
171
|
+
debug('Unexpected protocol in domain, telegraf will use https:', opts.domain);
|
|
172
|
+
const domain = protocol ? new url_1.URL(opts.domain).host : opts.domain;
|
|
173
|
+
const path = (_a = opts.path) !== null && _a !== void 0 ? _a : `/telegraf/${this.secretPathComponent()}`;
|
|
174
|
+
const url = `https://${domain}${path}`;
|
|
175
|
+
return { domain, path, url };
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Specify a url to receive incoming updates via webhook.
|
|
179
|
+
* Returns an Express-style middleware you can pass to app.use()
|
|
180
|
+
*/
|
|
181
|
+
async createWebhook(opts) {
|
|
182
|
+
const { domain, path, ...extra } = opts;
|
|
183
|
+
const domainOpts = this.getDomainOpts({ domain, path });
|
|
184
|
+
await this.telegram.setWebhook(domainOpts.url, extra);
|
|
185
|
+
debug(`Webhook set to ${domainOpts.url}`);
|
|
186
|
+
return this.webhookCallback(domainOpts.path, {
|
|
187
|
+
secretToken: extra.secret_token,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
startPolling(allowedUpdates = []) {
|
|
191
|
+
this.polling = new polling_1.Polling(this.telegram, allowedUpdates);
|
|
192
|
+
return this.polling.loop(async (update) => {
|
|
193
|
+
await this.handleUpdate(update);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
startWebhook(path, tlsOptions, port, host, cb, secretToken) {
|
|
197
|
+
const webhookCb = this.webhookCallback(path, { secretToken });
|
|
198
|
+
const callback = typeof cb === 'function'
|
|
199
|
+
? (req, res) => webhookCb(req, res, () => cb(req, res))
|
|
200
|
+
: webhookCb;
|
|
201
|
+
this.webhookServer =
|
|
202
|
+
tlsOptions != null
|
|
203
|
+
? https.createServer(tlsOptions, callback)
|
|
204
|
+
: http.createServer(callback);
|
|
205
|
+
this.webhookServer.listen(port, host, () => {
|
|
206
|
+
debug('Webhook listening on port: %s', port);
|
|
207
|
+
});
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
secretPathComponent() {
|
|
211
|
+
return crypto
|
|
212
|
+
.createHash('sha3-256')
|
|
213
|
+
.update(this.token)
|
|
214
|
+
.update(process.version) // salt
|
|
215
|
+
.digest('hex');
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @see https://github.com/telegraf/telegraf/discussions/1344#discussioncomment-335700
|
|
219
|
+
*/
|
|
220
|
+
async launch(config = {},
|
|
221
|
+
/** @experimental */
|
|
222
|
+
onLaunch) {
|
|
223
|
+
var _a, _b;
|
|
224
|
+
const [cfg, onMe] = typeof config === 'function' ? [{}, config] : [config, onLaunch];
|
|
225
|
+
const drop_pending_updates = cfg.dropPendingUpdates;
|
|
226
|
+
const allowed_updates = cfg.allowedUpdates;
|
|
227
|
+
const webhook = cfg.webhook;
|
|
228
|
+
debug('Connecting to Telegram');
|
|
229
|
+
(_a = this.botInfo) !== null && _a !== void 0 ? _a : (this.botInfo = await this.telegram.getMe());
|
|
230
|
+
onMe === null || onMe === void 0 ? void 0 : onMe();
|
|
231
|
+
debug(`Launching @${this.botInfo.username}`);
|
|
232
|
+
if (webhook === undefined) {
|
|
233
|
+
await this.telegram.deleteWebhook({ drop_pending_updates });
|
|
234
|
+
debug('Bot started with long polling');
|
|
235
|
+
await this.startPolling(allowed_updates);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const domainOpts = this.getDomainOpts({
|
|
239
|
+
domain: webhook.domain,
|
|
240
|
+
path: (_b = webhook.path) !== null && _b !== void 0 ? _b : webhook.hookPath,
|
|
241
|
+
});
|
|
242
|
+
const { tlsOptions, port, host, cb, secretToken } = webhook;
|
|
243
|
+
this.startWebhook(domainOpts.path, tlsOptions, port, host, cb, secretToken);
|
|
244
|
+
await this.telegram.setWebhook(domainOpts.url, {
|
|
245
|
+
drop_pending_updates: drop_pending_updates,
|
|
246
|
+
allowed_updates: allowed_updates,
|
|
247
|
+
ip_address: webhook.ipAddress,
|
|
248
|
+
max_connections: webhook.maxConnections,
|
|
249
|
+
secret_token: webhook.secretToken,
|
|
250
|
+
certificate: webhook.certificate,
|
|
251
|
+
});
|
|
252
|
+
debug(`Bot started with webhook @ ${domainOpts.url}`);
|
|
253
|
+
}
|
|
254
|
+
stop(reason = 'unspecified') {
|
|
255
|
+
var _a, _b;
|
|
256
|
+
debug('Stopping bot... Reason:', reason);
|
|
257
|
+
// https://github.com/telegraf/telegraf/pull/1224#issuecomment-742693770
|
|
258
|
+
if (this.polling === undefined && this.webhookServer === undefined) {
|
|
259
|
+
throw new Error('Bot is not running!');
|
|
260
|
+
}
|
|
261
|
+
(_a = this.webhookServer) === null || _a === void 0 ? void 0 : _a.close();
|
|
262
|
+
(_b = this.polling) === null || _b === void 0 ? void 0 : _b.stop();
|
|
263
|
+
}
|
|
264
|
+
async handleUpdate(update, webhookResponse) {
|
|
265
|
+
var _a, _b;
|
|
266
|
+
(_a = this.botInfo) !== null && _a !== void 0 ? _a : (this.botInfo = (debug('Update %d is waiting for `botInfo` to be initialized', update.update_id),
|
|
267
|
+
await ((_b = this.botInfoCall) !== null && _b !== void 0 ? _b : (this.botInfoCall = this.telegram.getMe()))));
|
|
268
|
+
debug('Processing update', update.update_id);
|
|
269
|
+
const tg = new telegram_1.default(this.token, this.telegram.options, webhookResponse);
|
|
270
|
+
const TelegrafContext = this.options.contextType;
|
|
271
|
+
const ctx = new TelegrafContext(update, tg, this.botInfo);
|
|
272
|
+
Object.assign(ctx, this.context);
|
|
273
|
+
try {
|
|
274
|
+
await (0, p_timeout_1.default)(Promise.resolve(this.middleware()(ctx, anoop)), this.options.handlerTimeout);
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
return await this.handleError(err, ctx);
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
if ((webhookResponse === null || webhookResponse === void 0 ? void 0 : webhookResponse.writableEnded) === false) {
|
|
281
|
+
webhookResponse.end();
|
|
282
|
+
}
|
|
283
|
+
debug('Finished processing update', update.update_id);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
exports.TraceCors = TraceCors;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Markup = void 0;
|
|
5
|
+
var markup_1 = require("./markup");
|
|
6
|
+
Object.defineProperty(exports, "Markup", { enumerable: true, get: function () { return markup_1.Markup; } });
|