teleproto 203.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.
- package/CryptoFile.d.ts +2 -0
- package/CryptoFile.js +23 -0
- package/Helpers.d.ts +151 -0
- package/Helpers.js +477 -0
- package/LICENSE +23 -0
- package/Password.d.ts +15 -0
- package/Password.js +271 -0
- package/README.md +111 -0
- package/Utils.d.ts +228 -0
- package/Utils.js +1248 -0
- package/Version.d.ts +1 -0
- package/Version.js +4 -0
- package/client/2fa.d.ts +48 -0
- package/client/2fa.js +109 -0
- package/client/TelegramClient.d.ts +1042 -0
- package/client/TelegramClient.js +1167 -0
- package/client/account.d.ts +0 -0
- package/client/account.js +1 -0
- package/client/auth.d.ts +93 -0
- package/client/auth.js +375 -0
- package/client/bots.d.ts +6 -0
- package/client/bots.js +24 -0
- package/client/buttons.d.ts +4 -0
- package/client/buttons.js +87 -0
- package/client/chats.d.ts +46 -0
- package/client/chats.js +350 -0
- package/client/dialogs.d.ts +52 -0
- package/client/dialogs.js +174 -0
- package/client/downloads.d.ts +157 -0
- package/client/downloads.js +598 -0
- package/client/fs.d.ts +1 -0
- package/client/fs.js +13 -0
- package/client/index.d.ts +15 -0
- package/client/index.js +50 -0
- package/client/messageParse.d.ts +17 -0
- package/client/messageParse.js +191 -0
- package/client/messages.d.ts +259 -0
- package/client/messages.js +804 -0
- package/client/os.d.ts +2 -0
- package/client/os.js +23 -0
- package/client/path.d.ts +2 -0
- package/client/path.js +7 -0
- package/client/telegramBaseClient.d.ts +238 -0
- package/client/telegramBaseClient.js +368 -0
- package/client/updates.d.ts +31 -0
- package/client/updates.js +254 -0
- package/client/uploads.d.ts +137 -0
- package/client/uploads.js +514 -0
- package/client/users.d.ts +29 -0
- package/client/users.js +491 -0
- package/crypto/AuthKey.d.ts +20 -0
- package/crypto/AuthKey.js +76 -0
- package/crypto/CTR.d.ts +6 -0
- package/crypto/CTR.js +35 -0
- package/crypto/Factorizator.d.ts +19 -0
- package/crypto/Factorizator.js +74 -0
- package/crypto/IGE.d.ts +18 -0
- package/crypto/IGE.js +34 -0
- package/crypto/RSA.d.ts +15 -0
- package/crypto/RSA.js +70 -0
- package/crypto/converters.d.ts +19 -0
- package/crypto/converters.js +52 -0
- package/crypto/crypto.d.ts +27 -0
- package/crypto/crypto.js +117 -0
- package/crypto/words.d.ts +6 -0
- package/crypto/words.js +48 -0
- package/define.d.ts +77 -0
- package/entityCache.d.ts +7 -0
- package/entityCache.js +79 -0
- package/errors/Common.d.ts +72 -0
- package/errors/Common.js +122 -0
- package/errors/RPCBaseErrors.d.ts +84 -0
- package/errors/RPCBaseErrors.js +134 -0
- package/errors/RPCErrorList.d.ts +37 -0
- package/errors/RPCErrorList.js +117 -0
- package/errors/index.d.ts +11 -0
- package/errors/index.js +29 -0
- package/events/Album.d.ts +36 -0
- package/events/Album.js +104 -0
- package/events/CallbackQuery.d.ts +74 -0
- package/events/CallbackQuery.js +193 -0
- package/events/DeletedMessage.d.ts +45 -0
- package/events/DeletedMessage.js +63 -0
- package/events/EditedMessage.d.ts +30 -0
- package/events/EditedMessage.js +41 -0
- package/events/NewMessage.d.ts +89 -0
- package/events/NewMessage.js +182 -0
- package/events/Raw.d.ts +29 -0
- package/events/Raw.js +43 -0
- package/events/common.d.ts +66 -0
- package/events/common.js +141 -0
- package/events/index.d.ts +2 -0
- package/events/index.js +8 -0
- package/extensions/AsyncQueue.d.ts +10 -0
- package/extensions/AsyncQueue.js +32 -0
- package/extensions/BinaryReader.d.ts +100 -0
- package/extensions/BinaryReader.js +242 -0
- package/extensions/BinaryWriter.d.ts +7 -0
- package/extensions/BinaryWriter.js +15 -0
- package/extensions/Deferred.d.ts +8 -0
- package/extensions/Deferred.js +16 -0
- package/extensions/Logger.d.ts +56 -0
- package/extensions/Logger.js +107 -0
- package/extensions/MessagePacker.d.ts +22 -0
- package/extensions/MessagePacker.js +154 -0
- package/extensions/PendingState.d.ts +12 -0
- package/extensions/PendingState.js +29 -0
- package/extensions/PromisedNetSockets.d.ts +25 -0
- package/extensions/PromisedNetSockets.js +178 -0
- package/extensions/PromisedWebSockets.d.ts +19 -0
- package/extensions/PromisedWebSockets.js +124 -0
- package/extensions/html.d.ts +5 -0
- package/extensions/html.js +213 -0
- package/extensions/index.d.ts +7 -0
- package/extensions/index.js +17 -0
- package/extensions/markdown.d.ts +5 -0
- package/extensions/markdown.js +76 -0
- package/extensions/markdownv2.d.ts +5 -0
- package/extensions/markdownv2.js +51 -0
- package/extensions/net.d.ts +1 -0
- package/extensions/net.js +13 -0
- package/extensions/socks.d.ts +1 -0
- package/extensions/socks.js +13 -0
- package/index.d.ts +14 -0
- package/index.js +48 -0
- package/inspect.d.ts +1 -0
- package/inspect.js +5 -0
- package/network/Authenticator.d.ts +12 -0
- package/network/Authenticator.js +193 -0
- package/network/MTProtoPlainSender.d.ts +19 -0
- package/network/MTProtoPlainSender.js +74 -0
- package/network/MTProtoSender.d.ts +291 -0
- package/network/MTProtoSender.js +854 -0
- package/network/MTProtoState.d.ts +103 -0
- package/network/MTProtoState.js +267 -0
- package/network/RequestState.d.ts +19 -0
- package/network/RequestState.js +35 -0
- package/network/connection/Connection.d.ts +71 -0
- package/network/connection/Connection.js +157 -0
- package/network/connection/TCPAbridged.d.ts +20 -0
- package/network/connection/TCPAbridged.js +58 -0
- package/network/connection/TCPFull.d.ts +17 -0
- package/network/connection/TCPFull.js +61 -0
- package/network/connection/TCPMTProxy.d.ts +50 -0
- package/network/connection/TCPMTProxy.js +121 -0
- package/network/connection/TCPObfuscated.d.ts +19 -0
- package/network/connection/TCPObfuscated.js +78 -0
- package/network/connection/index.d.ts +4 -0
- package/network/connection/index.js +11 -0
- package/network/index.d.ts +11 -0
- package/network/index.js +23 -0
- package/package.json +69 -0
- package/requestIter.d.ts +24 -0
- package/requestIter.js +107 -0
- package/sessions/Abstract.d.ts +103 -0
- package/sessions/Abstract.js +6 -0
- package/sessions/CacheApiSession.d.ts +18 -0
- package/sessions/CacheApiSession.js +99 -0
- package/sessions/Memory.d.ts +38 -0
- package/sessions/Memory.js +272 -0
- package/sessions/StoreSession.d.ts +14 -0
- package/sessions/StoreSession.js +77 -0
- package/sessions/StringSession.d.ts +33 -0
- package/sessions/StringSession.js +116 -0
- package/sessions/index.d.ts +4 -0
- package/sessions/index.js +13 -0
- package/sessions/localStorage.d.ts +1 -0
- package/sessions/localStorage.js +4 -0
- package/tl/AllTLObjects.d.ts +3 -0
- package/tl/AllTLObjects.js +17 -0
- package/tl/MTProtoRequest.d.ts +19 -0
- package/tl/MTProtoRequest.js +38 -0
- package/tl/api.d.ts +31425 -0
- package/tl/api.js +507 -0
- package/tl/apiTl.d.ts +2 -0
- package/tl/apiTl.js +2142 -0
- package/tl/core/GZIPPacked.d.ts +16 -0
- package/tl/core/GZIPPacked.js +51 -0
- package/tl/core/MessageContainer.d.ts +12 -0
- package/tl/core/MessageContainer.js +42 -0
- package/tl/core/RPCResult.d.ts +15 -0
- package/tl/core/RPCResult.js +32 -0
- package/tl/core/TLMessage.d.ts +10 -0
- package/tl/core/TLMessage.js +14 -0
- package/tl/core/index.d.ts +6 -0
- package/tl/core/index.js +16 -0
- package/tl/custom/button.d.ts +25 -0
- package/tl/custom/button.js +78 -0
- package/tl/custom/chatGetter.d.ts +30 -0
- package/tl/custom/chatGetter.js +114 -0
- package/tl/custom/dialog.d.ts +31 -0
- package/tl/custom/dialog.js +40 -0
- package/tl/custom/draft.d.ts +22 -0
- package/tl/custom/draft.js +48 -0
- package/tl/custom/file.d.ts +22 -0
- package/tl/custom/file.js +68 -0
- package/tl/custom/forward.d.ts +16 -0
- package/tl/custom/forward.js +47 -0
- package/tl/custom/index.d.ts +1 -0
- package/tl/custom/index.js +5 -0
- package/tl/custom/inlineResult.d.ts +33 -0
- package/tl/custom/inlineResult.js +87 -0
- package/tl/custom/inlineResults.d.ts +21 -0
- package/tl/custom/inlineResults.js +26 -0
- package/tl/custom/message.d.ts +428 -0
- package/tl/custom/message.js +702 -0
- package/tl/custom/messageButton.d.ts +55 -0
- package/tl/custom/messageButton.js +152 -0
- package/tl/custom/senderGetter.d.ts +29 -0
- package/tl/custom/senderGetter.js +55 -0
- package/tl/generateModule.d.ts +1 -0
- package/tl/generateModule.js +17 -0
- package/tl/generationHelpers.d.ts +12 -0
- package/tl/generationHelpers.js +289 -0
- package/tl/index.d.ts +3 -0
- package/tl/index.js +10 -0
- package/tl/patched/index.d.ts +2 -0
- package/tl/patched/index.js +77 -0
- package/tl/schemaTl.d.ts +2 -0
- package/tl/schemaTl.js +64 -0
- package/tl/types-generator/generate.d.ts +1 -0
- package/tl/types-generator/generate.js +84 -0
- package/tl/types-generator/template.d.ts +6 -0
- package/tl/types-generator/template.js +257 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._updateLoop = exports._dispatchUpdate = exports._processUpdate = exports._handleUpdate = exports.catchUp = exports.listEventHandlers = exports.removeEventHandler = exports.addEventHandler = exports.on = exports.StopPropagation = void 0;
|
|
4
|
+
const tl_1 = require("../tl");
|
|
5
|
+
const network_1 = require("../network");
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
const Helpers_1 = require("../Helpers");
|
|
8
|
+
const Logger_1 = require("../extensions/Logger");
|
|
9
|
+
const PING_INTERVAL = 9000; // 9 sec
|
|
10
|
+
const PING_TIMEOUT = 10000; // 10 sec
|
|
11
|
+
const PING_FAIL_ATTEMPTS = 3;
|
|
12
|
+
const PING_FAIL_INTERVAL = 100; // ms
|
|
13
|
+
const PING_DISCONNECT_DELAY = 60000; // 1 min
|
|
14
|
+
// An unusually long interval is a sign of returning from background mode...
|
|
15
|
+
const PING_INTERVAL_TO_WAKE_UP = 5000; // 5 sec
|
|
16
|
+
// ... so we send a quick "wake-up" ping to confirm than connection was dropped ASAP
|
|
17
|
+
const PING_WAKE_UP_TIMEOUT = 3000; // 3 sec
|
|
18
|
+
// We also send a warning to the user even a bit more quickly
|
|
19
|
+
const PING_WAKE_UP_WARNING_TIMEOUT = 1000; // 1 sec
|
|
20
|
+
/**
|
|
21
|
+
If this exception is raised in any of the handlers for a given event,
|
|
22
|
+
it will stop the execution of all other registered event handlers.
|
|
23
|
+
It can be seen as the ``StopIteration`` in a for loop but for events.
|
|
24
|
+
*/
|
|
25
|
+
class StopPropagation extends Error {
|
|
26
|
+
}
|
|
27
|
+
exports.StopPropagation = StopPropagation;
|
|
28
|
+
/** @hidden */
|
|
29
|
+
function on(client, event) {
|
|
30
|
+
return (f) => {
|
|
31
|
+
client.addEventHandler(f, event);
|
|
32
|
+
return f;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.on = on;
|
|
36
|
+
/** @hidden */
|
|
37
|
+
function addEventHandler(client, callback, event) {
|
|
38
|
+
if (event == undefined) {
|
|
39
|
+
// recursive imports :(
|
|
40
|
+
const raw = require("../events/Raw").Raw;
|
|
41
|
+
event = new raw({});
|
|
42
|
+
}
|
|
43
|
+
event.client = client;
|
|
44
|
+
client._eventBuilders.push([event, callback]);
|
|
45
|
+
}
|
|
46
|
+
exports.addEventHandler = addEventHandler;
|
|
47
|
+
/** @hidden */
|
|
48
|
+
function removeEventHandler(client, callback, event) {
|
|
49
|
+
client._eventBuilders = client._eventBuilders.filter(function (item) {
|
|
50
|
+
return item[0] !== event && item[1] !== callback;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.removeEventHandler = removeEventHandler;
|
|
54
|
+
/** @hidden */
|
|
55
|
+
function listEventHandlers(client) {
|
|
56
|
+
return client._eventBuilders;
|
|
57
|
+
}
|
|
58
|
+
exports.listEventHandlers = listEventHandlers;
|
|
59
|
+
/** @hidden */
|
|
60
|
+
function catchUp() {
|
|
61
|
+
// TODO
|
|
62
|
+
}
|
|
63
|
+
exports.catchUp = catchUp;
|
|
64
|
+
/** @hidden */
|
|
65
|
+
function _handleUpdate(client, update) {
|
|
66
|
+
if (typeof update === "number") {
|
|
67
|
+
if ([-1, 0, 1].includes(update)) {
|
|
68
|
+
_dispatchUpdate(client, {
|
|
69
|
+
update: new network_1.UpdateConnectionState(update),
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//this.session.processEntities(update)
|
|
75
|
+
client._entityCache.add(update);
|
|
76
|
+
client.session.processEntities(update);
|
|
77
|
+
if (update instanceof tl_1.Api.Updates ||
|
|
78
|
+
update instanceof tl_1.Api.UpdatesCombined) {
|
|
79
|
+
// TODO deal with entities
|
|
80
|
+
const entities = new Map();
|
|
81
|
+
for (const x of [...update.users, ...update.chats]) {
|
|
82
|
+
entities.set(index_1.utils.getPeerId(x), x);
|
|
83
|
+
}
|
|
84
|
+
for (const u of update.updates) {
|
|
85
|
+
_processUpdate(client, u, update.updates, entities);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (update instanceof tl_1.Api.UpdateShort) {
|
|
89
|
+
_processUpdate(client, update.update, null);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
_processUpdate(client, update, null);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports._handleUpdate = _handleUpdate;
|
|
96
|
+
/** @hidden */
|
|
97
|
+
function _processUpdate(client, update, others, entities) {
|
|
98
|
+
update._entities = entities || new Map();
|
|
99
|
+
const args = {
|
|
100
|
+
update: update,
|
|
101
|
+
others: others,
|
|
102
|
+
};
|
|
103
|
+
_dispatchUpdate(client, args);
|
|
104
|
+
}
|
|
105
|
+
exports._processUpdate = _processUpdate;
|
|
106
|
+
/** @hidden */
|
|
107
|
+
async function _dispatchUpdate(client, args) {
|
|
108
|
+
for (const [builder, callback] of client._eventBuilders) {
|
|
109
|
+
if (!builder || !callback) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!builder.resolved) {
|
|
113
|
+
await builder.resolve(client);
|
|
114
|
+
}
|
|
115
|
+
let event = args.update;
|
|
116
|
+
if (event) {
|
|
117
|
+
if (!client._selfInputPeer) {
|
|
118
|
+
try {
|
|
119
|
+
await client.getMe(true);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
// do nothing
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (!(event instanceof network_1.UpdateConnectionState)) {
|
|
126
|
+
// TODO fix me
|
|
127
|
+
}
|
|
128
|
+
// TODO fix others not being passed
|
|
129
|
+
event = builder.build(event, callback, client._selfInputPeer
|
|
130
|
+
? (0, Helpers_1.returnBigInt)(client._selfInputPeer.userId)
|
|
131
|
+
: undefined);
|
|
132
|
+
if (event) {
|
|
133
|
+
event._client = client;
|
|
134
|
+
if ("_eventName" in event) {
|
|
135
|
+
event._setClient(client);
|
|
136
|
+
event.originalUpdate = args.update;
|
|
137
|
+
event._entities = args.update._entities;
|
|
138
|
+
}
|
|
139
|
+
const filter = await builder.filter(event);
|
|
140
|
+
if (!filter) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
await callback(event);
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
if (e instanceof StopPropagation) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
if (client._errorHandler) {
|
|
151
|
+
await client._errorHandler(e);
|
|
152
|
+
}
|
|
153
|
+
if (client._log.canSend(Logger_1.LogLevel.ERROR)) {
|
|
154
|
+
console.error(e);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports._dispatchUpdate = _dispatchUpdate;
|
|
162
|
+
/** @hidden */
|
|
163
|
+
async function _updateLoop(client) {
|
|
164
|
+
let lastPongAt;
|
|
165
|
+
while (!client._destroyed) {
|
|
166
|
+
await (0, Helpers_1.sleep)(PING_INTERVAL, true);
|
|
167
|
+
if (client._destroyed)
|
|
168
|
+
break;
|
|
169
|
+
if (client._sender.isReconnecting || client._isSwitchingDc) {
|
|
170
|
+
lastPongAt = undefined;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
const ping = () => {
|
|
175
|
+
return client._sender.send(new tl_1.Api.PingDelayDisconnect({
|
|
176
|
+
pingId: (0, Helpers_1.returnBigInt)((0, Helpers_1.getRandomInt)(Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)),
|
|
177
|
+
disconnectDelay: PING_DISCONNECT_DELAY,
|
|
178
|
+
}));
|
|
179
|
+
};
|
|
180
|
+
const pingAt = Date.now();
|
|
181
|
+
const lastInterval = lastPongAt ? pingAt - lastPongAt : undefined;
|
|
182
|
+
if (!lastInterval || lastInterval < PING_INTERVAL_TO_WAKE_UP) {
|
|
183
|
+
await attempts(() => timeout(ping, PING_TIMEOUT), PING_FAIL_ATTEMPTS, PING_FAIL_INTERVAL);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
let wakeUpWarningTimeout = setTimeout(() => {
|
|
187
|
+
_handleUpdate(client, network_1.UpdateConnectionState.disconnected);
|
|
188
|
+
wakeUpWarningTimeout = undefined;
|
|
189
|
+
}, PING_WAKE_UP_WARNING_TIMEOUT);
|
|
190
|
+
await timeout(ping, PING_WAKE_UP_TIMEOUT);
|
|
191
|
+
if (wakeUpWarningTimeout) {
|
|
192
|
+
clearTimeout(wakeUpWarningTimeout);
|
|
193
|
+
wakeUpWarningTimeout = undefined;
|
|
194
|
+
}
|
|
195
|
+
_handleUpdate(client, network_1.UpdateConnectionState.connected);
|
|
196
|
+
}
|
|
197
|
+
lastPongAt = Date.now();
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
// eslint-disable-next-line no-console
|
|
201
|
+
if (client._errorHandler) {
|
|
202
|
+
await client._errorHandler(err);
|
|
203
|
+
}
|
|
204
|
+
if (client._log.canSend(Logger_1.LogLevel.ERROR)) {
|
|
205
|
+
console.error(err);
|
|
206
|
+
}
|
|
207
|
+
lastPongAt = undefined;
|
|
208
|
+
if (client._sender.isReconnecting || client._isSwitchingDc) {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
client._sender.reconnect();
|
|
212
|
+
}
|
|
213
|
+
// We need to send some content-related request at least hourly
|
|
214
|
+
// for Telegram to keep delivering updates, otherwise they will
|
|
215
|
+
// just stop even if we're connected. Do so every 30 minutes.
|
|
216
|
+
if (Date.now() - (client._lastRequest || 0) > 30 * 60 * 1000) {
|
|
217
|
+
try {
|
|
218
|
+
await client.invoke(new tl_1.Api.updates.GetState());
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
// we don't care about errors here
|
|
222
|
+
}
|
|
223
|
+
lastPongAt = undefined;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
await client.disconnect();
|
|
227
|
+
}
|
|
228
|
+
exports._updateLoop = _updateLoop;
|
|
229
|
+
/** @hidden */
|
|
230
|
+
async function attempts(cb, times, pause) {
|
|
231
|
+
for (let i = 0; i < times; i++) {
|
|
232
|
+
try {
|
|
233
|
+
// We need to `return await` here so it can be caught locally
|
|
234
|
+
return await cb();
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
if (i === times - 1) {
|
|
238
|
+
throw err;
|
|
239
|
+
}
|
|
240
|
+
await (0, Helpers_1.sleep)(pause);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
/** @hidden */
|
|
246
|
+
function timeout(cb, ms) {
|
|
247
|
+
let isResolved = false;
|
|
248
|
+
return Promise.race([
|
|
249
|
+
cb(),
|
|
250
|
+
(0, Helpers_1.sleep)(ms).then(() => isResolved ? undefined : Promise.reject(new Error("TIMEOUT"))),
|
|
251
|
+
]).finally(() => {
|
|
252
|
+
isResolved = true;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Api } from "../tl";
|
|
3
|
+
import { TelegramClient } from "./TelegramClient";
|
|
4
|
+
import { EntityLike, FileLike, MarkupLike, MessageIDLike } from "../define";
|
|
5
|
+
interface OnProgress {
|
|
6
|
+
(progress: number): void;
|
|
7
|
+
isCanceled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* interface for uploading files.
|
|
11
|
+
*/
|
|
12
|
+
export interface UploadFileParams {
|
|
13
|
+
/** for browsers this should be an instance of File.<br/>
|
|
14
|
+
* On node you should use {@link CustomFile} class to wrap your file.
|
|
15
|
+
*/
|
|
16
|
+
file: File | CustomFile;
|
|
17
|
+
/** How many workers to use to upload the file. anything above 16 is unstable. */
|
|
18
|
+
workers: number;
|
|
19
|
+
/** a progress callback for the upload. */
|
|
20
|
+
onProgress?: OnProgress;
|
|
21
|
+
maxBufferSize?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A custom file class that mimics the browser's File class.<br/>
|
|
25
|
+
* You should use this whenever you want to upload a file.
|
|
26
|
+
*/
|
|
27
|
+
export declare class CustomFile {
|
|
28
|
+
/** The name of the file to be uploaded. This is what will be shown in telegram */
|
|
29
|
+
name: string;
|
|
30
|
+
/** The size of the file. this should be the exact size to not lose any information */
|
|
31
|
+
size: number;
|
|
32
|
+
/** The full path on the system to where the file is. this will be used to read the file from.<br/>
|
|
33
|
+
* Can be left empty to use a buffer instead
|
|
34
|
+
*/
|
|
35
|
+
path: string;
|
|
36
|
+
/** in case of the no path a buffer can instead be passed instead to upload. */
|
|
37
|
+
buffer?: Buffer;
|
|
38
|
+
constructor(name: string, size: number, path: string, buffer?: Buffer);
|
|
39
|
+
}
|
|
40
|
+
/** @hidden */
|
|
41
|
+
export declare function uploadFile(client: TelegramClient, fileParams: UploadFileParams): Promise<Api.InputFile | Api.InputFileBig>;
|
|
42
|
+
/**
|
|
43
|
+
* Interface for sending files to a chat.
|
|
44
|
+
*/
|
|
45
|
+
export interface SendFileInterface {
|
|
46
|
+
/** a file like object.
|
|
47
|
+
* - can be a localpath. the file name will be used.
|
|
48
|
+
* - can be a Buffer with a ".name" attribute to use as the file name.
|
|
49
|
+
* - can be an external direct URL. Telegram will download the file and send it.
|
|
50
|
+
* - can be an existing media from another message.
|
|
51
|
+
* - can be a handle to a file that was received by using {@link uploadFile}
|
|
52
|
+
* - can be a list when using an album
|
|
53
|
+
* - can be {@link Api.TypeInputMedia} instance. For example if you want to send a dice you would use {@link Api.InputMediaDice}
|
|
54
|
+
*/
|
|
55
|
+
file: FileLike | FileLike[];
|
|
56
|
+
/** Optional caption for the sent media message. can be a list for albums*/
|
|
57
|
+
caption?: string | string[];
|
|
58
|
+
/** If left to false and the file is a path that ends with the extension of an image file or a video file, it will be sent as such. Otherwise always as a document. */
|
|
59
|
+
forceDocument?: boolean;
|
|
60
|
+
/** The size of the file to be uploaded if it needs to be uploaded, which will be determined automatically if not specified. */
|
|
61
|
+
fileSize?: number;
|
|
62
|
+
/** Whether the existing draft should be cleared or not. */
|
|
63
|
+
clearDraft?: boolean;
|
|
64
|
+
/** progress callback that will be called each time a new chunk is downloaded. */
|
|
65
|
+
progressCallback?: OnProgress;
|
|
66
|
+
/** Same as `replyTo` from {@link sendMessage}. */
|
|
67
|
+
replyTo?: MessageIDLike;
|
|
68
|
+
/** Optional attributes that override the inferred ones, like {@link Api.DocumentAttributeFilename} and so on.*/
|
|
69
|
+
attributes?: Api.TypeDocumentAttribute[] | Api.TypeDocumentAttribute[][];
|
|
70
|
+
/** Optional JPEG thumbnail (for documents). Telegram will ignore this parameter unless you pass a .jpg file!<br/>
|
|
71
|
+
* The file must also be small in dimensions and in disk size. Successful thumbnails were files below 20kB and 320x320px.<br/>
|
|
72
|
+
* Width/height and dimensions/size ratios may be important.
|
|
73
|
+
* For Telegram to accept a thumbnail, you must provide the dimensions of the underlying media through `attributes:` with DocumentAttributesVideo.
|
|
74
|
+
*/
|
|
75
|
+
thumb?: FileLike;
|
|
76
|
+
/** If true the audio will be sent as a voice note. */
|
|
77
|
+
voiceNote?: boolean;
|
|
78
|
+
/** If true the video will be sent as a video note, also known as a round video message.*/
|
|
79
|
+
videoNote?: boolean;
|
|
80
|
+
/** Whether the sent video supports streaming or not.<br/>
|
|
81
|
+
* Note that Telegram only recognizes as streamable some formats like MP4, and others like AVI or MKV will not work.<br/>
|
|
82
|
+
* You should convert these to MP4 before sending if you want them to be streamable. Unsupported formats will result in VideoContentTypeError. */
|
|
83
|
+
supportsStreaming?: boolean;
|
|
84
|
+
/** See the {@link parseMode} property for allowed values. Markdown parsing will be used by default. */
|
|
85
|
+
parseMode?: any;
|
|
86
|
+
/** A list of message formatting entities. When provided, the parseMode is ignored. */
|
|
87
|
+
formattingEntities?: Api.TypeMessageEntity[];
|
|
88
|
+
/** Whether the message should notify people in a broadcast channel or not. Defaults to false, which means it will notify them. Set it to True to alter this behaviour. */
|
|
89
|
+
silent?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* If set, the file won't send immediately, and instead it will be scheduled to be automatically sent at a later time.
|
|
92
|
+
*/
|
|
93
|
+
scheduleDate?: number;
|
|
94
|
+
/**
|
|
95
|
+
* The matrix (list of lists), row list or button to be shown after sending the message.<br/>
|
|
96
|
+
* This parameter will only work if you have signed in as a bot. You can also pass your own ReplyMarkup here.
|
|
97
|
+
*/
|
|
98
|
+
buttons?: MarkupLike;
|
|
99
|
+
/** How many workers to use to upload the file. anything above 16 is unstable. */
|
|
100
|
+
workers?: number;
|
|
101
|
+
noforwards?: boolean;
|
|
102
|
+
/** Similar to ``replyTo``, but replies in the linked group of a broadcast channel instead (effectively leaving a "comment to" the specified message).
|
|
103
|
+
|
|
104
|
+
This parameter takes precedence over ``replyTo``.
|
|
105
|
+
If there is no linked chat, `SG_ID_INVALID` is thrown.
|
|
106
|
+
*/
|
|
107
|
+
commentTo?: number | Api.Message;
|
|
108
|
+
/**
|
|
109
|
+
* Used for threads to reply to a specific thread
|
|
110
|
+
*/
|
|
111
|
+
topMsgId?: number | Api.Message;
|
|
112
|
+
}
|
|
113
|
+
interface FileToMediaInterface {
|
|
114
|
+
file: FileLike;
|
|
115
|
+
forceDocument?: boolean;
|
|
116
|
+
fileSize?: number;
|
|
117
|
+
progressCallback?: OnProgress;
|
|
118
|
+
attributes?: Api.TypeDocumentAttribute[];
|
|
119
|
+
thumb?: FileLike;
|
|
120
|
+
voiceNote?: boolean;
|
|
121
|
+
videoNote?: boolean;
|
|
122
|
+
supportsStreaming?: boolean;
|
|
123
|
+
mimeType?: string;
|
|
124
|
+
asImage?: boolean;
|
|
125
|
+
workers?: number;
|
|
126
|
+
}
|
|
127
|
+
/** @hidden */
|
|
128
|
+
export declare function _fileToMedia(client: TelegramClient, { file, forceDocument, fileSize, progressCallback, attributes, thumb, voiceNote, videoNote, supportsStreaming, mimeType, asImage, workers, }: FileToMediaInterface): Promise<{
|
|
129
|
+
fileHandle?: any;
|
|
130
|
+
media?: Api.TypeInputMedia;
|
|
131
|
+
image?: boolean;
|
|
132
|
+
}>;
|
|
133
|
+
/** @hidden */
|
|
134
|
+
export declare function _sendAlbum(client: TelegramClient, entity: EntityLike, { file, caption, forceDocument, fileSize, clearDraft, progressCallback, replyTo, attributes, thumb, parseMode, voiceNote, videoNote, silent, supportsStreaming, scheduleDate, workers, noforwards, commentTo, topMsgId, }: SendFileInterface): Promise<Api.Message>;
|
|
135
|
+
/** @hidden */
|
|
136
|
+
export declare function sendFile(client: TelegramClient, entity: EntityLike, { file, caption, forceDocument, fileSize, clearDraft, progressCallback, replyTo, attributes, thumb, parseMode, formattingEntities, voiceNote, videoNote, buttons, silent, supportsStreaming, scheduleDate, workers, noforwards, commentTo, topMsgId, }: SendFileInterface): Promise<Api.Message>;
|
|
137
|
+
export {};
|