@tgify/tgify 0.1.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.
- package/LICENSE +23 -0
- package/README.md +356 -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 +100 -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 +57 -0
- package/lib/core/helpers/check.js +55 -0
- package/lib/core/helpers/compact.js +16 -0
- package/lib/core/helpers/deunionize.js +12 -0
- package/lib/core/helpers/formatting.js +91 -0
- package/lib/core/helpers/util.js +50 -0
- package/lib/core/network/client.js +330 -0
- package/lib/core/network/error.js +21 -0
- package/lib/core/network/multipart-stream.js +71 -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 +149 -0
- package/lib/index.js +58 -0
- package/lib/input.js +61 -0
- package/lib/markup.js +121 -0
- package/lib/middleware.js +2 -0
- package/lib/reactions.js +84 -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 +256 -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 +140 -0
- 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 +1661 -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 +118 -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 +354 -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 +655 -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 +26 -0
- package/typings/core/helpers/util.d.ts.map +1 -0
- package/typings/core/network/client.d.ts +53 -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 +16 -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 +6 -0
- package/typings/core/network/webhook.d.ts.map +1 -0
- package/typings/core/types/typegram.d.ts +42 -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 +50 -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 +115 -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 +675 -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
|
@@ -0,0 +1,71 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const stream = __importStar(require("stream"));
|
|
40
|
+
const check_1 = require("../helpers/check");
|
|
41
|
+
const sandwich_stream_1 = __importDefault(require("sandwich-stream"));
|
|
42
|
+
const CRNL = '\r\n';
|
|
43
|
+
class MultipartStream extends sandwich_stream_1.default {
|
|
44
|
+
constructor(boundary) {
|
|
45
|
+
super({
|
|
46
|
+
head: `--${boundary}${CRNL}`,
|
|
47
|
+
tail: `${CRNL}--${boundary}--`,
|
|
48
|
+
separator: `${CRNL}--${boundary}${CRNL}`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
addPart(part) {
|
|
52
|
+
const partStream = new stream.PassThrough();
|
|
53
|
+
for (const [key, header] of Object.entries(part.headers)) {
|
|
54
|
+
partStream.write(`${key}:${header}${CRNL}`);
|
|
55
|
+
}
|
|
56
|
+
partStream.write(CRNL);
|
|
57
|
+
if (MultipartStream.isStream(part.body)) {
|
|
58
|
+
part.body.pipe(partStream);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
partStream.end(part.body);
|
|
62
|
+
}
|
|
63
|
+
this.add(partStream);
|
|
64
|
+
}
|
|
65
|
+
static isStream(stream) {
|
|
66
|
+
return (typeof stream === 'object' &&
|
|
67
|
+
stream !== null &&
|
|
68
|
+
(0, check_1.hasPropType)(stream, 'pipe', 'function'));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.default = MultipartStream;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Polling = void 0;
|
|
7
|
+
const abort_controller_1 = __importDefault(require("abort-controller"));
|
|
8
|
+
const debug_1 = __importDefault(require("debug"));
|
|
9
|
+
const util_1 = require("util");
|
|
10
|
+
const error_1 = require("./error");
|
|
11
|
+
const debug = (0, debug_1.default)('telegraf:polling');
|
|
12
|
+
const wait = (0, util_1.promisify)(setTimeout);
|
|
13
|
+
function always(x) {
|
|
14
|
+
return () => x;
|
|
15
|
+
}
|
|
16
|
+
const noop = always(Promise.resolve());
|
|
17
|
+
class Polling {
|
|
18
|
+
constructor(telegram, allowedUpdates) {
|
|
19
|
+
this.telegram = telegram;
|
|
20
|
+
this.allowedUpdates = allowedUpdates;
|
|
21
|
+
this.abortController = new abort_controller_1.default();
|
|
22
|
+
this.skipOffsetSync = false;
|
|
23
|
+
this.offset = 0;
|
|
24
|
+
}
|
|
25
|
+
async *[Symbol.asyncIterator]() {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
debug('Starting long polling');
|
|
28
|
+
do {
|
|
29
|
+
try {
|
|
30
|
+
const updates = await this.telegram.callApi('getUpdates', {
|
|
31
|
+
timeout: 50,
|
|
32
|
+
offset: this.offset,
|
|
33
|
+
allowed_updates: this.allowedUpdates,
|
|
34
|
+
}, this.abortController);
|
|
35
|
+
const last = updates[updates.length - 1];
|
|
36
|
+
if (last !== undefined) {
|
|
37
|
+
this.offset = last.update_id + 1;
|
|
38
|
+
}
|
|
39
|
+
yield updates;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const err = error;
|
|
43
|
+
if (err.name === 'AbortError')
|
|
44
|
+
return;
|
|
45
|
+
if (err.name === 'FetchError' ||
|
|
46
|
+
(err instanceof error_1.TelegramError && err.code === 429) ||
|
|
47
|
+
(err instanceof error_1.TelegramError && err.code >= 500)) {
|
|
48
|
+
const retryAfter = (_b = (_a = err.parameters) === null || _a === void 0 ? void 0 : _a.retry_after) !== null && _b !== void 0 ? _b : 5;
|
|
49
|
+
debug('Failed to fetch updates, retrying after %ds.', retryAfter, err);
|
|
50
|
+
await wait(retryAfter * 1000);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (err instanceof error_1.TelegramError &&
|
|
54
|
+
// Unauthorized Conflict
|
|
55
|
+
(err.code === 401 || err.code === 409)) {
|
|
56
|
+
this.skipOffsetSync = true;
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
} while (!this.abortController.signal.aborted);
|
|
62
|
+
}
|
|
63
|
+
async syncUpdateOffset() {
|
|
64
|
+
if (this.skipOffsetSync)
|
|
65
|
+
return;
|
|
66
|
+
debug('Syncing update offset...');
|
|
67
|
+
await this.telegram.callApi('getUpdates', { offset: this.offset, limit: 1 });
|
|
68
|
+
}
|
|
69
|
+
async loop(handleUpdate) {
|
|
70
|
+
if (this.abortController.signal.aborted)
|
|
71
|
+
throw new Error('Polling instances must not be reused!');
|
|
72
|
+
try {
|
|
73
|
+
for await (const updates of this)
|
|
74
|
+
await Promise.all(updates.map(handleUpdate));
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
debug('Long polling stopped');
|
|
78
|
+
// prevent instance reuse
|
|
79
|
+
this.stop();
|
|
80
|
+
await this.syncUpdateOffset().catch(noop);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
stop() {
|
|
84
|
+
this.abortController.abort();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.Polling = Polling;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = generateWebhook;
|
|
7
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
|
+
const debug = (0, debug_1.default)('telegraf:webhook');
|
|
9
|
+
function generateWebhook(filter, updateHandler) {
|
|
10
|
+
return async (req, res, next = () => {
|
|
11
|
+
res.statusCode = 403;
|
|
12
|
+
debug('Replying with status code', res.statusCode);
|
|
13
|
+
res.end();
|
|
14
|
+
}) => {
|
|
15
|
+
debug('Incoming request', req.method, req.url);
|
|
16
|
+
if (!filter(req)) {
|
|
17
|
+
debug('Webhook filter failed', req.method, req.url);
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
let update;
|
|
21
|
+
try {
|
|
22
|
+
if (req.body != null) {
|
|
23
|
+
/* If req.body is already set, we expect it to be the parsed
|
|
24
|
+
request body (update object) received from Telegram
|
|
25
|
+
However, some libraries such as `serverless-http` set req.body to the
|
|
26
|
+
raw buffer, so we'll handle that additionally */
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
let body = req.body;
|
|
29
|
+
// if body is Buffer, parse it into string
|
|
30
|
+
if (body instanceof Buffer)
|
|
31
|
+
body = String(req.body);
|
|
32
|
+
// if body is string, parse it into object
|
|
33
|
+
if (typeof body === 'string')
|
|
34
|
+
body = JSON.parse(body);
|
|
35
|
+
update = body;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
let body = '';
|
|
39
|
+
// parse each buffer to string and append to body
|
|
40
|
+
for await (const chunk of req)
|
|
41
|
+
body += String(chunk);
|
|
42
|
+
// parse body to object
|
|
43
|
+
update = JSON.parse(body);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
// if any of the parsing steps fails, give up and respond with error
|
|
48
|
+
res.writeHead(415).end();
|
|
49
|
+
debug('Failed to parse request body:', error);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
return await updateHandler(update, res);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// internal type provisions
|
|
18
|
+
__exportStar(require("@telegraf/types/api"), exports);
|
|
19
|
+
__exportStar(require("@telegraf/types/inline"), exports);
|
|
20
|
+
__exportStar(require("@telegraf/types/manage"), exports);
|
|
21
|
+
__exportStar(require("@telegraf/types/markup"), exports);
|
|
22
|
+
__exportStar(require("@telegraf/types/message"), exports);
|
|
23
|
+
__exportStar(require("@telegraf/types/methods"), exports);
|
|
24
|
+
__exportStar(require("@telegraf/types/passport"), exports);
|
|
25
|
+
__exportStar(require("@telegraf/types/payment"), exports);
|
|
26
|
+
__exportStar(require("@telegraf/types/settings"), exports);
|
|
27
|
+
__exportStar(require("@telegraf/types/update"), exports);
|
package/lib/filters.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.allOf = exports.anyOf = exports.callbackQuery = exports.editedChannelPost = exports.channelPost = exports.editedMessage = exports.message = void 0;
|
|
4
|
+
const message = (...keys) => (update) => {
|
|
5
|
+
if (!('message' in update))
|
|
6
|
+
return false;
|
|
7
|
+
for (const key of keys) {
|
|
8
|
+
if (!(key in update.message))
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
exports.message = message;
|
|
14
|
+
const editedMessage = (...keys) => (update) => {
|
|
15
|
+
if (!('edited_message' in update))
|
|
16
|
+
return false;
|
|
17
|
+
for (const key of keys) {
|
|
18
|
+
if (!(key in update.edited_message))
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
exports.editedMessage = editedMessage;
|
|
24
|
+
const channelPost = (...keys) => (update) => {
|
|
25
|
+
if (!('channel_post' in update))
|
|
26
|
+
return false;
|
|
27
|
+
for (const key of keys) {
|
|
28
|
+
if (!(key in update.channel_post))
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
33
|
+
exports.channelPost = channelPost;
|
|
34
|
+
const editedChannelPost = (...keys) => (update) => {
|
|
35
|
+
if (!('edited_channel_post' in update))
|
|
36
|
+
return false;
|
|
37
|
+
for (const key of keys) {
|
|
38
|
+
if (!(key in update.edited_channel_post))
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
exports.editedChannelPost = editedChannelPost;
|
|
44
|
+
const callbackQuery = (...keys) => (update) => {
|
|
45
|
+
if (!('callback_query' in update))
|
|
46
|
+
return false;
|
|
47
|
+
for (const key of keys) {
|
|
48
|
+
if (!(key in update.callback_query))
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
};
|
|
53
|
+
exports.callbackQuery = callbackQuery;
|
|
54
|
+
/** Any of the provided filters must match */
|
|
55
|
+
const anyOf = (...filters) => (update) => {
|
|
56
|
+
for (const filter of filters)
|
|
57
|
+
if (filter(update))
|
|
58
|
+
return true;
|
|
59
|
+
return false;
|
|
60
|
+
};
|
|
61
|
+
exports.anyOf = anyOf;
|
|
62
|
+
/** All of the provided filters must match */
|
|
63
|
+
const allOf = (...filters) => (update) => {
|
|
64
|
+
for (const filter of filters)
|
|
65
|
+
if (!filter(update))
|
|
66
|
+
return false;
|
|
67
|
+
return true;
|
|
68
|
+
};
|
|
69
|
+
exports.allOf = allOf;
|
package/lib/format.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mention = exports.link = exports.pre = exports.code = exports.quote = exports.underline = exports.strikethrough = exports.spoiler = exports.italic = exports.bold = exports.fmt = exports.join = exports.FmtString = void 0;
|
|
4
|
+
const formatting_1 = require("./core/helpers/formatting");
|
|
5
|
+
Object.defineProperty(exports, "FmtString", { enumerable: true, get: function () { return formatting_1.FmtString; } });
|
|
6
|
+
// Nests<A, B> means the function will return A, and it can nest B
|
|
7
|
+
// Nests<'fmt', string> means it will nest anything
|
|
8
|
+
// Nests<'code', never> means it will not nest anything
|
|
9
|
+
// Allowing everything to nest 'fmt' is a necessary evil; it allows to indirectly nest illegal entities
|
|
10
|
+
// Except for 'code' and 'pre', which don't nest anything anyway, so they only deal with strings
|
|
11
|
+
exports.join = formatting_1.join;
|
|
12
|
+
exports.fmt = (0, formatting_1.createFmt)();
|
|
13
|
+
exports.bold = (0, formatting_1.createFmt)('bold');
|
|
14
|
+
exports.italic = (0, formatting_1.createFmt)('italic');
|
|
15
|
+
exports.spoiler = (0, formatting_1.createFmt)('spoiler');
|
|
16
|
+
exports.strikethrough =
|
|
17
|
+
//
|
|
18
|
+
(0, formatting_1.createFmt)('strikethrough');
|
|
19
|
+
exports.underline =
|
|
20
|
+
//
|
|
21
|
+
(0, formatting_1.createFmt)('underline');
|
|
22
|
+
exports.quote =
|
|
23
|
+
//
|
|
24
|
+
(0, formatting_1.createFmt)('blockquote');
|
|
25
|
+
exports.code = (0, formatting_1.createFmt)('code');
|
|
26
|
+
const pre = (language) => (0, formatting_1.createFmt)('pre', { language });
|
|
27
|
+
exports.pre = pre;
|
|
28
|
+
const link = (content, url) =>
|
|
29
|
+
//
|
|
30
|
+
(0, formatting_1.linkOrMention)(content, { type: 'text_link', url });
|
|
31
|
+
exports.link = link;
|
|
32
|
+
const mention = (name, user) => typeof user === 'number'
|
|
33
|
+
? (0, exports.link)(name, 'tg://user?id=' + user)
|
|
34
|
+
: (0, formatting_1.linkOrMention)(name, {
|
|
35
|
+
type: 'text_mention',
|
|
36
|
+
user,
|
|
37
|
+
});
|
|
38
|
+
exports.mention = mention;
|
package/lib/future.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useNewReplies = useNewReplies;
|
|
4
|
+
function makeReply(ctx, extra) {
|
|
5
|
+
if (ctx.msgId)
|
|
6
|
+
return {
|
|
7
|
+
// overrides in this order so user can override all properties
|
|
8
|
+
reply_parameters: {
|
|
9
|
+
message_id: ctx.msgId,
|
|
10
|
+
...extra === null || extra === void 0 ? void 0 : extra.reply_parameters,
|
|
11
|
+
},
|
|
12
|
+
...extra,
|
|
13
|
+
};
|
|
14
|
+
else
|
|
15
|
+
return extra;
|
|
16
|
+
}
|
|
17
|
+
const replyContext = {
|
|
18
|
+
replyWithChatAction: function () {
|
|
19
|
+
throw new TypeError('ctx.replyWithChatAction has been removed, use ctx.sendChatAction instead');
|
|
20
|
+
},
|
|
21
|
+
reply(text, extra) {
|
|
22
|
+
this.assert(this.chat, 'reply');
|
|
23
|
+
return this.telegram.sendMessage(this.chat.id, text, makeReply(this, extra));
|
|
24
|
+
},
|
|
25
|
+
replyWithAnimation(animation, extra) {
|
|
26
|
+
this.assert(this.chat, 'replyWithAnimation');
|
|
27
|
+
return this.telegram.sendAnimation(this.chat.id, animation, makeReply(this, extra));
|
|
28
|
+
},
|
|
29
|
+
replyWithAudio(audio, extra) {
|
|
30
|
+
this.assert(this.chat, 'replyWithAudio');
|
|
31
|
+
return this.telegram.sendAudio(this.chat.id, audio, makeReply(this, extra));
|
|
32
|
+
},
|
|
33
|
+
replyWithContact(phoneNumber, firstName, extra) {
|
|
34
|
+
this.assert(this.chat, 'replyWithContact');
|
|
35
|
+
return this.telegram.sendContact(this.chat.id, phoneNumber, firstName, makeReply(this, extra));
|
|
36
|
+
},
|
|
37
|
+
replyWithDice(extra) {
|
|
38
|
+
this.assert(this.chat, 'replyWithDice');
|
|
39
|
+
return this.telegram.sendDice(this.chat.id, makeReply(this, extra));
|
|
40
|
+
},
|
|
41
|
+
replyWithDocument(document, extra) {
|
|
42
|
+
this.assert(this.chat, 'replyWithDocument');
|
|
43
|
+
return this.telegram.sendDocument(this.chat.id, document, makeReply(this, extra));
|
|
44
|
+
},
|
|
45
|
+
replyWithGame(gameName, extra) {
|
|
46
|
+
this.assert(this.chat, 'replyWithGame');
|
|
47
|
+
return this.telegram.sendGame(this.chat.id, gameName, makeReply(this, extra));
|
|
48
|
+
},
|
|
49
|
+
replyWithHTML(html, extra) {
|
|
50
|
+
this.assert(this.chat, 'replyWithHTML');
|
|
51
|
+
return this.telegram.sendMessage(this.chat.id, html, {
|
|
52
|
+
parse_mode: 'HTML',
|
|
53
|
+
...makeReply(this, extra),
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
replyWithInvoice(invoice, extra) {
|
|
57
|
+
this.assert(this.chat, 'replyWithInvoice');
|
|
58
|
+
return this.telegram.sendInvoice(this.chat.id, invoice, makeReply(this, extra));
|
|
59
|
+
},
|
|
60
|
+
replyWithLocation(latitude, longitude, extra) {
|
|
61
|
+
this.assert(this.chat, 'replyWithLocation');
|
|
62
|
+
return this.telegram.sendLocation(this.chat.id, latitude, longitude, makeReply(this, extra));
|
|
63
|
+
},
|
|
64
|
+
replyWithMarkdown(markdown, extra) {
|
|
65
|
+
this.assert(this.chat, 'replyWithMarkdown');
|
|
66
|
+
return this.telegram.sendMessage(this.chat.id, markdown, {
|
|
67
|
+
parse_mode: 'Markdown',
|
|
68
|
+
...makeReply(this, extra),
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
replyWithMarkdownV2(markdown, extra) {
|
|
72
|
+
this.assert(this.chat, 'replyWithMarkdownV2');
|
|
73
|
+
return this.telegram.sendMessage(this.chat.id, markdown, {
|
|
74
|
+
parse_mode: 'MarkdownV2',
|
|
75
|
+
...makeReply(this, extra),
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
replyWithMediaGroup(media, extra) {
|
|
79
|
+
this.assert(this.chat, 'replyWithMediaGroup');
|
|
80
|
+
return this.telegram.sendMediaGroup(this.chat.id, media, makeReply(this, extra));
|
|
81
|
+
},
|
|
82
|
+
replyWithPhoto(photo, extra) {
|
|
83
|
+
this.assert(this.chat, 'replyWithPhoto');
|
|
84
|
+
return this.telegram.sendPhoto(this.chat.id, photo, makeReply(this, extra));
|
|
85
|
+
},
|
|
86
|
+
replyWithPoll(question, options, extra) {
|
|
87
|
+
this.assert(this.chat, 'replyWithPoll');
|
|
88
|
+
return this.telegram.sendPoll(this.chat.id, question, options, makeReply(this, extra));
|
|
89
|
+
},
|
|
90
|
+
replyWithQuiz(question, options, extra) {
|
|
91
|
+
this.assert(this.chat, 'replyWithQuiz');
|
|
92
|
+
return this.telegram.sendQuiz(this.chat.id, question, options, makeReply(this, extra));
|
|
93
|
+
},
|
|
94
|
+
replyWithSticker(sticker, extra) {
|
|
95
|
+
this.assert(this.chat, 'replyWithSticker');
|
|
96
|
+
return this.telegram.sendSticker(this.chat.id, sticker, makeReply(this, extra));
|
|
97
|
+
},
|
|
98
|
+
replyWithVenue(latitude, longitude, title, address, extra) {
|
|
99
|
+
this.assert(this.chat, 'replyWithVenue');
|
|
100
|
+
return this.telegram.sendVenue(this.chat.id, latitude, longitude, title, address, makeReply(this, extra));
|
|
101
|
+
},
|
|
102
|
+
replyWithVideo(video, extra) {
|
|
103
|
+
this.assert(this.chat, 'replyWithVideo');
|
|
104
|
+
return this.telegram.sendVideo(this.chat.id, video, makeReply(this, extra));
|
|
105
|
+
},
|
|
106
|
+
replyWithVideoNote(videoNote, extra) {
|
|
107
|
+
this.assert(this.chat, 'replyWithVideoNote');
|
|
108
|
+
return this.telegram.sendVideoNote(this.chat.id, videoNote, makeReply(this, extra));
|
|
109
|
+
},
|
|
110
|
+
replyWithVoice(voice, extra) {
|
|
111
|
+
this.assert(this.chat, 'replyWithVoice');
|
|
112
|
+
return this.telegram.sendVoice(this.chat.id, voice, makeReply(this, extra));
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Sets up Context to use the new reply methods.
|
|
117
|
+
* This middleware makes `ctx.reply()` and `ctx.replyWith*()` methods will actually reply to the message they are replying to.
|
|
118
|
+
* Use `ctx.sendMessage()` to send a message in chat without replying to it.
|
|
119
|
+
*
|
|
120
|
+
* If the message to reply is deleted, `reply()` will send a normal message.
|
|
121
|
+
* If the update is not a message and we are unable to reply, `reply()` will send a normal message.
|
|
122
|
+
*/
|
|
123
|
+
function useNewReplies() {
|
|
124
|
+
return (ctx, next) => {
|
|
125
|
+
ctx.reply = replyContext.reply;
|
|
126
|
+
ctx.replyWithPhoto = replyContext.replyWithPhoto;
|
|
127
|
+
ctx.replyWithMediaGroup = replyContext.replyWithMediaGroup;
|
|
128
|
+
ctx.replyWithAudio = replyContext.replyWithAudio;
|
|
129
|
+
ctx.replyWithDice = replyContext.replyWithDice;
|
|
130
|
+
ctx.replyWithDocument = replyContext.replyWithDocument;
|
|
131
|
+
ctx.replyWithSticker = replyContext.replyWithSticker;
|
|
132
|
+
ctx.replyWithVideo = replyContext.replyWithVideo;
|
|
133
|
+
ctx.replyWithAnimation = replyContext.replyWithAnimation;
|
|
134
|
+
ctx.replyWithVideoNote = replyContext.replyWithVideoNote;
|
|
135
|
+
ctx.replyWithInvoice = replyContext.replyWithInvoice;
|
|
136
|
+
ctx.replyWithGame = replyContext.replyWithGame;
|
|
137
|
+
ctx.replyWithVoice = replyContext.replyWithVoice;
|
|
138
|
+
ctx.replyWithPoll = replyContext.replyWithPoll;
|
|
139
|
+
ctx.replyWithQuiz = replyContext.replyWithQuiz;
|
|
140
|
+
ctx.replyWithChatAction = replyContext.replyWithChatAction;
|
|
141
|
+
ctx.replyWithLocation = replyContext.replyWithLocation;
|
|
142
|
+
ctx.replyWithVenue = replyContext.replyWithVenue;
|
|
143
|
+
ctx.replyWithContact = replyContext.replyWithContact;
|
|
144
|
+
ctx.replyWithMarkdown = replyContext.replyWithMarkdown;
|
|
145
|
+
ctx.replyWithMarkdownV2 = replyContext.replyWithMarkdownV2;
|
|
146
|
+
ctx.replyWithHTML = replyContext.replyWithHTML;
|
|
147
|
+
return next();
|
|
148
|
+
};
|
|
149
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Scenes = exports.MemorySessionStore = exports.session = exports.deunionize = exports.Format = exports.Input = exports.Markup = exports.Types = exports.Telegram = exports.TelegramError = exports.Router = exports.Composer = exports.Context = exports.Telegraf = void 0;
|
|
37
|
+
var telegraf_1 = require("./telegraf");
|
|
38
|
+
Object.defineProperty(exports, "Telegraf", { enumerable: true, get: function () { return telegraf_1.Telegraf; } });
|
|
39
|
+
var context_1 = require("./context");
|
|
40
|
+
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
|
|
41
|
+
var composer_1 = require("./composer");
|
|
42
|
+
Object.defineProperty(exports, "Composer", { enumerable: true, get: function () { return composer_1.Composer; } });
|
|
43
|
+
var router_1 = require("./router");
|
|
44
|
+
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_1.Router; } });
|
|
45
|
+
var error_1 = require("./core/network/error");
|
|
46
|
+
Object.defineProperty(exports, "TelegramError", { enumerable: true, get: function () { return error_1.TelegramError; } });
|
|
47
|
+
var telegram_1 = require("./telegram");
|
|
48
|
+
Object.defineProperty(exports, "Telegram", { enumerable: true, get: function () { return telegram_1.Telegram; } });
|
|
49
|
+
exports.Types = __importStar(require("./telegram-types"));
|
|
50
|
+
exports.Markup = __importStar(require("./markup"));
|
|
51
|
+
exports.Input = __importStar(require("./input"));
|
|
52
|
+
exports.Format = __importStar(require("./format"));
|
|
53
|
+
var deunionize_1 = require("./core/helpers/deunionize");
|
|
54
|
+
Object.defineProperty(exports, "deunionize", { enumerable: true, get: function () { return deunionize_1.deunionize; } });
|
|
55
|
+
var session_1 = require("./session");
|
|
56
|
+
Object.defineProperty(exports, "session", { enumerable: true, get: function () { return session_1.session; } });
|
|
57
|
+
Object.defineProperty(exports, "MemorySessionStore", { enumerable: true, get: function () { return session_1.MemorySessionStore; } });
|
|
58
|
+
exports.Scenes = __importStar(require("./scenes"));
|
package/lib/input.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromFileId = exports.fromURL = exports.fromURLStream = exports.fromReadableStream = exports.fromBuffer = exports.fromLocalFile = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The local file specified by path will be uploaded to Telegram using multipart/form-data.
|
|
6
|
+
*
|
|
7
|
+
* 10 MB max size for photos, 50 MB for other files.
|
|
8
|
+
*/
|
|
9
|
+
// prettier-ignore
|
|
10
|
+
const fromLocalFile = (path, filename) => ({ source: path, filename });
|
|
11
|
+
exports.fromLocalFile = fromLocalFile;
|
|
12
|
+
/**
|
|
13
|
+
* The buffer will be uploaded as file to Telegram using multipart/form-data.
|
|
14
|
+
*
|
|
15
|
+
* 10 MB max size for photos, 50 MB for other files.
|
|
16
|
+
*/
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
const fromBuffer = (buffer, filename) => ({ source: buffer, filename });
|
|
19
|
+
exports.fromBuffer = fromBuffer;
|
|
20
|
+
/**
|
|
21
|
+
* Contents of the stream will be uploaded as file to Telegram using multipart/form-data.
|
|
22
|
+
*
|
|
23
|
+
* 10 MB max size for photos, 50 MB for other files.
|
|
24
|
+
*/
|
|
25
|
+
// prettier-ignore
|
|
26
|
+
const fromReadableStream = (stream, filename) => ({ source: stream, filename });
|
|
27
|
+
exports.fromReadableStream = fromReadableStream;
|
|
28
|
+
/**
|
|
29
|
+
* Contents of the URL will be streamed to Telegram.
|
|
30
|
+
*
|
|
31
|
+
* 10 MB max size for photos, 50 MB for other files.
|
|
32
|
+
*/
|
|
33
|
+
// prettier-ignore
|
|
34
|
+
const fromURLStream = (url, filename) => ({ url: url.toString(), filename });
|
|
35
|
+
exports.fromURLStream = fromURLStream;
|
|
36
|
+
/**
|
|
37
|
+
* Provide Telegram with an HTTP URL for the file to be sent.
|
|
38
|
+
* Telegram will download and send the file.
|
|
39
|
+
*
|
|
40
|
+
* * The target file must have the correct MIME type (e.g., audio/mpeg for `sendAudio`, etc.).
|
|
41
|
+
* * `sendDocument` with URL will currently only work for GIF, PDF and ZIP files.
|
|
42
|
+
* * To use `sendVoice`, the file must have the type audio/ogg and be no more than 1MB in size.
|
|
43
|
+
* 1-20MB voice notes will be sent as files.
|
|
44
|
+
*
|
|
45
|
+
* 5 MB max size for photos and 20 MB max for other types of content.
|
|
46
|
+
*/
|
|
47
|
+
const fromURL = (url) => url.toString();
|
|
48
|
+
exports.fromURL = fromURL;
|
|
49
|
+
/**
|
|
50
|
+
* If the file is already stored somewhere on the Telegram servers, you don't need to reupload it:
|
|
51
|
+
* each file object has a file_id field, simply pass this file_id as a parameter instead of uploading.
|
|
52
|
+
*
|
|
53
|
+
* It is not possible to change the file type when resending by file_id.
|
|
54
|
+
*
|
|
55
|
+
* It is not possible to resend thumbnails using file_id.
|
|
56
|
+
* They have to be uploaded using one of the other Input methods.
|
|
57
|
+
*
|
|
58
|
+
* There are no limits for files sent this way.
|
|
59
|
+
*/
|
|
60
|
+
const fromFileId = (fileId) => fileId;
|
|
61
|
+
exports.fromFileId = fromFileId;
|