@mtkruto/browser 0.119.0 → 0.119.1
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/esm/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +9 -31
- package/esm/3_errors.js +2 -12
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +0 -99
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +1 -127
- package/esm/client/0_abortable_loop.js +26 -39
- package/esm/client/0_storage_operations.js +179 -218
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/2_account_manager.js +140 -149
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +198 -215
- package/esm/client/2_file_manager.js +255 -262
- package/esm/client/2_network_statistics_manager.js +31 -44
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +101 -111
- package/esm/client/2_update_manager.js +750 -745
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_message_manager.js +503 -508
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +140 -146
- package/esm/client/4_chat_manager.js +161 -169
- package/esm/client/4_checklist_manager.js +26 -39
- package/esm/client/4_context.js +244 -259
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +22 -35
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_composer.js +13 -26
- package/esm/client/6_client.js +866 -896
- package/esm/client/6_client_dispatcher.js +308 -325
- package/esm/client/7_client_worker.js +16 -29
- package/esm/connection/1_connection_tcp.js +55 -82
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +422 -420
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.js +3 -16
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/1_tl_reader.d.ts +1 -1
- package/esm/tl/1_tl_reader.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +95 -103
- package/esm/tl/1_tl_writer.js +169 -178
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +9 -31
- package/script/3_errors.js +2 -12
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +0 -99
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +0 -128
- package/script/client/0_abortable_loop.js +27 -40
- package/script/client/0_storage_operations.js +179 -218
- package/script/client/1_client_plain.js +4 -22
- package/script/client/2_account_manager.js +140 -149
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +199 -216
- package/script/client/2_file_manager.js +255 -262
- package/script/client/2_network_statistics_manager.js +32 -45
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +102 -112
- package/script/client/2_update_manager.js +750 -745
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_message_manager.js +503 -508
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +140 -146
- package/script/client/4_chat_manager.js +161 -169
- package/script/client/4_checklist_manager.js +26 -39
- package/script/client/4_context.js +244 -259
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +22 -35
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_composer.js +13 -26
- package/script/client/6_client.js +866 -896
- package/script/client/6_client_dispatcher.js +308 -325
- package/script/client/7_client_worker.js +16 -29
- package/script/connection/1_connection_tcp.js +55 -82
- package/script/connection/1_connection_web_socket.js +75 -91
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +49 -72
- package/script/session/2_session_encrypted.js +423 -421
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.js +3 -16
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/1_tl_reader.d.ts +1 -1
- package/script/tl/1_tl_reader.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +96 -104
- package/script/tl/1_tl_writer.js +170 -179
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/1_crypto.js +43 -54
- package/script/utilities/2_queue.js +30 -48
|
@@ -18,18 +18,6 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _MessageManager_instances, _a, _MessageManager_c, _MessageManager_LresolveFileId, _MessageManager_checkParams, _MessageManager_constructReplyMarkup, _MessageManager_resolveSendAs, _MessageManager_constructReplyTo, _MessageManager_isM4a, _MessageManager_sendDocumentInner, _MessageManager_sendMedia, _MessageManager_CAPTIONABLE_MESSAGE_TYPES, _MessageManager_editInlineMessageTextInner, _MessageManager_resolveInputMediaInner, _MessageManager_resolveInputMedia, _MessageManager_resolveInputMediaUpload, _MessageManager_sendReaction, _MessageManager_getCachedVoiceTranscription, _MessageManager_cacheVoiceTranscription;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.MessageManager = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -65,31 +53,21 @@ const messageManagerUpdates = [
|
|
|
65
53
|
"updateTranscribedAudio",
|
|
66
54
|
];
|
|
67
55
|
class MessageManager {
|
|
56
|
+
#c;
|
|
57
|
+
#LresolveFileId;
|
|
68
58
|
constructor(c) {
|
|
69
|
-
|
|
70
|
-
_MessageManager_c.set(this, void 0);
|
|
71
|
-
_MessageManager_LresolveFileId.set(this, void 0);
|
|
72
|
-
Object.defineProperty(this, "usernameResolver", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
configurable: true,
|
|
75
|
-
writable: true,
|
|
76
|
-
value: async (v) => {
|
|
77
|
-
const inputPeer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(v).then((v) => _2_tl_js_1.Api.as("inputPeerUser", v));
|
|
78
|
-
return { ...inputPeer, _: "inputUser" };
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
__classPrivateFieldSet(this, _MessageManager_c, c, "f");
|
|
59
|
+
this.#c = c;
|
|
82
60
|
const L = (0, _1_utilities_js_1.getLogger)("MessageManager").client(c.id);
|
|
83
|
-
|
|
61
|
+
this.#LresolveFileId = L.branch("resolveFileId");
|
|
84
62
|
}
|
|
85
63
|
async getMessages(chatId, messageIds) {
|
|
86
64
|
(0, _0_utilities_js_1.checkArray)(messageIds, _0_utilities_js_1.checkMessageId);
|
|
87
|
-
const peer = await
|
|
65
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
88
66
|
let messages_ = new Array();
|
|
89
|
-
const chatId_ = await
|
|
67
|
+
const chatId_ = await this.#c.getInputPeerChatId(peer);
|
|
90
68
|
let shouldFetch = false;
|
|
91
69
|
for (const messageId of messageIds) {
|
|
92
|
-
const message = await
|
|
70
|
+
const message = await this.#c.messageStorage.getMessage(chatId_, messageId);
|
|
93
71
|
if (message === null) {
|
|
94
72
|
messages_ = [];
|
|
95
73
|
shouldFetch = true;
|
|
@@ -101,10 +79,10 @@ class MessageManager {
|
|
|
101
79
|
}
|
|
102
80
|
if (shouldFetch) {
|
|
103
81
|
if ((0, _0_utilities_js_1.canBeInputChannel)(peer)) {
|
|
104
|
-
messages_ = await
|
|
82
|
+
messages_ = await this.#c.invoke({ _: "channels.getMessages", channel: (0, _0_utilities_js_1.toInputChannel)(peer), id: messageIds.map((v) => ({ _: "inputMessageID", id: v })) }).then((v) => _2_tl_js_1.Api.as("messages.channelMessages", v).messages);
|
|
105
83
|
}
|
|
106
84
|
else {
|
|
107
|
-
messages_ = await
|
|
85
|
+
messages_ = await this.#c.invoke({
|
|
108
86
|
_: "messages.getMessages",
|
|
109
87
|
id: messageIds.map((v) => ({ _: "inputMessageID", id: v })),
|
|
110
88
|
}).then((v) => _2_tl_js_1.Api.as("messages.messages", v).messages);
|
|
@@ -167,9 +145,23 @@ class MessageManager {
|
|
|
167
145
|
}
|
|
168
146
|
return [text, entities];
|
|
169
147
|
}
|
|
148
|
+
#checkParams(params) {
|
|
149
|
+
if (params && "replyMarkup" in params && params.replyMarkup !== undefined) {
|
|
150
|
+
this.#c.storage.assertBot("replyMarkup");
|
|
151
|
+
}
|
|
152
|
+
if (params && "businessConnectionId" in params && params.businessConnectionId !== undefined) {
|
|
153
|
+
this.#c.storage.assertBot("businessConnectionId");
|
|
154
|
+
}
|
|
155
|
+
if (params && "sendAs" in params && params.sendAs !== undefined) {
|
|
156
|
+
this.#c.storage.assertUser("sendAs");
|
|
157
|
+
}
|
|
158
|
+
if (params && "sendAt" in params && params.sendAt !== undefined) {
|
|
159
|
+
this.#c.storage.assertUser("businessConsendAtnectionId");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
170
162
|
parseText(text_, params) {
|
|
171
|
-
const [text, entities_] =
|
|
172
|
-
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_2.messageEntityToTlObject)(v,
|
|
163
|
+
const [text, entities_] = MessageManager.parseText(text_, params?.entities ?? [], params?.parseMode ?? this.#c.parseMode);
|
|
164
|
+
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_2.messageEntityToTlObject)(v, this.#c.getPeer)) : undefined;
|
|
173
165
|
return [text, entities];
|
|
174
166
|
}
|
|
175
167
|
async updatesToMessages(chatId, updates, businessConnectionId) {
|
|
@@ -211,24 +203,24 @@ class MessageManager {
|
|
|
211
203
|
let poll = null;
|
|
212
204
|
let pollResults = null;
|
|
213
205
|
if (pollId) {
|
|
214
|
-
[poll, pollResults] = await Promise.all([
|
|
206
|
+
[poll, pollResults] = await Promise.all([this.#c.messageStorage.getPoll(pollId), this.#c.messageStorage.getPollResults(pollId)]);
|
|
215
207
|
}
|
|
216
|
-
const message = await (0, _3_types_js_2.constructMessage)(message_,
|
|
208
|
+
const message = await (0, _3_types_js_2.constructMessage)(message_, this.#c.getPeer, this.getMessage.bind(this), this.#c.fileManager.getStickerSetName.bind(this.#c.fileManager), r, business, poll ?? undefined, pollResults ?? undefined);
|
|
217
209
|
if (!poll && mediaPoll) {
|
|
218
|
-
await
|
|
210
|
+
await this.#c.messageStorage.setPoll(mediaPoll.poll.id, mediaPoll.poll);
|
|
219
211
|
}
|
|
220
212
|
if (!pollResults && mediaPoll) {
|
|
221
|
-
await
|
|
213
|
+
await this.#c.messageStorage.setPollResults(mediaPoll.poll.id, mediaPoll.results);
|
|
222
214
|
}
|
|
223
215
|
return message;
|
|
224
216
|
}
|
|
225
217
|
async forwardMessages(from, to, messageIds, params) {
|
|
226
218
|
(0, _0_utilities_js_1.checkArray)(messageIds, _0_utilities_js_1.checkMessageId);
|
|
227
|
-
const result = await
|
|
219
|
+
const result = await this.#c.invoke({ _: "messages.forwardMessages", from_peer: await this.#c.getInputPeer(from), to_peer: await this.#c.getInputPeer(to), id: messageIds, random_id: messageIds.map(() => (0, _1_utilities_js_1.getRandomId)()), silent: params?.isSilent || undefined, top_msg_id: params?.messageThreadId, noforwards: params?.isSilent || undefined, send_as: params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined, drop_author: params?.dropSenderName || undefined, drop_media_captions: params?.dropCaption || undefined });
|
|
228
220
|
return await this.updatesToMessages(to, result);
|
|
229
221
|
}
|
|
230
222
|
async getHistory(chatId, params) {
|
|
231
|
-
|
|
223
|
+
this.#c.storage.assertUser("getHistory");
|
|
232
224
|
const limit = (0, _0_utilities_js_1.getLimit)(params?.limit);
|
|
233
225
|
let offsetId = params?.offsetId ?? 0;
|
|
234
226
|
if (offsetId < 0) {
|
|
@@ -238,12 +230,12 @@ class MessageManager {
|
|
|
238
230
|
if (offsetDate < 0) {
|
|
239
231
|
offsetDate = 0;
|
|
240
232
|
}
|
|
241
|
-
const peer = await
|
|
233
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
242
234
|
const messages = new Array();
|
|
243
235
|
if (messages.length > 0) {
|
|
244
236
|
offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
|
|
245
237
|
}
|
|
246
|
-
const result = await
|
|
238
|
+
const result = await this.#c.invoke({
|
|
247
239
|
_: "messages.getHistory",
|
|
248
240
|
peer: peer,
|
|
249
241
|
offset_id: offsetId,
|
|
@@ -263,11 +255,28 @@ class MessageManager {
|
|
|
263
255
|
}
|
|
264
256
|
return messages;
|
|
265
257
|
}
|
|
258
|
+
usernameResolver = async (v) => {
|
|
259
|
+
const inputPeer = await this.#c.getInputPeer(v).then((v) => _2_tl_js_1.Api.as("inputPeerUser", v));
|
|
260
|
+
return { ...inputPeer, _: "inputUser" };
|
|
261
|
+
};
|
|
262
|
+
async #constructReplyMarkup(params) {
|
|
263
|
+
if (params?.replyMarkup) {
|
|
264
|
+
this.#c.storage.assertBot("replyMarkup");
|
|
265
|
+
return await (0, _3_types_js_2.replyMarkupToTlObject)(params.replyMarkup, this.usernameResolver.bind(this));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async #resolveSendAs(params) {
|
|
269
|
+
const sendAs = params?.sendAs;
|
|
270
|
+
if (sendAs !== undefined) {
|
|
271
|
+
this.#c.storage.assertUser("sendAs");
|
|
272
|
+
return sendAs ? await this.#c.getInputPeer(sendAs) : undefined;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
266
275
|
async sendMessageDraft(chatId, draftId, text, params) {
|
|
267
|
-
|
|
276
|
+
this.#c.storage.assertBot("sendMessageDraft");
|
|
268
277
|
const [message, entities] = this.parseText(text, params);
|
|
269
|
-
const peer = await
|
|
270
|
-
await
|
|
278
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
279
|
+
await this.#c.invoke({
|
|
271
280
|
_: "messages.setTyping",
|
|
272
281
|
peer,
|
|
273
282
|
action: { _: "sendMessageTextDraftAction", random_id: BigInt(draftId), text: { _: "textWithEntities", text: message, entities: entities ?? [] } },
|
|
@@ -275,22 +284,22 @@ class MessageManager {
|
|
|
275
284
|
});
|
|
276
285
|
}
|
|
277
286
|
async sendMessage(chatId, text, params) {
|
|
278
|
-
|
|
287
|
+
this.#checkParams(params);
|
|
279
288
|
const [message, entities] = this.parseText(text, params);
|
|
280
|
-
const replyMarkup = await
|
|
281
|
-
const peer = await
|
|
289
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
290
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
282
291
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
283
292
|
const noWebpage = params?.linkPreview?.isDisabled ? true : undefined;
|
|
284
293
|
const invertMedia = params?.linkPreview?.isAboveText ? true : undefined;
|
|
285
294
|
const silent = params?.isSilent ? true : undefined;
|
|
286
295
|
const noforwards = params?.isContentProtected ? true : undefined;
|
|
287
|
-
const sendAs = await
|
|
296
|
+
const sendAs = await this.#resolveSendAs(params);
|
|
288
297
|
const effect = params?.effectId ? BigInt(params.effectId) : undefined;
|
|
289
298
|
const schedule_date = params?.sendAt;
|
|
290
299
|
const allow_paid_floodskip = params?.isPaidBroadcast ? true : undefined;
|
|
291
300
|
let result;
|
|
292
301
|
if (!noWebpage && params?.linkPreview?.url) {
|
|
293
|
-
result = await
|
|
302
|
+
result = await this.#c.invoke({
|
|
294
303
|
_: "messages.sendMedia",
|
|
295
304
|
peer,
|
|
296
305
|
random_id: randomId,
|
|
@@ -305,7 +314,7 @@ class MessageManager {
|
|
|
305
314
|
invert_media: invertMedia,
|
|
306
315
|
silent,
|
|
307
316
|
noforwards,
|
|
308
|
-
reply_to: await
|
|
317
|
+
reply_to: await this.#constructReplyTo(params),
|
|
309
318
|
send_as: sendAs,
|
|
310
319
|
entities,
|
|
311
320
|
reply_markup: replyMarkup,
|
|
@@ -315,7 +324,7 @@ class MessageManager {
|
|
|
315
324
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
316
325
|
}
|
|
317
326
|
else {
|
|
318
|
-
result = await
|
|
327
|
+
result = await this.#c.invoke({
|
|
319
328
|
_: "messages.sendMessage",
|
|
320
329
|
peer,
|
|
321
330
|
random_id: randomId,
|
|
@@ -324,7 +333,7 @@ class MessageManager {
|
|
|
324
333
|
invert_media: invertMedia,
|
|
325
334
|
silent,
|
|
326
335
|
noforwards,
|
|
327
|
-
reply_to: await
|
|
336
|
+
reply_to: await this.#constructReplyTo(params),
|
|
328
337
|
send_as: sendAs,
|
|
329
338
|
entities,
|
|
330
339
|
reply_markup: replyMarkup,
|
|
@@ -336,21 +345,38 @@ class MessageManager {
|
|
|
336
345
|
const message_ = (await this.updatesToMessages(chatId, result, params?.businessConnectionId))[0];
|
|
337
346
|
return (0, _3_types_js_2.assertMessageType)(message_, "text");
|
|
338
347
|
}
|
|
348
|
+
async #constructReplyTo(params) {
|
|
349
|
+
const topMsgId = params?.messageThreadId;
|
|
350
|
+
if (!params?.replyTo) {
|
|
351
|
+
if (topMsgId) {
|
|
352
|
+
return { _: "inputReplyToMessage", reply_to_msg_id: topMsgId, top_msg_id: topMsgId };
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if ("messageId" in params.replyTo) {
|
|
359
|
+
return { _: "inputReplyToMessage", reply_to_msg_id: params.replyTo.messageId, top_msg_id: topMsgId, quote_text: params.replyTo.quote?.text, quote_entities: await Promise.all(params.replyTo.quote?.entities.map((v) => (0, _3_types_js_2.messageEntityToTlObject)(v, this.#c.getPeer)) ?? []), quote_offset: params.replyTo.quote?.offset };
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
return { _: "inputReplyToStory", peer: await this.#c.getInputPeer(params.replyTo.chatId), story_id: params.replyTo.storyId };
|
|
363
|
+
}
|
|
364
|
+
}
|
|
339
365
|
async sendVenue(chatId, latitude, longitude, title, address, params) {
|
|
340
|
-
|
|
341
|
-
const peer = await
|
|
366
|
+
this.#checkParams(params);
|
|
367
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
342
368
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
343
369
|
const silent = params?.isSilent ? true : undefined;
|
|
344
370
|
const noforwards = params?.isContentProtected ? true : undefined;
|
|
345
|
-
const sendAs = params?.sendAs ? await
|
|
346
|
-
const replyMarkup = await
|
|
347
|
-
const result = await
|
|
371
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
372
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
373
|
+
const result = await this.#c.invoke({
|
|
348
374
|
_: "messages.sendMedia",
|
|
349
375
|
peer,
|
|
350
376
|
random_id: randomId,
|
|
351
377
|
silent,
|
|
352
378
|
noforwards,
|
|
353
|
-
reply_to: await
|
|
379
|
+
reply_to: await this.#constructReplyTo(params),
|
|
354
380
|
send_as: sendAs,
|
|
355
381
|
reply_markup: replyMarkup,
|
|
356
382
|
media: {
|
|
@@ -375,20 +401,20 @@ class MessageManager {
|
|
|
375
401
|
return (0, _3_types_js_2.assertMessageType)(message, "venue");
|
|
376
402
|
}
|
|
377
403
|
async sendContact(chatId, firstName, number, params) {
|
|
378
|
-
|
|
379
|
-
const peer = await
|
|
404
|
+
this.#checkParams(params);
|
|
405
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
380
406
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
381
407
|
const silent = params?.isSilent ? true : undefined;
|
|
382
408
|
const noforwards = params?.isContentProtected ? true : undefined;
|
|
383
|
-
const sendAs = params?.sendAs ? await
|
|
384
|
-
const replyMarkup = await
|
|
385
|
-
const result = await
|
|
409
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
410
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
411
|
+
const result = await this.#c.invoke({
|
|
386
412
|
_: "messages.sendMedia",
|
|
387
413
|
peer,
|
|
388
414
|
random_id: randomId,
|
|
389
415
|
silent,
|
|
390
416
|
noforwards,
|
|
391
|
-
reply_to: await
|
|
417
|
+
reply_to: await this.#constructReplyTo(params),
|
|
392
418
|
send_as: sendAs,
|
|
393
419
|
reply_markup: replyMarkup,
|
|
394
420
|
media: {
|
|
@@ -407,20 +433,20 @@ class MessageManager {
|
|
|
407
433
|
return (0, _3_types_js_2.assertMessageType)(message, "contact");
|
|
408
434
|
}
|
|
409
435
|
async sendDice(chatId, params) {
|
|
410
|
-
|
|
411
|
-
const peer = await
|
|
436
|
+
this.#checkParams(params);
|
|
437
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
412
438
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
413
439
|
const silent = params?.isSilent ? true : undefined;
|
|
414
440
|
const noforwards = params?.isContentProtected ? true : undefined;
|
|
415
|
-
const sendAs = params?.sendAs ? await
|
|
416
|
-
const replyMarkup = await
|
|
417
|
-
const result = await
|
|
441
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
442
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
443
|
+
const result = await this.#c.invoke({
|
|
418
444
|
_: "messages.sendMedia",
|
|
419
445
|
peer,
|
|
420
446
|
random_id: randomId,
|
|
421
447
|
silent,
|
|
422
448
|
noforwards,
|
|
423
|
-
reply_to: await
|
|
449
|
+
reply_to: await this.#constructReplyTo(params),
|
|
424
450
|
send_as: sendAs,
|
|
425
451
|
reply_markup: replyMarkup,
|
|
426
452
|
media: {
|
|
@@ -436,20 +462,20 @@ class MessageManager {
|
|
|
436
462
|
return (0, _3_types_js_2.assertMessageType)(message, "dice");
|
|
437
463
|
}
|
|
438
464
|
async sendLocation(chatId, latitude, longitude, params) {
|
|
439
|
-
|
|
440
|
-
const peer = await
|
|
465
|
+
this.#checkParams(params);
|
|
466
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
441
467
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
442
468
|
const silent = params?.isSilent ? true : undefined;
|
|
443
469
|
const noforwards = params?.isContentProtected ? true : undefined;
|
|
444
|
-
const sendAs = params?.sendAs ? await
|
|
445
|
-
const replyMarkup = await
|
|
446
|
-
const result = await
|
|
470
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
471
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
472
|
+
const result = await this.#c.invoke({
|
|
447
473
|
_: "messages.sendMedia",
|
|
448
474
|
peer,
|
|
449
475
|
random_id: randomId,
|
|
450
476
|
silent,
|
|
451
477
|
noforwards,
|
|
452
|
-
reply_to: await
|
|
478
|
+
reply_to: await this.#constructReplyTo(params),
|
|
453
479
|
send_as: sendAs,
|
|
454
480
|
reply_markup: replyMarkup,
|
|
455
481
|
media: params?.livePeriod !== undefined
|
|
@@ -483,18 +509,18 @@ class MessageManager {
|
|
|
483
509
|
return (0, _3_types_js_2.assertMessageType)(message, "location");
|
|
484
510
|
}
|
|
485
511
|
async sendVideoNote(chatId, audio, params) {
|
|
486
|
-
|
|
487
|
-
const message = await
|
|
512
|
+
this.#checkParams(params);
|
|
513
|
+
const message = await this.#sendDocumentInner(chatId, audio, params, _3_types_js_2.FileType.VideoNote, [
|
|
488
514
|
{ _: "documentAttributeVideo", round_message: true, w: params?.length ?? 0, h: params?.length ?? 0, duration: params?.duration ?? 0 },
|
|
489
515
|
], false, VIDEO_NOTE_MIME_TYPES, () => "video_note.mp4");
|
|
490
516
|
return (0, _3_types_js_2.assertMessageType)(message, "videoNote");
|
|
491
517
|
}
|
|
492
518
|
async sendAudio(chatId, audio, params) {
|
|
493
|
-
|
|
494
|
-
const message = await
|
|
519
|
+
this.#checkParams(params);
|
|
520
|
+
const message = await this.#sendDocumentInner(chatId, audio, params, _3_types_js_2.FileType.Audio, [
|
|
495
521
|
{ _: "documentAttributeAudio", duration: params?.duration ?? 0, performer: params?.performer, title: params?.title },
|
|
496
522
|
], undefined, AUDIO_MIME_TYPES, (firstPart) => {
|
|
497
|
-
if (
|
|
523
|
+
if (MessageManager.#isM4a(firstPart)) {
|
|
498
524
|
return "audio.m4a";
|
|
499
525
|
}
|
|
500
526
|
else {
|
|
@@ -503,15 +529,18 @@ class MessageManager {
|
|
|
503
529
|
});
|
|
504
530
|
return (0, _3_types_js_2.assertMessageType)(message, "audio");
|
|
505
531
|
}
|
|
532
|
+
static #isM4a(firstPart) {
|
|
533
|
+
return firstPart.length >= 10 && (0, _0_deps_js_1.startsWith)(firstPart.subarray(4), new Uint8Array([0x66, 0x74, 0x79, 0x70, 0x4D, 0x34]));
|
|
534
|
+
}
|
|
506
535
|
async sendVoice(chatId, voice, params) {
|
|
507
|
-
|
|
508
|
-
const message = await
|
|
536
|
+
this.#checkParams(params);
|
|
537
|
+
const message = await this.#sendDocumentInner(chatId, voice, params, _3_types_js_2.FileType.VoiceNote, [
|
|
509
538
|
{ _: "documentAttributeAudio", voice: true, duration: params?.duration ?? 0 },
|
|
510
539
|
], undefined, VOICE_MIME_TYPES, (firstPart) => {
|
|
511
540
|
if ((0, _0_deps_js_1.startsWith)(firstPart, new Uint8Array([0x4F, 0x67, 0x67]))) {
|
|
512
541
|
return "voice.ogg";
|
|
513
542
|
}
|
|
514
|
-
else if (
|
|
543
|
+
else if (MessageManager.#isM4a(firstPart)) {
|
|
515
544
|
return "voice.m4a";
|
|
516
545
|
}
|
|
517
546
|
else {
|
|
@@ -521,8 +550,8 @@ class MessageManager {
|
|
|
521
550
|
return (0, _3_types_js_2.assertMessageType)(message, "voice");
|
|
522
551
|
}
|
|
523
552
|
async sendAnimation(chatId, animation, params) {
|
|
524
|
-
|
|
525
|
-
const message = await
|
|
553
|
+
this.#checkParams(params);
|
|
554
|
+
const message = await this.#sendDocumentInner(chatId, animation, params, _3_types_js_2.FileType.Animation, [
|
|
526
555
|
{ _: "documentAttributeAnimated" },
|
|
527
556
|
{ _: "documentAttributeVideo", supports_streaming: true, w: params?.width ?? 0, h: params?.height ?? 0, duration: params?.duration ?? 0 },
|
|
528
557
|
], undefined, ANIMATION_MIME_TYPES, (firstPart) => {
|
|
@@ -536,20 +565,66 @@ class MessageManager {
|
|
|
536
565
|
return (0, _3_types_js_2.assertMessageType)(message, "animation");
|
|
537
566
|
}
|
|
538
567
|
async sendVideo(chatId, video, params) {
|
|
539
|
-
|
|
540
|
-
const message = await
|
|
568
|
+
this.#checkParams(params);
|
|
569
|
+
const message = await this.#sendDocumentInner(chatId, video, params, _3_types_js_2.FileType.Video, [
|
|
541
570
|
{ _: "documentAttributeVideo", supports_streaming: params?.supportsStreaming ? true : undefined, w: params?.width ?? 0, h: params?.height ?? 0, duration: params?.duration ?? 0 },
|
|
542
571
|
], undefined, VIDEO_MIME_TYPES, () => "video.mp4");
|
|
543
572
|
return (0, _3_types_js_2.assertMessageType)(message, "video");
|
|
544
573
|
}
|
|
574
|
+
async #sendDocumentInner(chatId, document, params, fileType, otherAttribs, urlSupported = true, expectedMimeTypes, createName) {
|
|
575
|
+
let media = null;
|
|
576
|
+
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
577
|
+
const ttl_seconds = params && "selfDestruct" in params && typeof params.selfDestruct !== undefined ? (0, _3_types_js_1.selfDestructOptionToInt)(params.selfDestruct) : undefined;
|
|
578
|
+
if (typeof document === "string") {
|
|
579
|
+
const fileId = this.resolveFileId(document, fileType);
|
|
580
|
+
if (fileId !== null) {
|
|
581
|
+
media = { _: "inputMediaDocument", id: { ...fileId, _: "inputDocument" }, spoiler, query: otherAttribs.find((v) => _2_tl_js_1.Api.is("documentAttributeSticker", v))?.alt || undefined, ttl_seconds };
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (media === null) {
|
|
585
|
+
if (typeof document === "string" && (0, _0_utilities_js_1.isHttpUrl)(document)) {
|
|
586
|
+
if (!urlSupported) {
|
|
587
|
+
throw new _0_errors_js_1.InputError("URL not supported.");
|
|
588
|
+
}
|
|
589
|
+
media = { _: "inputMediaDocumentExternal", url: document, spoiler, ttl_seconds };
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
let mimeType;
|
|
593
|
+
const file = await this.#c.fileManager.upload(document, params, (name, firstPart) => {
|
|
594
|
+
if (!params?.fileName && firstPart && createName) {
|
|
595
|
+
name = createName(firstPart);
|
|
596
|
+
}
|
|
597
|
+
mimeType = params?.mimeType ?? (0, _0_deps_js_1.contentType)(name.split(".").slice(-1)[0]);
|
|
598
|
+
if (name.endsWith(".tgs") && fileType === _3_types_js_2.FileType.Document) {
|
|
599
|
+
name += "-";
|
|
600
|
+
}
|
|
601
|
+
return name;
|
|
602
|
+
});
|
|
603
|
+
mimeType ??= FALLBACK_MIME_TYPE;
|
|
604
|
+
if (mimeType && expectedMimeTypes && !expectedMimeTypes.includes(mimeType)) {
|
|
605
|
+
(0, _0_deps_js_1.unreachable)();
|
|
606
|
+
}
|
|
607
|
+
if (_2_tl_js_1.Api.is("inputFileStoryDocument", file)) {
|
|
608
|
+
(0, _0_deps_js_1.unreachable)();
|
|
609
|
+
}
|
|
610
|
+
let thumb = undefined;
|
|
611
|
+
if (params?.thumbnail) {
|
|
612
|
+
thumb = await this.#c.fileManager.upload(params.thumbnail, { chunkSize: params?.chunkSize, signal: params?.signal });
|
|
613
|
+
}
|
|
614
|
+
media = { _: "inputMediaUploadedDocument", file, thumb, spoiler, attributes: [{ _: "documentAttributeFilename", file_name: file.name }, ...otherAttribs], mime_type: mimeType, force_file: fileType === _3_types_js_2.FileType.Document ? true : undefined, ttl_seconds };
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
const message = await this.#sendMedia(chatId, media, params);
|
|
618
|
+
return message;
|
|
619
|
+
}
|
|
545
620
|
async sendDocument(chatId, document, params) {
|
|
546
|
-
|
|
547
|
-
const message = await
|
|
621
|
+
this.#checkParams(params);
|
|
622
|
+
const message = await this.#sendDocumentInner(chatId, document, params, _3_types_js_2.FileType.Document, []);
|
|
548
623
|
return (0, _3_types_js_2.assertMessageType)(message, "document");
|
|
549
624
|
}
|
|
550
625
|
async sendSticker(chatId, sticker, params) {
|
|
551
|
-
|
|
552
|
-
const message = await
|
|
626
|
+
this.#checkParams(params);
|
|
627
|
+
const message = await this.#sendDocumentInner(chatId, sticker, params, _3_types_js_2.FileType.Sticker, [{ _: "documentAttributeSticker", alt: params?.emoji || "", stickerset: { _: "inputStickerSetEmpty" } }], undefined, STICKER_MIME_TYPES, (firstPart) => {
|
|
553
628
|
if ((0, _0_deps_js_1.startsWith)(firstPart, new Uint8Array([0x1F, 0x8B]))) {
|
|
554
629
|
return "file.tgs";
|
|
555
630
|
}
|
|
@@ -563,7 +638,7 @@ class MessageManager {
|
|
|
563
638
|
return (0, _3_types_js_2.assertMessageType)(message, "sticker");
|
|
564
639
|
}
|
|
565
640
|
async sendPhoto(chatId, photo, params) {
|
|
566
|
-
|
|
641
|
+
this.#checkParams(params);
|
|
567
642
|
let media = null;
|
|
568
643
|
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
569
644
|
const ttl_seconds = params && "selfDestruct" in params && params.selfDestruct !== undefined ? (0, _3_types_js_1.selfDestructOptionToInt)(params.selfDestruct) : undefined;
|
|
@@ -578,7 +653,7 @@ class MessageManager {
|
|
|
578
653
|
media = { _: "inputMediaPhotoExternal", url: photo, spoiler, ttl_seconds: (params && "selfDestruct" in params && params.selfDestruct !== undefined) ? (0, _3_types_js_1.selfDestructOptionToInt)(params.selfDestruct) : undefined };
|
|
579
654
|
}
|
|
580
655
|
else {
|
|
581
|
-
const file = await
|
|
656
|
+
const file = await this.#c.fileManager.upload(photo, params, (name, firstPart) => {
|
|
582
657
|
if (params?.fileName || !firstPart || name.includes(".")) {
|
|
583
658
|
return name;
|
|
584
659
|
}
|
|
@@ -592,9 +667,44 @@ class MessageManager {
|
|
|
592
667
|
media = { _: "inputMediaUploadedPhoto", file, spoiler, ttl_seconds: (params && "selfDestruct" in params && params.selfDestruct !== undefined) ? (0, _3_types_js_1.selfDestructOptionToInt)(params.selfDestruct) : undefined };
|
|
593
668
|
}
|
|
594
669
|
}
|
|
595
|
-
const message = await
|
|
670
|
+
const message = await this.#sendMedia(chatId, media, params);
|
|
596
671
|
return (0, _3_types_js_2.assertMessageType)(message, "photo");
|
|
597
672
|
}
|
|
673
|
+
async #sendMedia(chatId, media, params) {
|
|
674
|
+
if (params?.starCount !== undefined) {
|
|
675
|
+
if (params.starCount <= 0) {
|
|
676
|
+
throw new _0_errors_js_1.InputError("starCount cannot be zero or negative");
|
|
677
|
+
}
|
|
678
|
+
media = { _: "inputMediaPaidMedia", stars_amount: BigInt(params.starCount), extended_media: [media] };
|
|
679
|
+
}
|
|
680
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
681
|
+
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
682
|
+
const silent = params?.isSilent ? true : undefined;
|
|
683
|
+
const noforwards = params?.isContentProtected ? true : undefined;
|
|
684
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
685
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
686
|
+
const caption_ = params?.caption;
|
|
687
|
+
const parseResult = caption_ !== undefined ? this.parseText(caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
688
|
+
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
689
|
+
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
690
|
+
const result = await this.#c.invoke({
|
|
691
|
+
_: "messages.sendMedia",
|
|
692
|
+
peer,
|
|
693
|
+
random_id: randomId,
|
|
694
|
+
silent,
|
|
695
|
+
noforwards,
|
|
696
|
+
reply_markup: replyMarkup,
|
|
697
|
+
reply_to: await this.#constructReplyTo(params),
|
|
698
|
+
send_as: sendAs,
|
|
699
|
+
media,
|
|
700
|
+
message: caption ?? "",
|
|
701
|
+
entities: captionEntities,
|
|
702
|
+
effect: params?.effectId ? BigInt(params.effectId) : undefined,
|
|
703
|
+
schedule_date: params?.sendAt,
|
|
704
|
+
allow_paid_floodskip: params?.isPaidBroadcast ? true : undefined,
|
|
705
|
+
}, { businessConnectionId: params?.businessConnectionId });
|
|
706
|
+
return (await this.updatesToMessages(chatId, result, params?.businessConnectionId))[0];
|
|
707
|
+
}
|
|
598
708
|
resolveFileId(maybeFileId, expectedFileType) {
|
|
599
709
|
expectedFileType = Array.isArray(expectedFileType) ? expectedFileType : [expectedFileType];
|
|
600
710
|
let fileId = null;
|
|
@@ -602,7 +712,7 @@ class MessageManager {
|
|
|
602
712
|
fileId = (0, _3_types_js_1.deserializeFileId)(maybeFileId);
|
|
603
713
|
}
|
|
604
714
|
catch (err) {
|
|
605
|
-
|
|
715
|
+
this.#LresolveFileId.warning(err);
|
|
606
716
|
}
|
|
607
717
|
if (fileId !== null) {
|
|
608
718
|
if (!expectedFileType.includes(fileId.type)) {
|
|
@@ -617,7 +727,7 @@ class MessageManager {
|
|
|
617
727
|
return null;
|
|
618
728
|
}
|
|
619
729
|
async sendPoll(chatId, question, options, params) {
|
|
620
|
-
|
|
730
|
+
this.#checkParams(params);
|
|
621
731
|
question = question?.trim();
|
|
622
732
|
if (!question) {
|
|
623
733
|
throw new Error("Question must not be empty.");
|
|
@@ -625,12 +735,12 @@ class MessageManager {
|
|
|
625
735
|
if (!Array.isArray(options) || options.length < 2) {
|
|
626
736
|
throw new Error("There must be at least two options.");
|
|
627
737
|
}
|
|
628
|
-
const peer = await
|
|
738
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
629
739
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
630
740
|
const silent = params?.isSilent ? true : undefined;
|
|
631
741
|
const noforwards = params?.isContentProtected ? true : undefined;
|
|
632
|
-
const sendAs = params?.sendAs ? await
|
|
633
|
-
const replyMarkup = await
|
|
742
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
743
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
634
744
|
const explanation = params?.explanation;
|
|
635
745
|
const parseResult = explanation !== undefined ? this.parseText(explanation, { parseMode: params?.explanationParseMode, entities: params?.explanationEntities }) : undefined;
|
|
636
746
|
const solution = parseResult === undefined ? undefined : parseResult[0];
|
|
@@ -644,14 +754,14 @@ class MessageManager {
|
|
|
644
754
|
const questionParseResult = this.parseText(question, { parseMode: params?.questionParseMode, entities: params?.questionEntities });
|
|
645
755
|
const poll = { _: "poll", id: (0, _1_utilities_js_1.getRandomId)(), answers, question: { _: "textWithEntities", text: questionParseResult[0], entities: questionParseResult[1] ?? [] }, closed: params?.isClosed ? true : undefined, close_date: params?.closeDate, close_period: params?.openPeriod ? params.openPeriod : undefined, multiple_choice: params?.allowMultipleAnswers ? true : undefined, public_voters: params?.isAnonymous === false ? true : undefined, quiz: params?.type === "quiz" ? true : undefined };
|
|
646
756
|
const media = { _: "inputMediaPoll", poll, correct_answers: params?.correctOptionIndex !== undefined ? [(0, _1_utilities_js_1.encodeText)(String(params.correctOptionIndex))] : undefined, solution, solution_entities: solutionEntities };
|
|
647
|
-
const result = await
|
|
757
|
+
const result = await this.#c.invoke({
|
|
648
758
|
_: "messages.sendMedia",
|
|
649
759
|
peer,
|
|
650
760
|
random_id: randomId,
|
|
651
761
|
silent,
|
|
652
762
|
noforwards,
|
|
653
763
|
reply_markup: replyMarkup,
|
|
654
|
-
reply_to: await
|
|
764
|
+
reply_to: await this.#constructReplyTo(params),
|
|
655
765
|
send_as: sendAs,
|
|
656
766
|
media,
|
|
657
767
|
message: "",
|
|
@@ -663,8 +773,8 @@ class MessageManager {
|
|
|
663
773
|
return (0, _3_types_js_2.assertMessageType)(message, "poll");
|
|
664
774
|
}
|
|
665
775
|
async sendChecklist(chatId, title, items, params) {
|
|
666
|
-
|
|
667
|
-
|
|
776
|
+
this.#c.storage.assertUser("sendChecklist");
|
|
777
|
+
this.#checkParams(params);
|
|
668
778
|
title = title?.trim();
|
|
669
779
|
if (!title) {
|
|
670
780
|
throw new Error("Title must not be empty.");
|
|
@@ -672,11 +782,11 @@ class MessageManager {
|
|
|
672
782
|
if (!Array.isArray(items) || items.length < 1) {
|
|
673
783
|
throw new Error("There must be at least one item.");
|
|
674
784
|
}
|
|
675
|
-
const peer = await
|
|
785
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
676
786
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
677
787
|
const silent = params?.isSilent ? true : undefined;
|
|
678
788
|
const noforwards = params?.isContentProtected ? true : undefined;
|
|
679
|
-
const sendAs = params?.sendAs ? await
|
|
789
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
680
790
|
const list = items.map((v, i) => {
|
|
681
791
|
const text = v.text;
|
|
682
792
|
const entities = v.entities;
|
|
@@ -692,13 +802,13 @@ class MessageManager {
|
|
|
692
802
|
others_can_complete: params?.isCompletableByOthers ? true : undefined,
|
|
693
803
|
};
|
|
694
804
|
const media = { _: "inputMediaTodo", todo };
|
|
695
|
-
const result = await
|
|
805
|
+
const result = await this.#c.invoke({
|
|
696
806
|
_: "messages.sendMedia",
|
|
697
807
|
peer,
|
|
698
808
|
random_id: randomId,
|
|
699
809
|
silent,
|
|
700
810
|
noforwards,
|
|
701
|
-
reply_to: await
|
|
811
|
+
reply_to: await this.#constructReplyTo(params),
|
|
702
812
|
send_as: sendAs,
|
|
703
813
|
media,
|
|
704
814
|
message: "",
|
|
@@ -710,26 +820,26 @@ class MessageManager {
|
|
|
710
820
|
return (0, _3_types_js_2.assertMessageType)(message, "checklist");
|
|
711
821
|
}
|
|
712
822
|
async editMessageReplyMarkup(chatId, messageId, params) {
|
|
713
|
-
|
|
714
|
-
const result = await
|
|
823
|
+
this.#checkParams(params);
|
|
824
|
+
const result = await this.#c.invoke({
|
|
715
825
|
_: "messages.editMessage",
|
|
716
826
|
id: (0, _0_utilities_js_1.checkMessageId)(messageId),
|
|
717
|
-
peer: await
|
|
718
|
-
reply_markup: await
|
|
827
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
828
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
719
829
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
720
830
|
const message_ = (await this.updatesToMessages(chatId, result))[0];
|
|
721
831
|
return message_;
|
|
722
832
|
}
|
|
723
833
|
async editInlineMessageReplyMarkup(inlineMessageId, params) {
|
|
724
834
|
const id = await (0, _3_types_js_2.deserializeInlineMessageId)(inlineMessageId);
|
|
725
|
-
await
|
|
835
|
+
await this.#c.invoke({
|
|
726
836
|
_: "messages.editInlineBotMessage",
|
|
727
837
|
id,
|
|
728
|
-
reply_markup: await
|
|
838
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
729
839
|
}, { dc: (0, _3_transport_js_1.getDc)(id.dc_id) });
|
|
730
840
|
}
|
|
731
841
|
async editMessageText(chatId, messageId, text, params) {
|
|
732
|
-
|
|
842
|
+
this.#checkParams(params);
|
|
733
843
|
{
|
|
734
844
|
const message = await this.getMessage(chatId, messageId);
|
|
735
845
|
if (!message) {
|
|
@@ -752,27 +862,28 @@ class MessageManager {
|
|
|
752
862
|
if (!noWebpage && params?.linkPreview?.url) {
|
|
753
863
|
media = { _: "inputMediaWebPage", url: params.linkPreview.url, force_large_media: params.linkPreview.mediaSize === "large" ? true : undefined, force_small_media: params.linkPreview.mediaSize === "small" ? true : undefined, optional: message.length ? undefined : true };
|
|
754
864
|
}
|
|
755
|
-
const result = await
|
|
865
|
+
const result = await this.#c.invoke({
|
|
756
866
|
_: "messages.editMessage",
|
|
757
867
|
id: (0, _0_utilities_js_1.checkMessageId)(messageId),
|
|
758
|
-
peer: await
|
|
868
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
759
869
|
entities,
|
|
760
870
|
message,
|
|
761
871
|
media,
|
|
762
872
|
no_webpage: noWebpage,
|
|
763
873
|
invert_media: invertMedia,
|
|
764
|
-
reply_markup: await
|
|
874
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
765
875
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
766
876
|
const message_ = (await this.updatesToMessages(chatId, result))[0];
|
|
767
877
|
return (0, _3_types_js_2.assertMessageType)(message_, "text");
|
|
768
878
|
}
|
|
879
|
+
static #CAPTIONABLE_MESSAGE_TYPES = ["photo", "document", "video", "animation", "voice", "audio", "video"];
|
|
769
880
|
async editMessageCaption(chatId, messageId, params) {
|
|
770
881
|
let canHaveCaption = false;
|
|
771
882
|
const message_ = await this.getMessage(chatId, messageId);
|
|
772
883
|
if (!message_) {
|
|
773
884
|
throw new _0_errors_js_1.InputError("Message not found.");
|
|
774
885
|
}
|
|
775
|
-
for (const type of
|
|
886
|
+
for (const type of MessageManager.#CAPTIONABLE_MESSAGE_TYPES) {
|
|
776
887
|
if ((0, _3_types_js_1.isMessageType)(message_, type)) {
|
|
777
888
|
canHaveCaption = true;
|
|
778
889
|
}
|
|
@@ -781,24 +892,167 @@ class MessageManager {
|
|
|
781
892
|
throw new _0_errors_js_1.InputError("The referenced message cannot have a caption.");
|
|
782
893
|
}
|
|
783
894
|
const [message, entities] = this.parseText(params?.caption ?? "", params);
|
|
784
|
-
const result = await
|
|
895
|
+
const result = await this.#c.invoke({
|
|
785
896
|
_: "messages.editMessage",
|
|
786
897
|
id: (0, _0_utilities_js_1.checkMessageId)(messageId),
|
|
787
|
-
peer: await
|
|
898
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
788
899
|
entities: message ? entities : [],
|
|
789
900
|
message,
|
|
790
|
-
reply_markup: await
|
|
901
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
791
902
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
792
903
|
return (await this.updatesToMessages(chatId, result))[0];
|
|
793
904
|
}
|
|
905
|
+
async #editInlineMessageTextInner(inlineMessageId, text, params, allowEmpty = true) {
|
|
906
|
+
this.#checkParams(params);
|
|
907
|
+
const [message, entities] = this.parseText(text, params);
|
|
908
|
+
if (!allowEmpty && !message) {
|
|
909
|
+
throw new _0_errors_js_1.InputError("Message text cannot be empty.");
|
|
910
|
+
}
|
|
911
|
+
const id = await (0, _3_types_js_2.deserializeInlineMessageId)(inlineMessageId);
|
|
912
|
+
if (params?.linkPreview && params.linkPreview.type !== "input") {
|
|
913
|
+
throw new _0_errors_js_1.InputError("Expected link preview of type input.");
|
|
914
|
+
}
|
|
915
|
+
const noWebpage = params?.linkPreview && params.linkPreview.type === "input" && params.linkPreview.isDisabled ? true : undefined;
|
|
916
|
+
const invertMedia = params?.linkPreview?.isAboveText ? true : undefined;
|
|
917
|
+
let media = undefined;
|
|
918
|
+
if (!noWebpage && params?.linkPreview?.url) {
|
|
919
|
+
media = { _: "inputMediaWebPage", url: params.linkPreview.url, force_large_media: params.linkPreview.mediaSize === "large" ? true : undefined, force_small_media: params.linkPreview.mediaSize === "small" ? true : undefined, optional: message.length ? undefined : true };
|
|
920
|
+
}
|
|
921
|
+
await this.#c.invoke({
|
|
922
|
+
_: "messages.editInlineBotMessage",
|
|
923
|
+
id,
|
|
924
|
+
entities,
|
|
925
|
+
message,
|
|
926
|
+
media,
|
|
927
|
+
no_webpage: noWebpage,
|
|
928
|
+
invert_media: invertMedia,
|
|
929
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
930
|
+
}, { dc: (0, _3_transport_js_1.getDc)(id.dc_id) });
|
|
931
|
+
}
|
|
794
932
|
async editInlineMessageText(inlineMessageId, text, params) {
|
|
795
|
-
await
|
|
933
|
+
await this.#editInlineMessageTextInner(inlineMessageId, text, params, false);
|
|
796
934
|
}
|
|
797
935
|
async editInlineMessageCaption(inlineMessageId, params) {
|
|
798
|
-
await
|
|
936
|
+
await this.#editInlineMessageTextInner(inlineMessageId, params?.caption ?? "", params);
|
|
937
|
+
}
|
|
938
|
+
async #resolveInputMediaInner(document, media, fileType, otherAttribs) {
|
|
939
|
+
let media_ = null;
|
|
940
|
+
const spoiler = "hasSpoiler" in media && media.hasSpoiler ? true : undefined;
|
|
941
|
+
if (typeof document === "string") {
|
|
942
|
+
const fileId = this.resolveFileId(document, fileType);
|
|
943
|
+
if (fileId !== null) {
|
|
944
|
+
media_ = { _: "inputMediaDocument", id: { ...fileId, _: "inputDocument" }, spoiler, query: otherAttribs.find((v) => _2_tl_js_1.Api.is("documentAttributeSticker", v))?.alt || undefined };
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
if (media_ === null) {
|
|
948
|
+
if (typeof document === "string" && (0, _0_utilities_js_1.isHttpUrl)(document)) {
|
|
949
|
+
media_ = { _: "inputMediaDocumentExternal", url: document, spoiler };
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
let mimeType;
|
|
953
|
+
const file = await this.#c.fileManager.upload(document, media, (name) => {
|
|
954
|
+
mimeType = media?.mimeType ?? (0, _0_deps_js_1.contentType)(name.split(".").slice(-1)[0]) ?? FALLBACK_MIME_TYPE;
|
|
955
|
+
if (name.endsWith(".tgs") && fileType === _3_types_js_2.FileType.Document) {
|
|
956
|
+
name += "-";
|
|
957
|
+
}
|
|
958
|
+
return name;
|
|
959
|
+
});
|
|
960
|
+
if (_2_tl_js_1.Api.is("inputFileStoryDocument", file)) {
|
|
961
|
+
(0, _0_deps_js_1.unreachable)();
|
|
962
|
+
}
|
|
963
|
+
let thumb = undefined;
|
|
964
|
+
if ("thumbnail" in media && media.thumbnail) {
|
|
965
|
+
thumb = await this.#c.fileManager.upload(media.thumbnail, { chunkSize: media?.chunkSize, signal: media?.signal });
|
|
966
|
+
}
|
|
967
|
+
media_ = { _: "inputMediaUploadedDocument", file, thumb, spoiler, attributes: [{ _: "documentAttributeFilename", file_name: file.name }, ...otherAttribs], mime_type: mimeType, force_file: fileType === _3_types_js_2.FileType.Document ? true : undefined };
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return media_;
|
|
971
|
+
}
|
|
972
|
+
async #resolveInputMedia(media) {
|
|
973
|
+
if ("animation" in media) {
|
|
974
|
+
return await this.#resolveInputMediaInner(media.animation, media, _3_types_js_2.FileType.Animation, [
|
|
975
|
+
{ _: "documentAttributeAnimated" },
|
|
976
|
+
{ _: "documentAttributeVideo", supports_streaming: true, w: media?.width ?? 0, h: media?.height ?? 0, duration: media?.duration ?? 0 },
|
|
977
|
+
]);
|
|
978
|
+
}
|
|
979
|
+
else if ("audio" in media) {
|
|
980
|
+
return await this.#resolveInputMediaInner(media.audio, media, _3_types_js_2.FileType.Audio, [
|
|
981
|
+
{ _: "documentAttributeAudio", duration: media?.duration ?? 0, performer: media?.performer, title: media?.title },
|
|
982
|
+
]);
|
|
983
|
+
}
|
|
984
|
+
else if ("document" in media) {
|
|
985
|
+
return await this.#resolveInputMediaInner(media.document, media, _3_types_js_2.FileType.Document, []);
|
|
986
|
+
}
|
|
987
|
+
else if ("photo" in media) {
|
|
988
|
+
let media_ = null;
|
|
989
|
+
const spoiler = media.hasSpoiler ? true : undefined;
|
|
990
|
+
const ttl_seconds = "selfDestruct" in media && media.selfDestruct !== undefined ? (0, _3_types_js_1.selfDestructOptionToInt)(media.selfDestruct) : undefined;
|
|
991
|
+
if (typeof media.photo === "string") {
|
|
992
|
+
const fileId = this.resolveFileId(media.photo, [_3_types_js_2.FileType.Photo, _3_types_js_2.FileType.ProfilePhoto]);
|
|
993
|
+
if (fileId !== null) {
|
|
994
|
+
media_ = { _: "inputMediaPhoto", id: { ...fileId, _: "inputPhoto" }, spoiler, ttl_seconds };
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (media_ === null) {
|
|
998
|
+
if (typeof media.photo === "string" && (0, _0_utilities_js_1.isHttpUrl)(media.photo)) {
|
|
999
|
+
media_ = { _: "inputMediaPhotoExternal", url: media.photo, spoiler };
|
|
1000
|
+
}
|
|
1001
|
+
else {
|
|
1002
|
+
const file = await this.#c.fileManager.upload(media.photo, media, null, false);
|
|
1003
|
+
media_ = { _: "inputMediaUploadedPhoto", file, spoiler, ttl_seconds };
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
return media_;
|
|
1007
|
+
}
|
|
1008
|
+
else if ("video" in media) {
|
|
1009
|
+
const ttl_seconds = "selfDestruct" in media && media.selfDestruct !== undefined ? (0, _3_types_js_1.selfDestructOptionToInt)(media.selfDestruct) : undefined;
|
|
1010
|
+
const media_ = await this.#resolveInputMediaInner(media.video, media, _3_types_js_2.FileType.Video, [
|
|
1011
|
+
{ _: "documentAttributeVideo", supports_streaming: media?.supportsStreaming ? true : undefined, w: media?.width ?? 0, h: media?.height ?? 0, duration: media?.duration ?? 0 },
|
|
1012
|
+
]);
|
|
1013
|
+
media_.ttl_seconds = ttl_seconds;
|
|
1014
|
+
return media_;
|
|
1015
|
+
}
|
|
1016
|
+
else {
|
|
1017
|
+
(0, _0_deps_js_1.unreachable)();
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
async #resolveInputMediaUpload(media, businessConnectionId) {
|
|
1021
|
+
const inputMedia = await this.#resolveInputMedia(media);
|
|
1022
|
+
if (_2_tl_js_1.Api.is("inputMediaUploadedPhoto", inputMedia) || _2_tl_js_1.Api.is("inputMediaUploadedDocument", inputMedia)) {
|
|
1023
|
+
const messageMedia = await this.#c.invoke({
|
|
1024
|
+
_: "messages.uploadMedia",
|
|
1025
|
+
peer: { _: "inputPeerSelf" },
|
|
1026
|
+
media: inputMedia,
|
|
1027
|
+
business_connection_id: businessConnectionId,
|
|
1028
|
+
});
|
|
1029
|
+
if (("photo" in messageMedia) && _2_tl_js_1.Api.is("photo", messageMedia.photo)) {
|
|
1030
|
+
return {
|
|
1031
|
+
_: "inputMediaPhoto",
|
|
1032
|
+
id: {
|
|
1033
|
+
_: "inputPhoto",
|
|
1034
|
+
id: messageMedia.photo.id,
|
|
1035
|
+
access_hash: messageMedia.photo.access_hash,
|
|
1036
|
+
file_reference: messageMedia.photo.file_reference,
|
|
1037
|
+
},
|
|
1038
|
+
spoiler: "hasSpoiler" in media && media.hasSpoiler ? true : undefined,
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
else if ("document" in messageMedia && _2_tl_js_1.Api.is("document", messageMedia.document)) {
|
|
1042
|
+
return {
|
|
1043
|
+
_: "inputMediaDocument",
|
|
1044
|
+
id: { _: "inputDocument", id: messageMedia.document.id, access_hash: messageMedia.document.access_hash, file_reference: messageMedia.document.file_reference },
|
|
1045
|
+
spoiler: "hasSpoiler" in media && media.hasSpoiler ? true : undefined,
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
else {
|
|
1049
|
+
(0, _0_deps_js_1.unreachable)();
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
return inputMedia;
|
|
799
1053
|
}
|
|
800
1054
|
async editMessageMedia(chatId, messageId, media, params) {
|
|
801
|
-
|
|
1055
|
+
this.#checkParams(params);
|
|
802
1056
|
const message = await this.getMessage(chatId, messageId);
|
|
803
1057
|
if (!message) {
|
|
804
1058
|
throw new _0_errors_js_1.InputError("Message not found.");
|
|
@@ -807,12 +1061,12 @@ class MessageManager {
|
|
|
807
1061
|
throw new _0_errors_js_1.InputError("Unexpected message type.");
|
|
808
1062
|
}
|
|
809
1063
|
const [text, entities] = media.caption !== undefined ? this.parseText(media.caption, { entities: media.captionEntities, parseMode: media.parseMode }) : ["", []];
|
|
810
|
-
const result = await
|
|
1064
|
+
const result = await this.#c.invoke({
|
|
811
1065
|
_: "messages.editMessage",
|
|
812
|
-
peer: await
|
|
1066
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
813
1067
|
id: messageId,
|
|
814
|
-
media: await
|
|
815
|
-
reply_markup: await
|
|
1068
|
+
media: await this.#resolveInputMedia(media),
|
|
1069
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
816
1070
|
message: text,
|
|
817
1071
|
entities,
|
|
818
1072
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
@@ -820,70 +1074,73 @@ class MessageManager {
|
|
|
820
1074
|
return message_;
|
|
821
1075
|
}
|
|
822
1076
|
async editInlineMessageMedia(inlineMessageId, media, params) {
|
|
823
|
-
|
|
824
|
-
|
|
1077
|
+
this.#checkParams(params);
|
|
1078
|
+
this.#c.storage.assertBot("editInlineMessageMedia");
|
|
825
1079
|
const id = await (0, _3_types_js_2.deserializeInlineMessageId)(inlineMessageId);
|
|
826
|
-
await
|
|
1080
|
+
await this.#c.invoke({
|
|
827
1081
|
_: "messages.editInlineBotMessage",
|
|
828
1082
|
id,
|
|
829
|
-
media: await
|
|
830
|
-
reply_markup: await
|
|
1083
|
+
media: await this.#resolveInputMediaUpload(media),
|
|
1084
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
831
1085
|
}, { dc: (0, _3_transport_js_1.getDc)(id.dc_id) });
|
|
832
1086
|
}
|
|
833
1087
|
async deleteMessages(chatId, messageIds, params) {
|
|
834
1088
|
(0, _0_utilities_js_1.checkArray)(messageIds, _0_utilities_js_1.checkMessageId);
|
|
835
|
-
const peer = await
|
|
1089
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
836
1090
|
if ((0, _0_utilities_js_1.canBeInputChannel)(peer)) {
|
|
837
|
-
await
|
|
1091
|
+
await this.#c.invoke({ _: "channels.deleteMessages", channel: (0, _0_utilities_js_1.toInputChannel)(peer), id: messageIds });
|
|
838
1092
|
}
|
|
839
1093
|
else {
|
|
840
|
-
await
|
|
1094
|
+
await this.#c.invoke({ _: "messages.deleteMessages", id: messageIds, revoke: params?.onlyForMe ? undefined : true });
|
|
841
1095
|
}
|
|
842
1096
|
}
|
|
843
1097
|
async deleteScheduledMessages(chatId, messageIds) {
|
|
844
|
-
|
|
1098
|
+
this.#c.storage.assertUser("sendScheduledMessage");
|
|
845
1099
|
(0, _0_utilities_js_1.checkArray)(messageIds, _0_utilities_js_1.checkMessageId);
|
|
846
|
-
const peer = await
|
|
847
|
-
await
|
|
1100
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1101
|
+
await this.#c.invoke({ _: "messages.deleteScheduledMessages", peer, id: messageIds });
|
|
848
1102
|
}
|
|
849
1103
|
async deleteScheduledMessage(chatId, messageId) {
|
|
850
|
-
|
|
1104
|
+
this.#c.storage.assertUser("deleteScheduledMessage");
|
|
851
1105
|
return await this.deleteScheduledMessages(chatId, [messageId]);
|
|
852
1106
|
}
|
|
853
1107
|
async sendScheduledMessages(chatId, messageIds) {
|
|
854
|
-
|
|
1108
|
+
this.#c.storage.assertUser("sendScheduledMessages");
|
|
855
1109
|
(0, _0_utilities_js_1.checkArray)(messageIds, _0_utilities_js_1.checkMessageId);
|
|
856
|
-
const peer = await
|
|
857
|
-
const result = await
|
|
1110
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1111
|
+
const result = await this.#c.invoke({ _: "messages.sendScheduledMessages", peer, id: messageIds });
|
|
858
1112
|
return await this.updatesToMessages(chatId, result);
|
|
859
1113
|
}
|
|
860
1114
|
async sendScheduledMessage(chatId, messageId) {
|
|
861
|
-
|
|
1115
|
+
this.#c.storage.assertUser("sendScheduledMessage");
|
|
862
1116
|
return (await this.sendScheduledMessages(chatId, [messageId]))[0];
|
|
863
1117
|
}
|
|
864
1118
|
async deleteChatMemberMessages(chatId, memberId) {
|
|
865
|
-
|
|
866
|
-
const channel = await
|
|
867
|
-
const participant = await
|
|
868
|
-
await
|
|
1119
|
+
this.#c.storage.assertUser("deleteChatMemberMessages");
|
|
1120
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
1121
|
+
const participant = await this.#c.getInputPeer(memberId);
|
|
1122
|
+
await this.#c.invoke({ _: "channels.deleteParticipantHistory", channel, participant });
|
|
869
1123
|
}
|
|
870
1124
|
async pinMessage(chatId, messageId, params) {
|
|
871
|
-
|
|
872
|
-
await
|
|
1125
|
+
this.#checkParams(params);
|
|
1126
|
+
await this.#c.invoke({ _: "messages.updatePinnedMessage", peer: await this.#c.getInputPeer(chatId), id: (0, _0_utilities_js_1.checkMessageId)(messageId), silent: params?.isSilent ? true : undefined, pm_oneside: params?.bothSides ? undefined : true });
|
|
873
1127
|
}
|
|
874
1128
|
async unpinMessage(chatId, messageId, params) {
|
|
875
|
-
|
|
876
|
-
await
|
|
1129
|
+
this.#checkParams(params);
|
|
1130
|
+
await this.#c.invoke({ _: "messages.updatePinnedMessage", peer: await this.#c.getInputPeer(chatId), id: (0, _0_utilities_js_1.checkMessageId)(messageId), unpin: true }, { businessConnectionId: params?.businessConnectionId });
|
|
877
1131
|
}
|
|
878
1132
|
async unpinMessages(chatId, params) {
|
|
879
|
-
await
|
|
1133
|
+
await this.#c.invoke({
|
|
880
1134
|
_: "messages.unpinAllMessages",
|
|
881
|
-
peer: await
|
|
1135
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
882
1136
|
top_msg_id: params?.topicId,
|
|
883
1137
|
});
|
|
884
1138
|
}
|
|
1139
|
+
async #sendReaction(chatId, messageId, reactions, params) {
|
|
1140
|
+
await this.#c.invoke({ _: "messages.sendReaction", peer: await this.#c.getInputPeer(chatId), msg_id: (0, _0_utilities_js_1.checkMessageId)(messageId), reaction: reactions.map((v) => (0, _3_types_js_2.reactionToTlObject)(v)), big: params?.isBig ? true : undefined, add_to_recent: params?.addToRecents ? true : undefined });
|
|
1141
|
+
}
|
|
885
1142
|
async setReactions(chatId, messageId, reactions, params) {
|
|
886
|
-
await
|
|
1143
|
+
await this.#sendReaction(chatId, messageId, reactions, params);
|
|
887
1144
|
}
|
|
888
1145
|
async addReaction(chatId, messageId, reaction, params) {
|
|
889
1146
|
const message = await this.getMessage(chatId, messageId);
|
|
@@ -920,7 +1177,7 @@ class MessageManager {
|
|
|
920
1177
|
if (_2_tl_js_1.Api.is("updateNewMessage", update) || _2_tl_js_1.Api.is("updateNewChannelMessage", update) || _2_tl_js_1.Api.is("updateEditMessage", update) || _2_tl_js_1.Api.is("updateEditChannelMessage", update)) {
|
|
921
1178
|
if (_2_tl_js_1.Api.is("message", update.message) || _2_tl_js_1.Api.is("messageService", update.message)) {
|
|
922
1179
|
const chatId = _2_tl_js_1.Api.peerToChatId(update.message.peer_id);
|
|
923
|
-
await
|
|
1180
|
+
await this.#c.messageStorage.setMessage(chatId, update.message.id, update.message);
|
|
924
1181
|
}
|
|
925
1182
|
}
|
|
926
1183
|
if (_2_tl_js_1.Api.isOneOf([
|
|
@@ -940,7 +1197,7 @@ class MessageManager {
|
|
|
940
1197
|
shouldIgnore = true;
|
|
941
1198
|
}
|
|
942
1199
|
else {
|
|
943
|
-
shouldIgnore = !
|
|
1200
|
+
shouldIgnore = !this.#c.outgoingMessages;
|
|
944
1201
|
}
|
|
945
1202
|
}
|
|
946
1203
|
if (!shouldIgnore) {
|
|
@@ -962,7 +1219,7 @@ class MessageManager {
|
|
|
962
1219
|
if (_2_tl_js_1.Api.is("updateDeleteMessages", update)) {
|
|
963
1220
|
const deletedMessages = new Array();
|
|
964
1221
|
for (const messageId of update.messages) {
|
|
965
|
-
const chatId = await
|
|
1222
|
+
const chatId = await this.#c.messageStorage.getMessageChat(messageId);
|
|
966
1223
|
if (chatId) {
|
|
967
1224
|
deletedMessages.push({ chatId, messageId });
|
|
968
1225
|
}
|
|
@@ -975,7 +1232,7 @@ class MessageManager {
|
|
|
975
1232
|
const chatId = _2_tl_js_1.Api.getChannelChatId(update.channel_id);
|
|
976
1233
|
const deletedMessages = new Array();
|
|
977
1234
|
for (const messageId of update.messages) {
|
|
978
|
-
const message = await
|
|
1235
|
+
const message = await this.#c.messageStorage.getMessage(chatId, messageId);
|
|
979
1236
|
if (message !== null) {
|
|
980
1237
|
deletedMessages.push({ chatId, messageId });
|
|
981
1238
|
}
|
|
@@ -994,13 +1251,13 @@ class MessageManager {
|
|
|
994
1251
|
}
|
|
995
1252
|
if (_2_tl_js_1.Api.is("updateTranscribedAudio", update)) {
|
|
996
1253
|
const voiceTranscription = (0, _3_types_js_1.constructVoiceTranscription)(update);
|
|
997
|
-
await
|
|
1254
|
+
await this.#c.messageStorage.setVoiceTranscription(voiceTranscription);
|
|
998
1255
|
return { voiceTranscription };
|
|
999
1256
|
}
|
|
1000
1257
|
return null;
|
|
1001
1258
|
}
|
|
1002
1259
|
async sendChatAction(chatId, action, params) {
|
|
1003
|
-
|
|
1260
|
+
this.#checkParams(params);
|
|
1004
1261
|
let action_;
|
|
1005
1262
|
switch (action) {
|
|
1006
1263
|
case "type":
|
|
@@ -1039,13 +1296,13 @@ class MessageManager {
|
|
|
1039
1296
|
default:
|
|
1040
1297
|
throw new _0_errors_js_1.InputError(`Invalid chat action: ${action}`);
|
|
1041
1298
|
}
|
|
1042
|
-
await
|
|
1299
|
+
await this.#c.invoke({ _: "messages.setTyping", peer: await this.#c.getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId }, { businessConnectionId: params?.businessConnectionId });
|
|
1043
1300
|
}
|
|
1044
1301
|
async searchMessages(params) {
|
|
1045
|
-
|
|
1046
|
-
const peer = params?.chatId === undefined ? { _: "inputPeerEmpty" } : await
|
|
1302
|
+
this.#c.storage.assertUser("searchMessages");
|
|
1303
|
+
const peer = params?.chatId === undefined ? { _: "inputPeerEmpty" } : await this.#c.getInputPeer(params.chatId);
|
|
1047
1304
|
const query = params?.query ?? "";
|
|
1048
|
-
const result = await
|
|
1305
|
+
const result = await this.#c.invoke({
|
|
1049
1306
|
_: "messages.search",
|
|
1050
1307
|
peer,
|
|
1051
1308
|
q: query,
|
|
@@ -1058,7 +1315,7 @@ class MessageManager {
|
|
|
1058
1315
|
min_date: 0,
|
|
1059
1316
|
min_id: 0,
|
|
1060
1317
|
offset_id: params?.offset ? params.offset : 0,
|
|
1061
|
-
from_id: params?.from ? await
|
|
1318
|
+
from_id: params?.from ? await this.#c.getInputPeer(params.from) : undefined,
|
|
1062
1319
|
});
|
|
1063
1320
|
if (!("messages" in result)) {
|
|
1064
1321
|
(0, _0_deps_js_1.unreachable)();
|
|
@@ -1072,25 +1329,25 @@ class MessageManager {
|
|
|
1072
1329
|
return { messages, count };
|
|
1073
1330
|
}
|
|
1074
1331
|
async blockUser(userId) {
|
|
1075
|
-
|
|
1076
|
-
const id = await
|
|
1077
|
-
await
|
|
1332
|
+
this.#c.storage.assertUser("blockUser");
|
|
1333
|
+
const id = await this.#c.getInputPeer(userId);
|
|
1334
|
+
await this.#c.invoke({ _: "contacts.block", id });
|
|
1078
1335
|
}
|
|
1079
1336
|
async unblockUser(userId) {
|
|
1080
|
-
|
|
1081
|
-
const id = await
|
|
1082
|
-
await
|
|
1337
|
+
this.#c.storage.assertUser("unblockUser");
|
|
1338
|
+
const id = await this.#c.getInputPeer(userId);
|
|
1339
|
+
await this.#c.invoke({ _: "contacts.unblock", id });
|
|
1083
1340
|
}
|
|
1084
1341
|
async setChatStickerSet(chatId, setName) {
|
|
1085
|
-
const channel = await
|
|
1086
|
-
await
|
|
1342
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
1343
|
+
await this.#c.invoke({ _: "channels.setStickers", channel, stickerset: { _: "inputStickerSetShortName", short_name: setName } });
|
|
1087
1344
|
}
|
|
1088
1345
|
async deleteChatStickerSet(chatId) {
|
|
1089
|
-
const channel = await
|
|
1090
|
-
await
|
|
1346
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
1347
|
+
await this.#c.invoke({ _: "channels.setStickers", channel, stickerset: { _: "inputStickerSetEmpty" } });
|
|
1091
1348
|
}
|
|
1092
1349
|
async stopPoll(chatId, messageId, params) {
|
|
1093
|
-
|
|
1350
|
+
this.#checkParams(params);
|
|
1094
1351
|
const message = await this.getMessage(chatId, messageId);
|
|
1095
1352
|
if (!message) {
|
|
1096
1353
|
throw new _0_errors_js_1.InputError("Message not found.");
|
|
@@ -1101,26 +1358,26 @@ class MessageManager {
|
|
|
1101
1358
|
if (message.poll.isClosed) {
|
|
1102
1359
|
throw new _0_errors_js_1.InputError("Poll is already stopped.");
|
|
1103
1360
|
}
|
|
1104
|
-
const result = await
|
|
1361
|
+
const result = await this.#c.invoke({
|
|
1105
1362
|
_: "messages.editMessage",
|
|
1106
|
-
peer: await
|
|
1363
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
1107
1364
|
id: messageId,
|
|
1108
1365
|
media: { _: "inputMediaPoll", poll: { _: "poll", id: BigInt(message.poll.id), closed: true, question: { _: "textWithEntities", text: "", entities: [] }, answers: [] } },
|
|
1109
|
-
reply_markup: await
|
|
1366
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
1110
1367
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
1111
1368
|
const message_ = (await this.updatesToMessages(chatId, result))[0];
|
|
1112
1369
|
return (0, _3_types_js_2.assertMessageType)(message_, "poll").poll;
|
|
1113
1370
|
}
|
|
1114
1371
|
async editMessageLiveLocation(chatId, messageId, latitude, longitude, params) {
|
|
1115
|
-
|
|
1372
|
+
this.#checkParams(params);
|
|
1116
1373
|
const message = await this.getMessage(chatId, messageId);
|
|
1117
1374
|
if (message && "location" in message && message.location.livePeriod) {
|
|
1118
|
-
const result = await
|
|
1375
|
+
const result = await this.#c.invoke({
|
|
1119
1376
|
_: "messages.editMessage",
|
|
1120
|
-
peer: await
|
|
1377
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
1121
1378
|
id: messageId,
|
|
1122
1379
|
media: { _: "inputMediaGeoLive", geo_point: { _: "inputGeoPoint", lat: latitude, long: longitude, accuracy_radius: params?.horizontalAccuracy }, heading: params?.heading, proximity_notification_radius: params?.proximityAlertRadius },
|
|
1123
|
-
reply_markup: await
|
|
1380
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
1124
1381
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
1125
1382
|
const message = (await this.updatesToMessages(chatId, result))[0];
|
|
1126
1383
|
return (0, _3_types_js_2.assertMessageType)(message, "location");
|
|
@@ -1128,19 +1385,19 @@ class MessageManager {
|
|
|
1128
1385
|
(0, _0_deps_js_1.unreachable)();
|
|
1129
1386
|
}
|
|
1130
1387
|
async editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params) {
|
|
1131
|
-
|
|
1132
|
-
|
|
1388
|
+
this.#checkParams(params);
|
|
1389
|
+
this.#c.storage.assertBot("editInlineMessageLiveLocation");
|
|
1133
1390
|
const id = await (0, _3_types_js_2.deserializeInlineMessageId)(inlineMessageId);
|
|
1134
|
-
await
|
|
1391
|
+
await this.#c.invoke({
|
|
1135
1392
|
_: "messages.editInlineBotMessage",
|
|
1136
1393
|
id,
|
|
1137
1394
|
media: { _: "inputMediaGeoLive", geo_point: { _: "inputGeoPoint", lat: latitude, long: longitude, accuracy_radius: params?.horizontalAccuracy }, heading: params?.heading, proximity_notification_radius: params?.proximityAlertRadius },
|
|
1138
|
-
reply_markup: await
|
|
1395
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
1139
1396
|
}, { dc: (0, _3_transport_js_1.getDc)(id.dc_id) });
|
|
1140
1397
|
}
|
|
1141
1398
|
async sendInvoice(chatId, title, description, payload, currency, prices, params) {
|
|
1142
|
-
|
|
1143
|
-
|
|
1399
|
+
this.#c.storage.assertBot("sendInvoice");
|
|
1400
|
+
this.#checkParams(params);
|
|
1144
1401
|
if (title.length < 1) {
|
|
1145
1402
|
throw new _0_errors_js_1.InputError("Invoice title cannot be empty.");
|
|
1146
1403
|
}
|
|
@@ -1167,7 +1424,7 @@ class MessageManager {
|
|
|
1167
1424
|
phone_to_provider: params?.sendPhoneNumberToProvider || undefined,
|
|
1168
1425
|
flexible: params?.isFlexible || undefined,
|
|
1169
1426
|
};
|
|
1170
|
-
const message = await
|
|
1427
|
+
const message = await this.#sendMedia(chatId, {
|
|
1171
1428
|
_: "inputMediaInvoice",
|
|
1172
1429
|
title,
|
|
1173
1430
|
description,
|
|
@@ -1193,7 +1450,7 @@ class MessageManager {
|
|
|
1193
1450
|
return (0, _3_types_js_2.assertMessageType)(message, "invoice");
|
|
1194
1451
|
}
|
|
1195
1452
|
async sendMediaGroup(chatId, media, params) {
|
|
1196
|
-
|
|
1453
|
+
this.#checkParams(params);
|
|
1197
1454
|
{
|
|
1198
1455
|
if (!Array.isArray(media) || !media.length) {
|
|
1199
1456
|
throw new _0_errors_js_1.InputError("Media group must not be empty.");
|
|
@@ -1219,25 +1476,25 @@ class MessageManager {
|
|
|
1219
1476
|
for (const v of media) {
|
|
1220
1477
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
1221
1478
|
const [message, entities] = v.caption !== undefined ? this.parseText(v.caption, { entities: v.captionEntities, parseMode: v.parseMode }) : ["", []];
|
|
1222
|
-
multiMedia.push({ _: "inputSingleMedia", message, entities, random_id: randomId, media: await
|
|
1479
|
+
multiMedia.push({ _: "inputSingleMedia", message, entities, random_id: randomId, media: await this.#resolveInputMedia(v) });
|
|
1223
1480
|
}
|
|
1224
|
-
const peer = await
|
|
1481
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1225
1482
|
for (const [i, media_] of multiMedia.entries()) {
|
|
1226
1483
|
if (_2_tl_js_1.Api.is("inputMediaUploadedPhoto", media_.media)) {
|
|
1227
|
-
const result = _2_tl_js_1.Api.as("messageMediaPhoto", await
|
|
1484
|
+
const result = _2_tl_js_1.Api.as("messageMediaPhoto", await this.#c.invoke({ _: "messages.uploadMedia", media: media_.media, peer }));
|
|
1228
1485
|
const photo = _2_tl_js_1.Api.as("photo", result.photo);
|
|
1229
1486
|
multiMedia[i] = { ...media_, media: { _: "inputMediaPhoto", id: { ...photo, _: "inputPhoto" } } };
|
|
1230
1487
|
}
|
|
1231
1488
|
else if (_2_tl_js_1.Api.is("inputMediaUploadedDocument", media_.media)) {
|
|
1232
|
-
const result = _2_tl_js_1.Api.as("messageMediaDocument", await
|
|
1489
|
+
const result = _2_tl_js_1.Api.as("messageMediaDocument", await this.#c.invoke({ _: "messages.uploadMedia", media: media_.media, peer }));
|
|
1233
1490
|
const document = _2_tl_js_1.Api.as("document", result.document);
|
|
1234
1491
|
multiMedia[i] = { ...media_, media: { _: "inputMediaDocument", id: { ...document, _: "inputDocument" } } };
|
|
1235
1492
|
}
|
|
1236
1493
|
}
|
|
1237
1494
|
const silent = params?.isSilent ? true : undefined;
|
|
1238
1495
|
const noforwards = params?.isContentProtected ? true : undefined;
|
|
1239
|
-
const sendAs = params?.sendAs ? await
|
|
1240
|
-
const result = await
|
|
1496
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
1497
|
+
const result = await this.#c.invoke({
|
|
1241
1498
|
_: "messages.sendMultiMedia",
|
|
1242
1499
|
peer,
|
|
1243
1500
|
multi_media: multiMedia,
|
|
@@ -1245,19 +1502,19 @@ class MessageManager {
|
|
|
1245
1502
|
noforwards,
|
|
1246
1503
|
silent,
|
|
1247
1504
|
send_as: sendAs,
|
|
1248
|
-
reply_to: await
|
|
1505
|
+
reply_to: await this.#constructReplyTo(params),
|
|
1249
1506
|
allow_paid_floodskip: params?.isPaidBroadcast ? true : undefined,
|
|
1250
1507
|
});
|
|
1251
1508
|
return await this.updatesToMessages(chatId, result);
|
|
1252
1509
|
}
|
|
1253
1510
|
async readMessages(chatId, untilMessageId) {
|
|
1254
|
-
|
|
1255
|
-
const peer = await
|
|
1511
|
+
this.#c.storage.assertUser("readMessages");
|
|
1512
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1256
1513
|
const max_id = untilMessageId;
|
|
1257
|
-
await
|
|
1514
|
+
await this.#c.invoke({ _: "messages.readHistory", peer, max_id });
|
|
1258
1515
|
}
|
|
1259
1516
|
async startBot(botId, params) {
|
|
1260
|
-
|
|
1517
|
+
this.#c.storage.assertUser("startBot");
|
|
1261
1518
|
const start_param = params?.deeplink?.trim() || "";
|
|
1262
1519
|
if (params?.chatId !== undefined && !start_param) {
|
|
1263
1520
|
throw new _0_errors_js_1.InputError("deeplink cannot be unspecified while chatId is specified.");
|
|
@@ -1265,13 +1522,13 @@ class MessageManager {
|
|
|
1265
1522
|
if (!params?.deeplink) {
|
|
1266
1523
|
return await this.sendMessage(botId, "/start");
|
|
1267
1524
|
}
|
|
1268
|
-
const bot = await
|
|
1269
|
-
const peer = await
|
|
1270
|
-
const result = await
|
|
1525
|
+
const bot = await this.#c.getInputUser(botId);
|
|
1526
|
+
const peer = await this.#c.getInputPeer(params?.chatId || botId);
|
|
1527
|
+
const result = await this.#c.invoke({ _: "messages.startBot", bot, peer, random_id: (0, _1_utilities_js_1.getRandomId)(), start_param });
|
|
1271
1528
|
return (await this.updatesToMessages(botId, result))[0];
|
|
1272
1529
|
}
|
|
1273
1530
|
async transcribeVoice(chatId, messageId) {
|
|
1274
|
-
|
|
1531
|
+
this.#c.storage.assertUser("transcribeVoice");
|
|
1275
1532
|
const message = await this.getMessage(chatId, messageId);
|
|
1276
1533
|
if (message === null) {
|
|
1277
1534
|
throw new _0_errors_js_1.InputError("Message not found.");
|
|
@@ -1279,16 +1536,32 @@ class MessageManager {
|
|
|
1279
1536
|
if (!(0, _3_types_js_1.isMessageType)(message, "voice")) {
|
|
1280
1537
|
throw new _0_errors_js_1.InputError("Message not voice.");
|
|
1281
1538
|
}
|
|
1282
|
-
const cachedTranscription = await
|
|
1539
|
+
const cachedTranscription = await this.#getCachedVoiceTranscription(message);
|
|
1283
1540
|
if (cachedTranscription) {
|
|
1284
1541
|
return cachedTranscription;
|
|
1285
1542
|
}
|
|
1286
|
-
const peer = await
|
|
1287
|
-
const result = await
|
|
1288
|
-
return await
|
|
1543
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1544
|
+
const result = await this.#c.invoke({ _: "messages.transcribeAudio", peer, msg_id: messageId });
|
|
1545
|
+
return await this.#cacheVoiceTranscription(message, (0, _3_types_js_1.constructVoiceTranscription)(result));
|
|
1546
|
+
}
|
|
1547
|
+
async #getCachedVoiceTranscription(message) {
|
|
1548
|
+
const reference = await this.#c.messageStorage.getVoiceTranscriptionReference(message.chat.id, message.id, (0, _1_utilities_js_1.fromUnixTimestamp)(message.editDate ?? message.date));
|
|
1549
|
+
if (!reference) {
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
const voiceTranscription = await this.#c.messageStorage.getVoiceTranscription(reference);
|
|
1553
|
+
if (!voiceTranscription || !voiceTranscription.isCompleted) {
|
|
1554
|
+
return null;
|
|
1555
|
+
}
|
|
1556
|
+
return voiceTranscription;
|
|
1557
|
+
}
|
|
1558
|
+
async #cacheVoiceTranscription(message, voiceTranscription) {
|
|
1559
|
+
await this.#c.messageStorage.setVoiceTranscriptionReference(message.chat.id, message.id, (0, _1_utilities_js_1.fromUnixTimestamp)(message.editDate ?? message.date), BigInt(voiceTranscription.id));
|
|
1560
|
+
await this.#c.messageStorage.setVoiceTranscription(voiceTranscription);
|
|
1561
|
+
return voiceTranscription;
|
|
1289
1562
|
}
|
|
1290
1563
|
async resolveMessageLink(link) {
|
|
1291
|
-
const parseResult =
|
|
1564
|
+
const parseResult = MessageManager.parseMessageLink(link);
|
|
1292
1565
|
if (parseResult === null) {
|
|
1293
1566
|
throw new _0_errors_js_1.InputError("Invalid messsage link.");
|
|
1294
1567
|
}
|
|
@@ -1403,24 +1676,24 @@ class MessageManager {
|
|
|
1403
1676
|
throw new _0_errors_js_1.InputError("Invalid sticker set name or link.");
|
|
1404
1677
|
}
|
|
1405
1678
|
}
|
|
1406
|
-
const result = await
|
|
1679
|
+
const result = await this.#c.invoke({ _: "messages.getStickerSet", hash: 0, stickerset: { _: "inputStickerSetShortName", short_name: name } });
|
|
1407
1680
|
return (0, _3_types_js_1.constructStickerSet)(result);
|
|
1408
1681
|
}
|
|
1409
1682
|
async openMiniApp(botId, chatId, params) {
|
|
1410
|
-
|
|
1683
|
+
this.#c.storage.assertUser("openMiniApp");
|
|
1411
1684
|
const from_bot_menu = params?.isFromMenu ? true : undefined;
|
|
1412
1685
|
const silent = params?.isSilent ? true : undefined;
|
|
1413
1686
|
const compact = params?.mode === "compact" ? true : undefined;
|
|
1414
1687
|
const fullscreen = params?.mode === "fullscreen" ? true : undefined;
|
|
1415
|
-
const peer = await
|
|
1416
|
-
const bot = await
|
|
1688
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1689
|
+
const bot = await this.#c.getInputUser(botId);
|
|
1417
1690
|
const url = params?.url;
|
|
1418
1691
|
const start_param = params?.startParameter;
|
|
1419
1692
|
const theme_params = params?.themeParameters ? { _: "dataJSON", data: params.themeParameters } : undefined;
|
|
1420
|
-
const platform =
|
|
1421
|
-
const reply_to = await
|
|
1422
|
-
const send_as = params?.sendAs ? await
|
|
1423
|
-
const result = await
|
|
1693
|
+
const platform = this.#c.langPack ?? "";
|
|
1694
|
+
const reply_to = await this.#constructReplyTo(params);
|
|
1695
|
+
const send_as = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
1696
|
+
const result = await this.#c.invoke({
|
|
1424
1697
|
_: "messages.requestWebView",
|
|
1425
1698
|
from_bot_menu,
|
|
1426
1699
|
silent,
|
|
@@ -1438,8 +1711,8 @@ class MessageManager {
|
|
|
1438
1711
|
return (0, _3_types_js_1.constructMiniAppInfo)(result);
|
|
1439
1712
|
}
|
|
1440
1713
|
async getSavedMessages(chatId, params) {
|
|
1441
|
-
|
|
1442
|
-
const peer = await
|
|
1714
|
+
this.#c.storage.assertUser("getSavedMessages");
|
|
1715
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1443
1716
|
const limit = (0, _0_utilities_js_1.getLimit)(params?.limit);
|
|
1444
1717
|
let offsetId = params?.offsetId ?? 0;
|
|
1445
1718
|
if (offsetId < 0) {
|
|
@@ -1449,7 +1722,7 @@ class MessageManager {
|
|
|
1449
1722
|
if (offsetDate < 0) {
|
|
1450
1723
|
offsetDate = 0;
|
|
1451
1724
|
}
|
|
1452
|
-
const result = await
|
|
1725
|
+
const result = await this.#c.invoke({
|
|
1453
1726
|
_: "messages.getSavedHistory",
|
|
1454
1727
|
peer,
|
|
1455
1728
|
limit,
|
|
@@ -1482,9 +1755,9 @@ class MessageManager {
|
|
|
1482
1755
|
}
|
|
1483
1756
|
let offsetPeer = { _: "inputPeerEmpty" };
|
|
1484
1757
|
if (params?.offsetChatId !== undefined) {
|
|
1485
|
-
offsetPeer = await
|
|
1758
|
+
offsetPeer = await this.#c.getInputPeer(params.offsetChatId);
|
|
1486
1759
|
}
|
|
1487
|
-
const result = await
|
|
1760
|
+
const result = await this.#c.invoke({
|
|
1488
1761
|
_: "messages.getSavedDialogs",
|
|
1489
1762
|
hash: 0n,
|
|
1490
1763
|
limit,
|
|
@@ -1493,16 +1766,16 @@ class MessageManager {
|
|
|
1493
1766
|
offset_peer: offsetPeer,
|
|
1494
1767
|
exclude_pinned: params?.excludePinned || undefined,
|
|
1495
1768
|
});
|
|
1496
|
-
return (0, _3_types_js_1.constructSavedChats)(result,
|
|
1769
|
+
return (0, _3_types_js_1.constructSavedChats)(result, this.#c.getPeer, this.getMessage.bind(this), this.#c.fileManager.getStickerSetName.bind(this.#c.fileManager));
|
|
1497
1770
|
}
|
|
1498
1771
|
async getMessageReactions(chatId, messageId, params) {
|
|
1499
|
-
|
|
1500
|
-
const peer = await
|
|
1772
|
+
this.#c.storage.assertUser("getMessageReactions");
|
|
1773
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1501
1774
|
const id = messageId;
|
|
1502
1775
|
const reactions = params?.reaction ? (0, _3_types_js_2.reactionToTlObject)(params.reaction) : undefined;
|
|
1503
1776
|
const offset = params?.offset;
|
|
1504
1777
|
const limit = (0, _0_utilities_js_1.getLimit)(params?.limit);
|
|
1505
|
-
const messageReactionsList = await
|
|
1778
|
+
const messageReactionsList = await this.#c.invoke({
|
|
1506
1779
|
_: "messages.getMessageReactionsList",
|
|
1507
1780
|
peer,
|
|
1508
1781
|
id,
|
|
@@ -1514,281 +1787,3 @@ class MessageManager {
|
|
|
1514
1787
|
}
|
|
1515
1788
|
}
|
|
1516
1789
|
exports.MessageManager = MessageManager;
|
|
1517
|
-
_a = MessageManager, _MessageManager_c = new WeakMap(), _MessageManager_LresolveFileId = new WeakMap(), _MessageManager_instances = new WeakSet(), _MessageManager_checkParams = function _MessageManager_checkParams(params) {
|
|
1518
|
-
if (params && "replyMarkup" in params && params.replyMarkup !== undefined) {
|
|
1519
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertBot("replyMarkup");
|
|
1520
|
-
}
|
|
1521
|
-
if (params && "businessConnectionId" in params && params.businessConnectionId !== undefined) {
|
|
1522
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertBot("businessConnectionId");
|
|
1523
|
-
}
|
|
1524
|
-
if (params && "sendAs" in params && params.sendAs !== undefined) {
|
|
1525
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("sendAs");
|
|
1526
|
-
}
|
|
1527
|
-
if (params && "sendAt" in params && params.sendAt !== undefined) {
|
|
1528
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("businessConsendAtnectionId");
|
|
1529
|
-
}
|
|
1530
|
-
}, _MessageManager_constructReplyMarkup = async function _MessageManager_constructReplyMarkup(params) {
|
|
1531
|
-
if (params?.replyMarkup) {
|
|
1532
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertBot("replyMarkup");
|
|
1533
|
-
return await (0, _3_types_js_2.replyMarkupToTlObject)(params.replyMarkup, this.usernameResolver.bind(this));
|
|
1534
|
-
}
|
|
1535
|
-
}, _MessageManager_resolveSendAs = async function _MessageManager_resolveSendAs(params) {
|
|
1536
|
-
const sendAs = params?.sendAs;
|
|
1537
|
-
if (sendAs !== undefined) {
|
|
1538
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("sendAs");
|
|
1539
|
-
return sendAs ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(sendAs) : undefined;
|
|
1540
|
-
}
|
|
1541
|
-
}, _MessageManager_constructReplyTo = async function _MessageManager_constructReplyTo(params) {
|
|
1542
|
-
const topMsgId = params?.messageThreadId;
|
|
1543
|
-
if (!params?.replyTo) {
|
|
1544
|
-
if (topMsgId) {
|
|
1545
|
-
return { _: "inputReplyToMessage", reply_to_msg_id: topMsgId, top_msg_id: topMsgId };
|
|
1546
|
-
}
|
|
1547
|
-
else {
|
|
1548
|
-
return undefined;
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
if ("messageId" in params.replyTo) {
|
|
1552
|
-
return { _: "inputReplyToMessage", reply_to_msg_id: params.replyTo.messageId, top_msg_id: topMsgId, quote_text: params.replyTo.quote?.text, quote_entities: await Promise.all(params.replyTo.quote?.entities.map((v) => (0, _3_types_js_2.messageEntityToTlObject)(v, __classPrivateFieldGet(this, _MessageManager_c, "f").getPeer)) ?? []), quote_offset: params.replyTo.quote?.offset };
|
|
1553
|
-
}
|
|
1554
|
-
else {
|
|
1555
|
-
return { _: "inputReplyToStory", peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(params.replyTo.chatId), story_id: params.replyTo.storyId };
|
|
1556
|
-
}
|
|
1557
|
-
}, _MessageManager_isM4a = function _MessageManager_isM4a(firstPart) {
|
|
1558
|
-
return firstPart.length >= 10 && (0, _0_deps_js_1.startsWith)(firstPart.subarray(4), new Uint8Array([0x66, 0x74, 0x79, 0x70, 0x4D, 0x34]));
|
|
1559
|
-
}, _MessageManager_sendDocumentInner = async function _MessageManager_sendDocumentInner(chatId, document, params, fileType, otherAttribs, urlSupported = true, expectedMimeTypes, createName) {
|
|
1560
|
-
let media = null;
|
|
1561
|
-
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
1562
|
-
const ttl_seconds = params && "selfDestruct" in params && typeof params.selfDestruct !== undefined ? (0, _3_types_js_1.selfDestructOptionToInt)(params.selfDestruct) : undefined;
|
|
1563
|
-
if (typeof document === "string") {
|
|
1564
|
-
const fileId = this.resolveFileId(document, fileType);
|
|
1565
|
-
if (fileId !== null) {
|
|
1566
|
-
media = { _: "inputMediaDocument", id: { ...fileId, _: "inputDocument" }, spoiler, query: otherAttribs.find((v) => _2_tl_js_1.Api.is("documentAttributeSticker", v))?.alt || undefined, ttl_seconds };
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
if (media === null) {
|
|
1570
|
-
if (typeof document === "string" && (0, _0_utilities_js_1.isHttpUrl)(document)) {
|
|
1571
|
-
if (!urlSupported) {
|
|
1572
|
-
throw new _0_errors_js_1.InputError("URL not supported.");
|
|
1573
|
-
}
|
|
1574
|
-
media = { _: "inputMediaDocumentExternal", url: document, spoiler, ttl_seconds };
|
|
1575
|
-
}
|
|
1576
|
-
else {
|
|
1577
|
-
let mimeType;
|
|
1578
|
-
const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(document, params, (name, firstPart) => {
|
|
1579
|
-
if (!params?.fileName && firstPart && createName) {
|
|
1580
|
-
name = createName(firstPart);
|
|
1581
|
-
}
|
|
1582
|
-
mimeType = params?.mimeType ?? (0, _0_deps_js_1.contentType)(name.split(".").slice(-1)[0]);
|
|
1583
|
-
if (name.endsWith(".tgs") && fileType === _3_types_js_2.FileType.Document) {
|
|
1584
|
-
name += "-";
|
|
1585
|
-
}
|
|
1586
|
-
return name;
|
|
1587
|
-
});
|
|
1588
|
-
mimeType ??= FALLBACK_MIME_TYPE;
|
|
1589
|
-
if (mimeType && expectedMimeTypes && !expectedMimeTypes.includes(mimeType)) {
|
|
1590
|
-
(0, _0_deps_js_1.unreachable)();
|
|
1591
|
-
}
|
|
1592
|
-
if (_2_tl_js_1.Api.is("inputFileStoryDocument", file)) {
|
|
1593
|
-
(0, _0_deps_js_1.unreachable)();
|
|
1594
|
-
}
|
|
1595
|
-
let thumb = undefined;
|
|
1596
|
-
if (params?.thumbnail) {
|
|
1597
|
-
thumb = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(params.thumbnail, { chunkSize: params?.chunkSize, signal: params?.signal });
|
|
1598
|
-
}
|
|
1599
|
-
media = { _: "inputMediaUploadedDocument", file, thumb, spoiler, attributes: [{ _: "documentAttributeFilename", file_name: file.name }, ...otherAttribs], mime_type: mimeType, force_file: fileType === _3_types_js_2.FileType.Document ? true : undefined, ttl_seconds };
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
const message = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_sendMedia).call(this, chatId, media, params);
|
|
1603
|
-
return message;
|
|
1604
|
-
}, _MessageManager_sendMedia = async function _MessageManager_sendMedia(chatId, media, params) {
|
|
1605
|
-
if (params?.starCount !== undefined) {
|
|
1606
|
-
if (params.starCount <= 0) {
|
|
1607
|
-
throw new _0_errors_js_1.InputError("starCount cannot be zero or negative");
|
|
1608
|
-
}
|
|
1609
|
-
media = { _: "inputMediaPaidMedia", stars_amount: BigInt(params.starCount), extended_media: [media] };
|
|
1610
|
-
}
|
|
1611
|
-
const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
1612
|
-
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
1613
|
-
const silent = params?.isSilent ? true : undefined;
|
|
1614
|
-
const noforwards = params?.isContentProtected ? true : undefined;
|
|
1615
|
-
const sendAs = params?.sendAs ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(params.sendAs) : undefined;
|
|
1616
|
-
const replyMarkup = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params);
|
|
1617
|
-
const caption_ = params?.caption;
|
|
1618
|
-
const parseResult = caption_ !== undefined ? this.parseText(caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
1619
|
-
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
1620
|
-
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
1621
|
-
const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").invoke({
|
|
1622
|
-
_: "messages.sendMedia",
|
|
1623
|
-
peer,
|
|
1624
|
-
random_id: randomId,
|
|
1625
|
-
silent,
|
|
1626
|
-
noforwards,
|
|
1627
|
-
reply_markup: replyMarkup,
|
|
1628
|
-
reply_to: await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyTo).call(this, params),
|
|
1629
|
-
send_as: sendAs,
|
|
1630
|
-
media,
|
|
1631
|
-
message: caption ?? "",
|
|
1632
|
-
entities: captionEntities,
|
|
1633
|
-
effect: params?.effectId ? BigInt(params.effectId) : undefined,
|
|
1634
|
-
schedule_date: params?.sendAt,
|
|
1635
|
-
allow_paid_floodskip: params?.isPaidBroadcast ? true : undefined,
|
|
1636
|
-
}, { businessConnectionId: params?.businessConnectionId });
|
|
1637
|
-
return (await this.updatesToMessages(chatId, result, params?.businessConnectionId))[0];
|
|
1638
|
-
}, _MessageManager_editInlineMessageTextInner = async function _MessageManager_editInlineMessageTextInner(inlineMessageId, text, params, allowEmpty = true) {
|
|
1639
|
-
__classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_checkParams).call(this, params);
|
|
1640
|
-
const [message, entities] = this.parseText(text, params);
|
|
1641
|
-
if (!allowEmpty && !message) {
|
|
1642
|
-
throw new _0_errors_js_1.InputError("Message text cannot be empty.");
|
|
1643
|
-
}
|
|
1644
|
-
const id = await (0, _3_types_js_2.deserializeInlineMessageId)(inlineMessageId);
|
|
1645
|
-
if (params?.linkPreview && params.linkPreview.type !== "input") {
|
|
1646
|
-
throw new _0_errors_js_1.InputError("Expected link preview of type input.");
|
|
1647
|
-
}
|
|
1648
|
-
const noWebpage = params?.linkPreview && params.linkPreview.type === "input" && params.linkPreview.isDisabled ? true : undefined;
|
|
1649
|
-
const invertMedia = params?.linkPreview?.isAboveText ? true : undefined;
|
|
1650
|
-
let media = undefined;
|
|
1651
|
-
if (!noWebpage && params?.linkPreview?.url) {
|
|
1652
|
-
media = { _: "inputMediaWebPage", url: params.linkPreview.url, force_large_media: params.linkPreview.mediaSize === "large" ? true : undefined, force_small_media: params.linkPreview.mediaSize === "small" ? true : undefined, optional: message.length ? undefined : true };
|
|
1653
|
-
}
|
|
1654
|
-
await __classPrivateFieldGet(this, _MessageManager_c, "f").invoke({
|
|
1655
|
-
_: "messages.editInlineBotMessage",
|
|
1656
|
-
id,
|
|
1657
|
-
entities,
|
|
1658
|
-
message,
|
|
1659
|
-
media,
|
|
1660
|
-
no_webpage: noWebpage,
|
|
1661
|
-
invert_media: invertMedia,
|
|
1662
|
-
reply_markup: await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params),
|
|
1663
|
-
}, { dc: (0, _3_transport_js_1.getDc)(id.dc_id) });
|
|
1664
|
-
}, _MessageManager_resolveInputMediaInner = async function _MessageManager_resolveInputMediaInner(document, media, fileType, otherAttribs) {
|
|
1665
|
-
let media_ = null;
|
|
1666
|
-
const spoiler = "hasSpoiler" in media && media.hasSpoiler ? true : undefined;
|
|
1667
|
-
if (typeof document === "string") {
|
|
1668
|
-
const fileId = this.resolveFileId(document, fileType);
|
|
1669
|
-
if (fileId !== null) {
|
|
1670
|
-
media_ = { _: "inputMediaDocument", id: { ...fileId, _: "inputDocument" }, spoiler, query: otherAttribs.find((v) => _2_tl_js_1.Api.is("documentAttributeSticker", v))?.alt || undefined };
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
if (media_ === null) {
|
|
1674
|
-
if (typeof document === "string" && (0, _0_utilities_js_1.isHttpUrl)(document)) {
|
|
1675
|
-
media_ = { _: "inputMediaDocumentExternal", url: document, spoiler };
|
|
1676
|
-
}
|
|
1677
|
-
else {
|
|
1678
|
-
let mimeType;
|
|
1679
|
-
const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(document, media, (name) => {
|
|
1680
|
-
mimeType = media?.mimeType ?? (0, _0_deps_js_1.contentType)(name.split(".").slice(-1)[0]) ?? FALLBACK_MIME_TYPE;
|
|
1681
|
-
if (name.endsWith(".tgs") && fileType === _3_types_js_2.FileType.Document) {
|
|
1682
|
-
name += "-";
|
|
1683
|
-
}
|
|
1684
|
-
return name;
|
|
1685
|
-
});
|
|
1686
|
-
if (_2_tl_js_1.Api.is("inputFileStoryDocument", file)) {
|
|
1687
|
-
(0, _0_deps_js_1.unreachable)();
|
|
1688
|
-
}
|
|
1689
|
-
let thumb = undefined;
|
|
1690
|
-
if ("thumbnail" in media && media.thumbnail) {
|
|
1691
|
-
thumb = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(media.thumbnail, { chunkSize: media?.chunkSize, signal: media?.signal });
|
|
1692
|
-
}
|
|
1693
|
-
media_ = { _: "inputMediaUploadedDocument", file, thumb, spoiler, attributes: [{ _: "documentAttributeFilename", file_name: file.name }, ...otherAttribs], mime_type: mimeType, force_file: fileType === _3_types_js_2.FileType.Document ? true : undefined };
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
return media_;
|
|
1697
|
-
}, _MessageManager_resolveInputMedia = async function _MessageManager_resolveInputMedia(media) {
|
|
1698
|
-
if ("animation" in media) {
|
|
1699
|
-
return await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_resolveInputMediaInner).call(this, media.animation, media, _3_types_js_2.FileType.Animation, [
|
|
1700
|
-
{ _: "documentAttributeAnimated" },
|
|
1701
|
-
{ _: "documentAttributeVideo", supports_streaming: true, w: media?.width ?? 0, h: media?.height ?? 0, duration: media?.duration ?? 0 },
|
|
1702
|
-
]);
|
|
1703
|
-
}
|
|
1704
|
-
else if ("audio" in media) {
|
|
1705
|
-
return await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_resolveInputMediaInner).call(this, media.audio, media, _3_types_js_2.FileType.Audio, [
|
|
1706
|
-
{ _: "documentAttributeAudio", duration: media?.duration ?? 0, performer: media?.performer, title: media?.title },
|
|
1707
|
-
]);
|
|
1708
|
-
}
|
|
1709
|
-
else if ("document" in media) {
|
|
1710
|
-
return await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_resolveInputMediaInner).call(this, media.document, media, _3_types_js_2.FileType.Document, []);
|
|
1711
|
-
}
|
|
1712
|
-
else if ("photo" in media) {
|
|
1713
|
-
let media_ = null;
|
|
1714
|
-
const spoiler = media.hasSpoiler ? true : undefined;
|
|
1715
|
-
const ttl_seconds = "selfDestruct" in media && media.selfDestruct !== undefined ? (0, _3_types_js_1.selfDestructOptionToInt)(media.selfDestruct) : undefined;
|
|
1716
|
-
if (typeof media.photo === "string") {
|
|
1717
|
-
const fileId = this.resolveFileId(media.photo, [_3_types_js_2.FileType.Photo, _3_types_js_2.FileType.ProfilePhoto]);
|
|
1718
|
-
if (fileId !== null) {
|
|
1719
|
-
media_ = { _: "inputMediaPhoto", id: { ...fileId, _: "inputPhoto" }, spoiler, ttl_seconds };
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
if (media_ === null) {
|
|
1723
|
-
if (typeof media.photo === "string" && (0, _0_utilities_js_1.isHttpUrl)(media.photo)) {
|
|
1724
|
-
media_ = { _: "inputMediaPhotoExternal", url: media.photo, spoiler };
|
|
1725
|
-
}
|
|
1726
|
-
else {
|
|
1727
|
-
const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(media.photo, media, null, false);
|
|
1728
|
-
media_ = { _: "inputMediaUploadedPhoto", file, spoiler, ttl_seconds };
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
return media_;
|
|
1732
|
-
}
|
|
1733
|
-
else if ("video" in media) {
|
|
1734
|
-
const ttl_seconds = "selfDestruct" in media && media.selfDestruct !== undefined ? (0, _3_types_js_1.selfDestructOptionToInt)(media.selfDestruct) : undefined;
|
|
1735
|
-
const media_ = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_resolveInputMediaInner).call(this, media.video, media, _3_types_js_2.FileType.Video, [
|
|
1736
|
-
{ _: "documentAttributeVideo", supports_streaming: media?.supportsStreaming ? true : undefined, w: media?.width ?? 0, h: media?.height ?? 0, duration: media?.duration ?? 0 },
|
|
1737
|
-
]);
|
|
1738
|
-
media_.ttl_seconds = ttl_seconds;
|
|
1739
|
-
return media_;
|
|
1740
|
-
}
|
|
1741
|
-
else {
|
|
1742
|
-
(0, _0_deps_js_1.unreachable)();
|
|
1743
|
-
}
|
|
1744
|
-
}, _MessageManager_resolveInputMediaUpload = async function _MessageManager_resolveInputMediaUpload(media, businessConnectionId) {
|
|
1745
|
-
const inputMedia = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_resolveInputMedia).call(this, media);
|
|
1746
|
-
if (_2_tl_js_1.Api.is("inputMediaUploadedPhoto", inputMedia) || _2_tl_js_1.Api.is("inputMediaUploadedDocument", inputMedia)) {
|
|
1747
|
-
const messageMedia = await __classPrivateFieldGet(this, _MessageManager_c, "f").invoke({
|
|
1748
|
-
_: "messages.uploadMedia",
|
|
1749
|
-
peer: { _: "inputPeerSelf" },
|
|
1750
|
-
media: inputMedia,
|
|
1751
|
-
business_connection_id: businessConnectionId,
|
|
1752
|
-
});
|
|
1753
|
-
if (("photo" in messageMedia) && _2_tl_js_1.Api.is("photo", messageMedia.photo)) {
|
|
1754
|
-
return {
|
|
1755
|
-
_: "inputMediaPhoto",
|
|
1756
|
-
id: {
|
|
1757
|
-
_: "inputPhoto",
|
|
1758
|
-
id: messageMedia.photo.id,
|
|
1759
|
-
access_hash: messageMedia.photo.access_hash,
|
|
1760
|
-
file_reference: messageMedia.photo.file_reference,
|
|
1761
|
-
},
|
|
1762
|
-
spoiler: "hasSpoiler" in media && media.hasSpoiler ? true : undefined,
|
|
1763
|
-
};
|
|
1764
|
-
}
|
|
1765
|
-
else if ("document" in messageMedia && _2_tl_js_1.Api.is("document", messageMedia.document)) {
|
|
1766
|
-
return {
|
|
1767
|
-
_: "inputMediaDocument",
|
|
1768
|
-
id: { _: "inputDocument", id: messageMedia.document.id, access_hash: messageMedia.document.access_hash, file_reference: messageMedia.document.file_reference },
|
|
1769
|
-
spoiler: "hasSpoiler" in media && media.hasSpoiler ? true : undefined,
|
|
1770
|
-
};
|
|
1771
|
-
}
|
|
1772
|
-
else {
|
|
1773
|
-
(0, _0_deps_js_1.unreachable)();
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
return inputMedia;
|
|
1777
|
-
}, _MessageManager_sendReaction = async function _MessageManager_sendReaction(chatId, messageId, reactions, params) {
|
|
1778
|
-
await __classPrivateFieldGet(this, _MessageManager_c, "f").invoke({ _: "messages.sendReaction", peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), msg_id: (0, _0_utilities_js_1.checkMessageId)(messageId), reaction: reactions.map((v) => (0, _3_types_js_2.reactionToTlObject)(v)), big: params?.isBig ? true : undefined, add_to_recent: params?.addToRecents ? true : undefined });
|
|
1779
|
-
}, _MessageManager_getCachedVoiceTranscription = async function _MessageManager_getCachedVoiceTranscription(message) {
|
|
1780
|
-
const reference = await __classPrivateFieldGet(this, _MessageManager_c, "f").messageStorage.getVoiceTranscriptionReference(message.chat.id, message.id, (0, _1_utilities_js_1.fromUnixTimestamp)(message.editDate ?? message.date));
|
|
1781
|
-
if (!reference) {
|
|
1782
|
-
return null;
|
|
1783
|
-
}
|
|
1784
|
-
const voiceTranscription = await __classPrivateFieldGet(this, _MessageManager_c, "f").messageStorage.getVoiceTranscription(reference);
|
|
1785
|
-
if (!voiceTranscription || !voiceTranscription.isCompleted) {
|
|
1786
|
-
return null;
|
|
1787
|
-
}
|
|
1788
|
-
return voiceTranscription;
|
|
1789
|
-
}, _MessageManager_cacheVoiceTranscription = async function _MessageManager_cacheVoiceTranscription(message, voiceTranscription) {
|
|
1790
|
-
await __classPrivateFieldGet(this, _MessageManager_c, "f").messageStorage.setVoiceTranscriptionReference(message.chat.id, message.id, (0, _1_utilities_js_1.fromUnixTimestamp)(message.editDate ?? message.date), BigInt(voiceTranscription.id));
|
|
1791
|
-
await __classPrivateFieldGet(this, _MessageManager_c, "f").messageStorage.setVoiceTranscription(voiceTranscription);
|
|
1792
|
-
return voiceTranscription;
|
|
1793
|
-
};
|
|
1794
|
-
_MessageManager_CAPTIONABLE_MESSAGE_TYPES = { value: ["photo", "document", "video", "animation", "voice", "audio", "video"] };
|