@icanseeuanywhere/telekaf 4.16.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/LICENSE +22 -0
- package/README.md +978 -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 +1277 -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/rich-message.js +102 -0
- package/lib/core/types/typegram.js +28 -0
- package/lib/filters.js +69 -0
- package/lib/format.js +38 -0
- package/lib/future.js +166 -0
- package/lib/index.js +49 -0
- package/lib/input.js +61 -0
- package/lib/markup.js +111 -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 +246 -0
- package/lib/telegram-types.js +6 -0
- package/lib/telegram.js +1265 -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 +138 -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 +1739 -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/rich-message.ts +474 -0
- package/src/core/types/typegram.ts +55 -0
- package/src/filters.ts +109 -0
- package/src/format.ts +110 -0
- package/src/future.ts +231 -0
- package/src/index.ts +18 -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 +250 -0
- package/src/telegram.ts +1671 -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 +693 -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 +19 -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/rich-message.d.ts +295 -0
- package/typings/core/types/rich-message.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 +16 -0
- package/typings/index.d.ts.map +1 -0
- package/typings/input.d.ts +55 -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 +117 -0
- package/typings/telegraf.d.ts.map +1 -0
- package/typings/telegram-types.d.ts +134 -0
- package/typings/telegram-types.d.ts.map +1 -0
- package/typings/telegram.d.ts +691 -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/filters.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './typings/filters'
|
package/filters.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/filters')
|
package/format.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './typings/format'
|
package/format.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/format')
|
package/future.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './typings/future'
|
package/future.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/future')
|
package/lib/button.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webApp = exports.login = exports.pay = exports.game = exports.switchToCurrentChat = exports.switchToChat = exports.callback = exports.url = exports.channelRequest = exports.groupRequest = exports.botRequest = exports.userRequest = exports.pollRequest = exports.locationRequest = exports.contactRequest = exports.text = void 0;
|
|
4
|
+
function text(text, hide = false) {
|
|
5
|
+
return { text, hide };
|
|
6
|
+
}
|
|
7
|
+
exports.text = text;
|
|
8
|
+
function contactRequest(text, hide = false) {
|
|
9
|
+
return { text, request_contact: true, hide };
|
|
10
|
+
}
|
|
11
|
+
exports.contactRequest = contactRequest;
|
|
12
|
+
function locationRequest(text, hide = false) {
|
|
13
|
+
return { text, request_location: true, hide };
|
|
14
|
+
}
|
|
15
|
+
exports.locationRequest = locationRequest;
|
|
16
|
+
function pollRequest(text, type, hide = false) {
|
|
17
|
+
return { text, request_poll: { type }, hide };
|
|
18
|
+
}
|
|
19
|
+
exports.pollRequest = pollRequest;
|
|
20
|
+
function userRequest(text,
|
|
21
|
+
/** Must fit in a signed 32 bit int */
|
|
22
|
+
request_id, extra, hide = false) {
|
|
23
|
+
return {
|
|
24
|
+
text,
|
|
25
|
+
request_users: { request_id, ...extra },
|
|
26
|
+
hide,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.userRequest = userRequest;
|
|
30
|
+
function botRequest(text,
|
|
31
|
+
/** Must fit in a signed 32 bit int */
|
|
32
|
+
request_id, extra, hide = false) {
|
|
33
|
+
return {
|
|
34
|
+
text,
|
|
35
|
+
request_users: { request_id, user_is_bot: true, ...extra },
|
|
36
|
+
hide,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.botRequest = botRequest;
|
|
40
|
+
function groupRequest(text,
|
|
41
|
+
/** Must fit in a signed 32 bit int */
|
|
42
|
+
request_id, extra, hide = false) {
|
|
43
|
+
return {
|
|
44
|
+
text,
|
|
45
|
+
request_chat: { request_id, chat_is_channel: false, ...extra },
|
|
46
|
+
hide,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
exports.groupRequest = groupRequest;
|
|
50
|
+
function channelRequest(text,
|
|
51
|
+
/** Must fit in a signed 32 bit int */
|
|
52
|
+
request_id, extra, hide = false) {
|
|
53
|
+
return {
|
|
54
|
+
text,
|
|
55
|
+
request_chat: { request_id, chat_is_channel: true, ...extra },
|
|
56
|
+
hide,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.channelRequest = channelRequest;
|
|
60
|
+
function url(text, url, hide = false) {
|
|
61
|
+
return { text, url, hide };
|
|
62
|
+
}
|
|
63
|
+
exports.url = url;
|
|
64
|
+
function callback(text, data, hide = false) {
|
|
65
|
+
return { text, callback_data: data, hide };
|
|
66
|
+
}
|
|
67
|
+
exports.callback = callback;
|
|
68
|
+
function switchToChat(text, value, hide = false) {
|
|
69
|
+
return { text, switch_inline_query: value, hide };
|
|
70
|
+
}
|
|
71
|
+
exports.switchToChat = switchToChat;
|
|
72
|
+
function switchToCurrentChat(text, value, hide = false) {
|
|
73
|
+
return { text, switch_inline_query_current_chat: value, hide };
|
|
74
|
+
}
|
|
75
|
+
exports.switchToCurrentChat = switchToCurrentChat;
|
|
76
|
+
function game(text, hide = false) {
|
|
77
|
+
return { text, callback_game: {}, hide };
|
|
78
|
+
}
|
|
79
|
+
exports.game = game;
|
|
80
|
+
function pay(text, hide = false) {
|
|
81
|
+
return { text, pay: true, hide };
|
|
82
|
+
}
|
|
83
|
+
exports.pay = pay;
|
|
84
|
+
function login(text, url, opts = {}, hide = false) {
|
|
85
|
+
return {
|
|
86
|
+
text,
|
|
87
|
+
login_url: { ...opts, url },
|
|
88
|
+
hide,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
exports.login = login;
|
|
92
|
+
function webApp(text, url, hide = false
|
|
93
|
+
// works as both InlineKeyboardButton and KeyboardButton
|
|
94
|
+
) {
|
|
95
|
+
return {
|
|
96
|
+
text,
|
|
97
|
+
web_app: { url },
|
|
98
|
+
hide,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
exports.webApp = webApp;
|
package/lib/cli.mjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import d from 'debug';
|
|
3
|
+
import parse from 'mri';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { Telegraf } from './index.js';
|
|
6
|
+
const debug = d('telegraf:cli');
|
|
7
|
+
const helpMsg = `Usage: telegraf [opts] <bot-file>
|
|
8
|
+
|
|
9
|
+
-t Bot token [$BOT_TOKEN]
|
|
10
|
+
-d Webhook domain [$BOT_DOMAIN]
|
|
11
|
+
-H Webhook host [0.0.0.0]
|
|
12
|
+
-p Webhook port [$PORT or 3000]
|
|
13
|
+
-l Enable logs
|
|
14
|
+
-h Show this help message
|
|
15
|
+
-m Bot API method to run directly
|
|
16
|
+
-D Data to pass to the Bot API method`;
|
|
17
|
+
const help = () => console.log(helpMsg);
|
|
18
|
+
/**
|
|
19
|
+
* Runs the cli program and returns exit code
|
|
20
|
+
*/
|
|
21
|
+
export async function main(argv, env = {}) {
|
|
22
|
+
const args = parse(argv, {
|
|
23
|
+
alias: {
|
|
24
|
+
// string params, all optional
|
|
25
|
+
t: 'token',
|
|
26
|
+
d: 'domain',
|
|
27
|
+
m: 'method',
|
|
28
|
+
D: 'data',
|
|
29
|
+
// defaults exist
|
|
30
|
+
H: 'host',
|
|
31
|
+
p: 'port',
|
|
32
|
+
// boolean params
|
|
33
|
+
l: 'logs',
|
|
34
|
+
h: 'help',
|
|
35
|
+
},
|
|
36
|
+
boolean: ['h', 'l'],
|
|
37
|
+
default: {
|
|
38
|
+
H: '0.0.0.0',
|
|
39
|
+
p: env.PORT || '3000',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
if (args.help) {
|
|
43
|
+
help();
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
const token = args.token || env.BOT_TOKEN;
|
|
47
|
+
const domain = args.domain || env.BOT_DOMAIN;
|
|
48
|
+
if (!token) {
|
|
49
|
+
console.error('Please supply Bot Token');
|
|
50
|
+
help();
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
const bot = new Telegraf(token);
|
|
54
|
+
if (args.method) {
|
|
55
|
+
const method = args.method;
|
|
56
|
+
console.log(await bot.telegram.callApi(method, JSON.parse(args.data || '{}')));
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
let [, , file] = args._;
|
|
60
|
+
if (!file) {
|
|
61
|
+
try {
|
|
62
|
+
const packageJson = (await import(path.resolve(process.cwd(), 'package.json')));
|
|
63
|
+
file = packageJson.main || 'index.js';
|
|
64
|
+
// eslint-disable-next-line no-empty
|
|
65
|
+
}
|
|
66
|
+
catch (err) { }
|
|
67
|
+
}
|
|
68
|
+
if (!file) {
|
|
69
|
+
console.error('Please supply a bot handler file.\n');
|
|
70
|
+
help();
|
|
71
|
+
return 2;
|
|
72
|
+
}
|
|
73
|
+
if (file[0] !== '/')
|
|
74
|
+
file = path.resolve(process.cwd(), file);
|
|
75
|
+
try {
|
|
76
|
+
if (args.logs)
|
|
77
|
+
d.enable('telegraf:*');
|
|
78
|
+
const mod = await import(file);
|
|
79
|
+
const botHandler = mod.botHandler || mod.default;
|
|
80
|
+
const httpHandler = mod.httpHandler;
|
|
81
|
+
const tlsOptions = mod.tlsOptions;
|
|
82
|
+
const config = {};
|
|
83
|
+
if (domain) {
|
|
84
|
+
config.webhook = {
|
|
85
|
+
domain,
|
|
86
|
+
host: args.host,
|
|
87
|
+
port: Number(args.port),
|
|
88
|
+
tlsOptions,
|
|
89
|
+
cb: httpHandler,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
bot.use(botHandler);
|
|
93
|
+
debug(`Starting module ${file}`);
|
|
94
|
+
await bot.launch(config);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
console.error(`Error launching bot from ${file}`, err === null || err === void 0 ? void 0 : err.stack);
|
|
98
|
+
return 3;
|
|
99
|
+
}
|
|
100
|
+
// Enable graceful stop
|
|
101
|
+
process.once('SIGINT', () => bot.stop('SIGINT'));
|
|
102
|
+
process.once('SIGTERM', () => bot.stop('SIGTERM'));
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
process.exitCode = await main(process.argv, process.env);
|