@mtkruto/node 0.67.2 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/0_errors.js +2 -6
- package/esm/3_errors.js +2 -12
- package/esm/3_types.d.ts +1 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +1 -0
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +99 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +127 -1
- package/esm/_dnt.test_polyfills.d.ts.map +1 -0
- package/esm/client/0_filters_test.d.ts.map +1 -1
- package/esm/client/0_markdown_test.d.ts.map +1 -1
- package/esm/client/0_params.d.ts +2 -0
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/0_password.d.ts +5 -5
- package/esm/client/0_password.d.ts.map +1 -1
- package/esm/client/0_password_test.d.ts.map +1 -1
- package/esm/client/0_storage_operations.js +143 -155
- package/esm/client/0_storage_operations_test.d.ts.map +1 -1
- package/esm/client/0_utilities.d.ts +1 -1
- package/esm/client/0_utilities_test.d.ts.map +1 -1
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/1_composer.js +8 -21
- package/esm/client/2_account_manager.js +85 -97
- 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 +194 -211
- package/esm/client/2_file_manager.d.ts +4 -3
- package/esm/client/2_file_manager.d.ts.map +1 -1
- package/esm/client/2_file_manager.js +268 -224
- package/esm/client/2_file_manager_test.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +8 -21
- 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 +97 -107
- package/esm/client/2_update_manager.js +764 -759
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/esm/client/3_message_manager.d.ts +1 -1
- package/esm/client/3_message_manager.js +441 -448
- package/esm/client/3_message_manager_test.d.ts.map +1 -1
- package/esm/client/3_video_chat_manager.d.ts +1 -1
- 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 +322 -318
- package/esm/client/4_chat_manager.js +118 -131
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +16 -29
- 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_client.d.ts +7 -0
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +1269 -1288
- package/esm/connection/1_connection_tcp.node.js +48 -65
- 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.0.13/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/esm/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/esm/mod.js +2 -12
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +324 -320
- package/esm/storage/1_utilities_test.d.ts.map +1 -1
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.node.js +12 -25
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/0_utilities_test.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +80 -88
- package/esm/tl/1_tl_reader_test.d.ts.map +1 -1
- package/esm/tl/1_tl_writer.js +155 -164
- package/esm/tl/1_tl_writer_test.d.ts.map +1 -1
- 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/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/esm/types/0_upload_progress.d.ts +29 -0
- package/esm/types/0_upload_progress.d.ts.map +1 -0
- package/esm/types/0_upload_progress.js +20 -0
- package/esm/types/1_sticker.d.ts +1 -1
- package/esm/types/1_sticker.d.ts.map +1 -1
- package/esm/types/2_poll_answer.d.ts +19 -0
- package/esm/types/2_poll_answer.d.ts.map +1 -1
- package/esm/types/2_poll_answer.js +19 -0
- package/esm/types/7_update.d.ts +21 -2
- package/esm/types/7_update.d.ts.map +1 -1
- package/esm/utilities/0_bigint_test.d.ts.map +1 -1
- package/esm/utilities/0_buffer.d.ts +1 -1
- package/esm/utilities/0_buffer.d.ts.map +1 -1
- package/esm/utilities/0_buffer_test.d.ts.map +1 -1
- package/esm/utilities/0_hash.d.ts +2 -2
- package/esm/utilities/0_hash.d.ts.map +1 -1
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/0_part_stream_test.d.ts.map +1 -1
- package/esm/utilities/0_rle.d.ts +2 -2
- package/esm/utilities/0_rle.d.ts.map +1 -1
- package/esm/utilities/0_rle_test.d.ts.map +1 -1
- package/esm/utilities/0_text.d.ts +20 -1
- package/esm/utilities/0_text.d.ts.map +1 -1
- package/esm/utilities/0_text.js +19 -0
- package/esm/utilities/1_auth.d.ts +1 -1
- package/esm/utilities/1_auth.d.ts.map +1 -1
- package/esm/utilities/1_base64.d.ts +1 -1
- package/esm/utilities/1_base64.d.ts.map +1 -1
- package/esm/utilities/1_base64_test.d.ts.map +1 -1
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/1_crypto_test.d.ts.map +1 -1
- package/esm/utilities/1_logger.d.ts +2 -2
- package/esm/utilities/1_math_test.d.ts.map +1 -1
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.js +2 -6
- package/script/2_tl.js +17 -7
- package/script/3_errors.js +2 -12
- package/script/3_types.d.ts +1 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +1 -0
- package/script/4_constants.js +17 -7
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +99 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +128 -0
- package/script/_dnt.test_polyfills.d.ts.map +1 -0
- package/script/client/0_filters_test.d.ts.map +1 -1
- package/script/client/0_markdown_test.d.ts.map +1 -1
- package/script/client/0_params.d.ts +2 -0
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/0_password.d.ts +5 -5
- package/script/client/0_password.d.ts.map +1 -1
- package/script/client/0_password.js +17 -7
- package/script/client/0_password_test.d.ts.map +1 -1
- package/script/client/0_storage_operations.js +143 -155
- package/script/client/0_storage_operations_test.d.ts.map +1 -1
- package/script/client/0_utilities.d.ts +1 -1
- package/script/client/0_utilities_test.d.ts.map +1 -1
- package/script/client/1_client_plain.js +4 -22
- package/script/client/1_composer.js +8 -21
- package/script/client/2_account_manager.js +85 -97
- 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 +195 -212
- package/script/client/2_file_manager.d.ts +4 -3
- package/script/client/2_file_manager.d.ts.map +1 -1
- package/script/client/2_file_manager.js +285 -231
- package/script/client/2_file_manager_test.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +8 -21
- 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 +98 -108
- package/script/client/2_update_manager.js +764 -759
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/script/client/3_message_manager.d.ts +1 -1
- package/script/client/3_message_manager.js +441 -448
- package/script/client/3_message_manager_test.d.ts.map +1 -1
- package/script/client/3_video_chat_manager.d.ts +1 -1
- 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 +322 -318
- package/script/client/4_chat_manager.js +118 -131
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +16 -29
- 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_client.d.ts +7 -0
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +1269 -1288
- package/script/connection/1_connection_tcp.node.js +48 -65
- package/script/connection/1_connection_web_socket.js +92 -98
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/assert/1.0.13/equal.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/delay.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/script/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/script/deps/jsr.io/@std/internal/1.0.10/format.js +17 -7
- package/script/deps/jsr.io/@std/internal/1.0.10/styles.js +17 -7
- package/script/deps/jsr.io/@std/path/1.1.0/_os.js +17 -7
- package/script/mod.js +19 -19
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +66 -79
- package/script/session/2_session_encrypted.js +325 -321
- package/script/storage/1_utilities_test.d.ts.map +1 -1
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.node.js +12 -25
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/0_utilities_test.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +81 -89
- package/script/tl/1_tl_reader_test.d.ts.map +1 -1
- package/script/tl/1_tl_writer.js +156 -165
- package/script/tl/1_tl_writer_test.d.ts.map +1 -1
- package/script/tl/2_telegram.js +17 -7
- package/script/transport/0_obfuscation.js +17 -7
- 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/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/script/types/0_upload_progress.d.ts +29 -0
- package/script/types/0_upload_progress.d.ts.map +1 -0
- package/script/types/0_upload_progress.js +21 -0
- package/script/types/1_sticker.d.ts +1 -1
- package/script/types/1_sticker.d.ts.map +1 -1
- package/script/types/2_poll_answer.d.ts +19 -0
- package/script/types/2_poll_answer.d.ts.map +1 -1
- package/script/types/2_poll_answer.js +19 -0
- package/script/types/7_update.d.ts +21 -2
- package/script/types/7_update.d.ts.map +1 -1
- package/script/utilities/0_bigint.js +17 -7
- package/script/utilities/0_bigint_test.d.ts.map +1 -1
- package/script/utilities/0_buffer.d.ts +1 -1
- package/script/utilities/0_buffer.d.ts.map +1 -1
- package/script/utilities/0_buffer_test.d.ts.map +1 -1
- package/script/utilities/0_env.js +17 -7
- package/script/utilities/0_hash.d.ts +2 -2
- package/script/utilities/0_hash.d.ts.map +1 -1
- package/script/utilities/0_hash.js +17 -7
- package/script/utilities/0_misc.js +17 -7
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/0_part_stream_test.d.ts.map +1 -1
- package/script/utilities/0_rle.d.ts +2 -2
- package/script/utilities/0_rle.d.ts.map +1 -1
- package/script/utilities/0_rle_test.d.ts.map +1 -1
- package/script/utilities/0_text.d.ts +20 -1
- package/script/utilities/0_text.d.ts.map +1 -1
- package/script/utilities/0_text.js +19 -0
- package/script/utilities/1_auth.d.ts +1 -1
- package/script/utilities/1_auth.d.ts.map +1 -1
- package/script/utilities/1_auth.js +17 -7
- package/script/utilities/1_base64.d.ts +1 -1
- package/script/utilities/1_base64.d.ts.map +1 -1
- package/script/utilities/1_base64_test.d.ts.map +1 -1
- package/script/utilities/1_crypto.js +60 -61
- package/script/utilities/1_crypto_test.d.ts.map +1 -1
- package/script/utilities/1_logger.d.ts +2 -2
- package/script/utilities/1_math_test.d.ts.map +1 -1
- package/script/utilities/2_queue.js +30 -48
|
@@ -17,18 +17,6 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _MessageManager_instances, _a, _MessageManager_c, _MessageManager_LresolveFileId, _MessageManager_checkParams, _MessageManager_constructReplyMarkup, _MessageManager_resolveSendAs, _MessageManager_constructReplyTo, _MessageManager_sendDocumentInner, _MessageManager_sendMedia, _MessageManager_CAPTIONABLE_MESSAGE_TYPES, _MessageManager_editInlineMessageTextInner, _MessageManager_resolveInputMediaInner, _MessageManager_resolveInputMedia, _MessageManager_sendReaction, _MessageManager_getCachedVoiceTranscription, _MessageManager_cacheVoiceTranscription;
|
|
32
20
|
import { contentType, unreachable } from "../0_deps.js";
|
|
33
21
|
import { InputError } from "../0_errors.js";
|
|
34
22
|
import { encodeText, fromUnixTimestamp, getLogger, getRandomId } from "../1_utilities.js";
|
|
@@ -57,31 +45,21 @@ const messageManagerUpdates = [
|
|
|
57
45
|
"updateTranscribedAudio",
|
|
58
46
|
];
|
|
59
47
|
export class MessageManager {
|
|
48
|
+
#c;
|
|
49
|
+
#LresolveFileId;
|
|
60
50
|
constructor(c) {
|
|
61
|
-
|
|
62
|
-
_MessageManager_c.set(this, void 0);
|
|
63
|
-
_MessageManager_LresolveFileId.set(this, void 0);
|
|
64
|
-
Object.defineProperty(this, "usernameResolver", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
configurable: true,
|
|
67
|
-
writable: true,
|
|
68
|
-
value: async (v) => {
|
|
69
|
-
const inputPeer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(v).then((v) => Api.as("inputPeerUser", v));
|
|
70
|
-
return { ...inputPeer, _: "inputUser" };
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
__classPrivateFieldSet(this, _MessageManager_c, c, "f");
|
|
51
|
+
this.#c = c;
|
|
74
52
|
const L = getLogger("MessageManager").client(c.id);
|
|
75
|
-
|
|
53
|
+
this.#LresolveFileId = L.branch("resolveFileId");
|
|
76
54
|
}
|
|
77
55
|
async getMessages(chatId, messageIds) {
|
|
78
56
|
checkArray(messageIds, checkMessageId);
|
|
79
|
-
const peer = await
|
|
57
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
80
58
|
let messages_ = new Array();
|
|
81
|
-
const chatId_ = await
|
|
59
|
+
const chatId_ = await this.#c.getInputPeerChatId(peer);
|
|
82
60
|
let shouldFetch = false;
|
|
83
61
|
for (const messageId of messageIds) {
|
|
84
|
-
const message = await
|
|
62
|
+
const message = await this.#c.messageStorage.getMessage(chatId_, messageId);
|
|
85
63
|
if (message == null) {
|
|
86
64
|
messages_ = [];
|
|
87
65
|
shouldFetch = true;
|
|
@@ -93,10 +71,10 @@ export class MessageManager {
|
|
|
93
71
|
}
|
|
94
72
|
if (shouldFetch) {
|
|
95
73
|
if (canBeInputChannel(peer)) {
|
|
96
|
-
messages_ = await
|
|
74
|
+
messages_ = await this.#c.invoke({ _: "channels.getMessages", channel: toInputChannel(peer), id: messageIds.map((v) => ({ _: "inputMessageID", id: v })) }).then((v) => Api.as("messages.channelMessages", v).messages);
|
|
97
75
|
}
|
|
98
76
|
else {
|
|
99
|
-
messages_ = await
|
|
77
|
+
messages_ = await this.#c.invoke({
|
|
100
78
|
_: "messages.getMessages",
|
|
101
79
|
id: messageIds.map((v) => ({ _: "inputMessageID", id: v })),
|
|
102
80
|
}).then((v) => Api.as("messages.messages", v).messages);
|
|
@@ -159,9 +137,23 @@ export class MessageManager {
|
|
|
159
137
|
}
|
|
160
138
|
return [text, entities];
|
|
161
139
|
}
|
|
140
|
+
#checkParams(params) {
|
|
141
|
+
if (params && "replyMarkup" in params && params.replyMarkup !== undefined) {
|
|
142
|
+
this.#c.storage.assertBot("replyMarkup");
|
|
143
|
+
}
|
|
144
|
+
if (params && "businessConnectionId" in params && params.businessConnectionId !== undefined) {
|
|
145
|
+
this.#c.storage.assertBot("businessConnectionId");
|
|
146
|
+
}
|
|
147
|
+
if (params && "sendAs" in params && params.sendAs !== undefined) {
|
|
148
|
+
this.#c.storage.assertUser("sendAs");
|
|
149
|
+
}
|
|
150
|
+
if (params && "sendAt" in params && params.sendAt !== undefined) {
|
|
151
|
+
this.#c.storage.assertUser("businessConsendAtnectionId");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
162
154
|
async parseText(text_, params) {
|
|
163
|
-
const [text, entities_] =
|
|
164
|
-
const entities = entities_?.length > 0 ? await Promise.all(entities_.map((v) => messageEntityToTlObject(v,
|
|
155
|
+
const [text, entities_] = MessageManager.parseText(text_, params?.entities ?? [], params?.parseMode ?? this.#c.parseMode);
|
|
156
|
+
const entities = entities_?.length > 0 ? await Promise.all(entities_.map((v) => messageEntityToTlObject(v, this.#c.getEntity))) : undefined;
|
|
165
157
|
return [text, entities];
|
|
166
158
|
}
|
|
167
159
|
async updatesToMessages(chatId, updates, businessConnectionId) {
|
|
@@ -203,35 +195,35 @@ export class MessageManager {
|
|
|
203
195
|
let poll = null;
|
|
204
196
|
let pollResults = null;
|
|
205
197
|
if (pollId) {
|
|
206
|
-
[poll, pollResults] = await Promise.all([
|
|
198
|
+
[poll, pollResults] = await Promise.all([this.#c.messageStorage.getPoll(pollId), this.#c.messageStorage.getPollResults(pollId)]);
|
|
207
199
|
}
|
|
208
|
-
const message = await constructMessage_(message_,
|
|
200
|
+
const message = await constructMessage_(message_, this.#c.getEntity, this.getMessage.bind(this), this.#c.fileManager.getStickerSetName.bind(this.#c.fileManager), r, business, poll ?? undefined, pollResults ?? undefined);
|
|
209
201
|
if (!poll && mediaPoll) {
|
|
210
|
-
await
|
|
202
|
+
await this.#c.storage.setPoll(mediaPoll.poll.id, mediaPoll.poll);
|
|
211
203
|
}
|
|
212
204
|
if (!pollResults && mediaPoll) {
|
|
213
|
-
await
|
|
205
|
+
await this.#c.storage.setPollResults(mediaPoll.poll.id, mediaPoll.results);
|
|
214
206
|
}
|
|
215
207
|
return message;
|
|
216
208
|
}
|
|
217
209
|
async forwardMessages(from, to, messageIds, params) {
|
|
218
210
|
checkArray(messageIds, checkMessageId);
|
|
219
|
-
const result = await
|
|
211
|
+
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(() => getRandomId()), silent: params?.disableNotification || undefined, top_msg_id: params?.messageThreadId, noforwards: params?.disableNotification || undefined, send_as: params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined, drop_author: params?.dropSenderName || undefined, drop_media_captions: params?.dropCaption || undefined });
|
|
220
212
|
return await this.updatesToMessages(to, result);
|
|
221
213
|
}
|
|
222
214
|
async getHistory(chatId, params) {
|
|
223
|
-
|
|
215
|
+
this.#c.storage.assertUser("getHistory");
|
|
224
216
|
const limit = getLimit(params?.limit);
|
|
225
217
|
let offsetId = params?.fromMessageId ?? 0;
|
|
226
218
|
if (offsetId < 0) {
|
|
227
219
|
offsetId = 0;
|
|
228
220
|
}
|
|
229
|
-
const peer = await
|
|
221
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
230
222
|
const messages = new Array();
|
|
231
223
|
if (messages.length > 0) {
|
|
232
224
|
offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
|
|
233
225
|
}
|
|
234
|
-
const result = await
|
|
226
|
+
const result = await this.#c.invoke({ _: "messages.getHistory", peer: peer, offset_id: offsetId, offset_date: 0, add_offset: 0, limit, max_id: 0, min_id: 0, hash: 0n });
|
|
235
227
|
if (!("messages" in result)) {
|
|
236
228
|
unreachable();
|
|
237
229
|
}
|
|
@@ -241,23 +233,40 @@ export class MessageManager {
|
|
|
241
233
|
}
|
|
242
234
|
return messages;
|
|
243
235
|
}
|
|
236
|
+
usernameResolver = async (v) => {
|
|
237
|
+
const inputPeer = await this.#c.getInputPeer(v).then((v) => Api.as("inputPeerUser", v));
|
|
238
|
+
return { ...inputPeer, _: "inputUser" };
|
|
239
|
+
};
|
|
240
|
+
async #constructReplyMarkup(params) {
|
|
241
|
+
if (params?.replyMarkup) {
|
|
242
|
+
this.#c.storage.assertBot("replyMarkup");
|
|
243
|
+
return await replyMarkupToTlObject(params.replyMarkup, this.usernameResolver.bind(this));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async #resolveSendAs(params) {
|
|
247
|
+
const sendAs = params?.sendAs;
|
|
248
|
+
if (sendAs !== undefined) {
|
|
249
|
+
this.#c.storage.assertUser("sendAs");
|
|
250
|
+
return sendAs ? await this.#c.getInputPeer(sendAs) : undefined;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
244
253
|
async sendMessage(chatId, text, params) {
|
|
245
|
-
|
|
254
|
+
this.#checkParams(params);
|
|
246
255
|
const [message, entities] = await this.parseText(text, params);
|
|
247
|
-
const replyMarkup = await
|
|
248
|
-
const peer = await
|
|
256
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
257
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
249
258
|
const randomId = getRandomId();
|
|
250
259
|
const noWebpage = params?.linkPreview?.disable ? true : undefined;
|
|
251
260
|
const invertMedia = params?.linkPreview?.aboveText ? true : undefined;
|
|
252
261
|
const silent = params?.disableNotification ? true : undefined;
|
|
253
262
|
const noforwards = params?.protectContent ? true : undefined;
|
|
254
|
-
const sendAs = await
|
|
263
|
+
const sendAs = await this.#resolveSendAs(params);
|
|
255
264
|
const effect = params?.effectId ? BigInt(params.effectId) : undefined;
|
|
256
265
|
const schedule_date = params?.sendAt;
|
|
257
266
|
const allow_paid_floodskip = params?.paidBroadcast ? true : undefined;
|
|
258
267
|
let result;
|
|
259
268
|
if (!noWebpage && params?.linkPreview?.url) {
|
|
260
|
-
result = await
|
|
269
|
+
result = await this.#c.invoke({
|
|
261
270
|
_: "messages.sendMedia",
|
|
262
271
|
peer,
|
|
263
272
|
random_id: randomId,
|
|
@@ -272,7 +281,7 @@ export class MessageManager {
|
|
|
272
281
|
invert_media: invertMedia,
|
|
273
282
|
silent,
|
|
274
283
|
noforwards,
|
|
275
|
-
reply_to: await
|
|
284
|
+
reply_to: await this.#constructReplyTo(params),
|
|
276
285
|
send_as: sendAs,
|
|
277
286
|
entities,
|
|
278
287
|
reply_markup: replyMarkup,
|
|
@@ -282,7 +291,7 @@ export class MessageManager {
|
|
|
282
291
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
283
292
|
}
|
|
284
293
|
else {
|
|
285
|
-
result = await
|
|
294
|
+
result = await this.#c.invoke({
|
|
286
295
|
_: "messages.sendMessage",
|
|
287
296
|
peer,
|
|
288
297
|
random_id: randomId,
|
|
@@ -291,7 +300,7 @@ export class MessageManager {
|
|
|
291
300
|
invert_media: invertMedia,
|
|
292
301
|
silent,
|
|
293
302
|
noforwards,
|
|
294
|
-
reply_to: await
|
|
303
|
+
reply_to: await this.#constructReplyTo(params),
|
|
295
304
|
send_as: sendAs,
|
|
296
305
|
entities,
|
|
297
306
|
reply_markup: replyMarkup,
|
|
@@ -303,21 +312,38 @@ export class MessageManager {
|
|
|
303
312
|
const message_ = (await this.updatesToMessages(chatId, result, params?.businessConnectionId))[0];
|
|
304
313
|
return assertMessageType(message_, "text");
|
|
305
314
|
}
|
|
315
|
+
async #constructReplyTo(params) {
|
|
316
|
+
const topMsgId = params?.messageThreadId;
|
|
317
|
+
if (!params?.replyTo) {
|
|
318
|
+
if (topMsgId) {
|
|
319
|
+
return { _: "inputReplyToMessage", reply_to_msg_id: topMsgId };
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if ("messageId" in params.replyTo) {
|
|
326
|
+
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) => messageEntityToTlObject(v, this.#c.getEntity)) ?? []), quote_offset: params.replyTo.quote?.offset };
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
return { _: "inputReplyToStory", peer: await this.#c.getInputPeer(params.replyTo.chatId), story_id: params.replyTo.storyId };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
306
332
|
async sendVenue(chatId, latitude, longitude, title, address, params) {
|
|
307
|
-
|
|
308
|
-
const peer = await
|
|
333
|
+
this.#checkParams(params);
|
|
334
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
309
335
|
const randomId = getRandomId();
|
|
310
336
|
const silent = params?.disableNotification ? true : undefined;
|
|
311
337
|
const noforwards = params?.protectContent ? true : undefined;
|
|
312
|
-
const sendAs = params?.sendAs ? await
|
|
313
|
-
const replyMarkup = await
|
|
314
|
-
const result = await
|
|
338
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
339
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
340
|
+
const result = await this.#c.invoke({
|
|
315
341
|
_: "messages.sendMedia",
|
|
316
342
|
peer,
|
|
317
343
|
random_id: randomId,
|
|
318
344
|
silent,
|
|
319
345
|
noforwards,
|
|
320
|
-
reply_to: await
|
|
346
|
+
reply_to: await this.#constructReplyTo(params),
|
|
321
347
|
send_as: sendAs,
|
|
322
348
|
reply_markup: replyMarkup,
|
|
323
349
|
media: ({
|
|
@@ -342,20 +368,20 @@ export class MessageManager {
|
|
|
342
368
|
return assertMessageType(message, "venue");
|
|
343
369
|
}
|
|
344
370
|
async sendContact(chatId, firstName, number, params) {
|
|
345
|
-
|
|
346
|
-
const peer = await
|
|
371
|
+
this.#checkParams(params);
|
|
372
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
347
373
|
const randomId = getRandomId();
|
|
348
374
|
const silent = params?.disableNotification ? true : undefined;
|
|
349
375
|
const noforwards = params?.protectContent ? true : undefined;
|
|
350
|
-
const sendAs = params?.sendAs ? await
|
|
351
|
-
const replyMarkup = await
|
|
352
|
-
const result = await
|
|
376
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
377
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
378
|
+
const result = await this.#c.invoke({
|
|
353
379
|
_: "messages.sendMedia",
|
|
354
380
|
peer,
|
|
355
381
|
random_id: randomId,
|
|
356
382
|
silent,
|
|
357
383
|
noforwards,
|
|
358
|
-
reply_to: await
|
|
384
|
+
reply_to: await this.#constructReplyTo(params),
|
|
359
385
|
send_as: sendAs,
|
|
360
386
|
reply_markup: replyMarkup,
|
|
361
387
|
media: ({
|
|
@@ -374,20 +400,20 @@ export class MessageManager {
|
|
|
374
400
|
return assertMessageType(message, "contact");
|
|
375
401
|
}
|
|
376
402
|
async sendDice(chatId, params) {
|
|
377
|
-
|
|
378
|
-
const peer = await
|
|
403
|
+
this.#checkParams(params);
|
|
404
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
379
405
|
const randomId = getRandomId();
|
|
380
406
|
const silent = params?.disableNotification ? true : undefined;
|
|
381
407
|
const noforwards = params?.protectContent ? true : undefined;
|
|
382
|
-
const sendAs = params?.sendAs ? await
|
|
383
|
-
const replyMarkup = await
|
|
384
|
-
const result = await
|
|
408
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
409
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
410
|
+
const result = await this.#c.invoke({
|
|
385
411
|
_: "messages.sendMedia",
|
|
386
412
|
peer,
|
|
387
413
|
random_id: randomId,
|
|
388
414
|
silent,
|
|
389
415
|
noforwards,
|
|
390
|
-
reply_to: await
|
|
416
|
+
reply_to: await this.#constructReplyTo(params),
|
|
391
417
|
send_as: sendAs,
|
|
392
418
|
reply_markup: replyMarkup,
|
|
393
419
|
media: ({
|
|
@@ -403,20 +429,20 @@ export class MessageManager {
|
|
|
403
429
|
return assertMessageType(message, "dice");
|
|
404
430
|
}
|
|
405
431
|
async sendLocation(chatId, latitude, longitude, params) {
|
|
406
|
-
|
|
407
|
-
const peer = await
|
|
432
|
+
this.#checkParams(params);
|
|
433
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
408
434
|
const randomId = getRandomId();
|
|
409
435
|
const silent = params?.disableNotification ? true : undefined;
|
|
410
436
|
const noforwards = params?.protectContent ? true : undefined;
|
|
411
|
-
const sendAs = params?.sendAs ? await
|
|
412
|
-
const replyMarkup = await
|
|
413
|
-
const result = await
|
|
437
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
438
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
439
|
+
const result = await this.#c.invoke({
|
|
414
440
|
_: "messages.sendMedia",
|
|
415
441
|
peer,
|
|
416
442
|
random_id: randomId,
|
|
417
443
|
silent,
|
|
418
444
|
noforwards,
|
|
419
|
-
reply_to: await
|
|
445
|
+
reply_to: await this.#constructReplyTo(params),
|
|
420
446
|
send_as: sendAs,
|
|
421
447
|
reply_markup: replyMarkup,
|
|
422
448
|
media: params?.livePeriod !== undefined
|
|
@@ -450,53 +476,95 @@ export class MessageManager {
|
|
|
450
476
|
return assertMessageType(message, "location");
|
|
451
477
|
}
|
|
452
478
|
async sendVideoNote(chatId, audio, params) {
|
|
453
|
-
|
|
454
|
-
const message = await
|
|
479
|
+
this.#checkParams(params);
|
|
480
|
+
const message = await this.#sendDocumentInner(chatId, audio, params, FileType.VideoNote, [
|
|
455
481
|
{ _: "documentAttributeVideo", round_message: true, w: params?.length ?? 0, h: params?.length ?? 0, duration: params?.duration ?? 0 },
|
|
456
482
|
], false);
|
|
457
483
|
return assertMessageType(message, "videoNote");
|
|
458
484
|
}
|
|
459
485
|
async sendAudio(chatId, audio, params) {
|
|
460
|
-
|
|
461
|
-
const message = await
|
|
486
|
+
this.#checkParams(params);
|
|
487
|
+
const message = await this.#sendDocumentInner(chatId, audio, params, FileType.Audio, [
|
|
462
488
|
{ _: "documentAttributeAudio", duration: params?.duration ?? 0, performer: params?.performer, title: params?.title },
|
|
463
489
|
]);
|
|
464
490
|
return assertMessageType(message, "audio");
|
|
465
491
|
}
|
|
466
492
|
async sendVoice(chatId, voice, params) {
|
|
467
|
-
|
|
468
|
-
const message = await
|
|
493
|
+
this.#checkParams(params);
|
|
494
|
+
const message = await this.#sendDocumentInner(chatId, voice, params, FileType.VoiceNote, [
|
|
469
495
|
{ _: "documentAttributeAudio", voice: true, duration: params?.duration ?? 0 },
|
|
470
496
|
]);
|
|
471
497
|
return assertMessageType(message, "voice");
|
|
472
498
|
}
|
|
473
499
|
async sendAnimation(chatId, animation, params) {
|
|
474
|
-
|
|
475
|
-
const message = await
|
|
500
|
+
this.#checkParams(params);
|
|
501
|
+
const message = await this.#sendDocumentInner(chatId, animation, params, FileType.Animation, [
|
|
476
502
|
{ _: "documentAttributeAnimated" },
|
|
477
503
|
{ _: "documentAttributeVideo", supports_streaming: true, w: params?.width ?? 0, h: params?.height ?? 0, duration: params?.duration ?? 0 },
|
|
478
504
|
]);
|
|
479
505
|
return assertMessageType(message, "animation");
|
|
480
506
|
}
|
|
481
507
|
async sendVideo(chatId, video, params) {
|
|
482
|
-
|
|
483
|
-
const message = await
|
|
508
|
+
this.#checkParams(params);
|
|
509
|
+
const message = await this.#sendDocumentInner(chatId, video, params, FileType.Video, [
|
|
484
510
|
{ _: "documentAttributeVideo", supports_streaming: params?.supportsStreaming ? true : undefined, w: params?.width ?? 0, h: params?.height ?? 0, duration: params?.duration ?? 0 },
|
|
485
511
|
]);
|
|
486
512
|
return assertMessageType(message, "video");
|
|
487
513
|
}
|
|
514
|
+
async #sendDocumentInner(chatId, document, params, fileType, otherAttribs, urlSupported = true, expectedMimeTypes) {
|
|
515
|
+
let media = null;
|
|
516
|
+
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
517
|
+
const ttl_seconds = params && "selfDestruct" in params && typeof params.selfDestruct !== undefined ? selfDestructOptionToInt(params.selfDestruct) : undefined;
|
|
518
|
+
if (typeof document === "string") {
|
|
519
|
+
const fileId = this.resolveFileId(document, fileType);
|
|
520
|
+
if (fileId != null) {
|
|
521
|
+
media = { _: "inputMediaDocument", id: { ...fileId, _: "inputDocument" }, spoiler, query: otherAttribs.find((v) => Api.is("documentAttributeSticker", v))?.alt || undefined, ttl_seconds };
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (media == null) {
|
|
525
|
+
if (typeof document === "string" && isHttpUrl(document)) {
|
|
526
|
+
if (!urlSupported) {
|
|
527
|
+
throw new InputError("URL not supported.");
|
|
528
|
+
}
|
|
529
|
+
media = { _: "inputMediaDocumentExternal", url: document, spoiler, ttl_seconds };
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
let mimeType;
|
|
533
|
+
const file = await this.#c.fileManager.upload(document, params, (name) => {
|
|
534
|
+
mimeType = params?.mimeType ?? contentType(name.split(".").slice(-1)[0]) ?? FALLBACK_MIME_TYPE;
|
|
535
|
+
if (expectedMimeTypes && !expectedMimeTypes.includes(mimeType)) {
|
|
536
|
+
unreachable();
|
|
537
|
+
}
|
|
538
|
+
if (name.endsWith(".tgs") && fileType == FileType.Document) {
|
|
539
|
+
name += "-";
|
|
540
|
+
}
|
|
541
|
+
return name;
|
|
542
|
+
});
|
|
543
|
+
if (Api.is("inputFileStoryDocument", file)) {
|
|
544
|
+
unreachable();
|
|
545
|
+
}
|
|
546
|
+
let thumb = undefined;
|
|
547
|
+
if (params?.thumbnail) {
|
|
548
|
+
thumb = await this.#c.fileManager.upload(params.thumbnail, { chunkSize: params?.chunkSize, signal: params?.signal });
|
|
549
|
+
}
|
|
550
|
+
media = { _: "inputMediaUploadedDocument", file, thumb, spoiler, attributes: [{ _: "documentAttributeFilename", file_name: file.name }, ...otherAttribs], mime_type: mimeType, force_file: fileType == FileType.Document ? true : undefined, ttl_seconds };
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
const message = await this.#sendMedia(chatId, media, params);
|
|
554
|
+
return message;
|
|
555
|
+
}
|
|
488
556
|
async sendDocument(chatId, document, params) {
|
|
489
|
-
|
|
490
|
-
const message = await
|
|
557
|
+
this.#checkParams(params);
|
|
558
|
+
const message = await this.#sendDocumentInner(chatId, document, params, FileType.Document, []);
|
|
491
559
|
return assertMessageType(message, "document");
|
|
492
560
|
}
|
|
493
561
|
async sendSticker(chatId, sticker, params) {
|
|
494
|
-
|
|
495
|
-
const message = await
|
|
562
|
+
this.#checkParams(params);
|
|
563
|
+
const message = await this.#sendDocumentInner(chatId, sticker, params, FileType.Sticker, [{ _: "documentAttributeSticker", alt: params?.emoji || "", stickerset: { _: "inputStickerSetEmpty" } }], undefined, STICKER_MIME_TYPES);
|
|
496
564
|
return assertMessageType(message, "sticker");
|
|
497
565
|
}
|
|
498
566
|
async sendPhoto(chatId, photo, params) {
|
|
499
|
-
|
|
567
|
+
this.#checkParams(params);
|
|
500
568
|
let media = null;
|
|
501
569
|
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
502
570
|
const ttl_seconds = params && "selfDestruct" in params && params.selfDestruct !== undefined ? selfDestructOptionToInt(params.selfDestruct) : undefined;
|
|
@@ -511,13 +579,48 @@ export class MessageManager {
|
|
|
511
579
|
media = { _: "inputMediaPhotoExternal", url: photo, spoiler, ttl_seconds: (params && "selfDestruct" in params && params.selfDestruct !== undefined) ? selfDestructOptionToInt(params.selfDestruct) : undefined };
|
|
512
580
|
}
|
|
513
581
|
else {
|
|
514
|
-
const file = await
|
|
582
|
+
const file = await this.#c.fileManager.upload(photo, params, null, false);
|
|
515
583
|
media = { _: "inputMediaUploadedPhoto", file, spoiler, ttl_seconds: (params && "selfDestruct" in params && params.selfDestruct !== undefined) ? selfDestructOptionToInt(params.selfDestruct) : undefined };
|
|
516
584
|
}
|
|
517
585
|
}
|
|
518
|
-
const message = await
|
|
586
|
+
const message = await this.#sendMedia(chatId, media, params);
|
|
519
587
|
return assertMessageType(message, "photo");
|
|
520
588
|
}
|
|
589
|
+
async #sendMedia(chatId, media, params) {
|
|
590
|
+
if (params?.starCount !== undefined) {
|
|
591
|
+
if (params.starCount <= 0) {
|
|
592
|
+
throw new InputError("starCount cannot be zero or negative");
|
|
593
|
+
}
|
|
594
|
+
media = { _: "inputMediaPaidMedia", stars_amount: BigInt(params.starCount), extended_media: [media] };
|
|
595
|
+
}
|
|
596
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
597
|
+
const randomId = getRandomId();
|
|
598
|
+
const silent = params?.disableNotification ? true : undefined;
|
|
599
|
+
const noforwards = params?.protectContent ? true : undefined;
|
|
600
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
601
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
602
|
+
const caption_ = params?.caption;
|
|
603
|
+
const parseResult = caption_ !== undefined ? await this.parseText(caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
604
|
+
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
605
|
+
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
606
|
+
const result = await this.#c.invoke({
|
|
607
|
+
_: "messages.sendMedia",
|
|
608
|
+
peer,
|
|
609
|
+
random_id: randomId,
|
|
610
|
+
silent,
|
|
611
|
+
noforwards,
|
|
612
|
+
reply_markup: replyMarkup,
|
|
613
|
+
reply_to: await this.#constructReplyTo(params),
|
|
614
|
+
send_as: sendAs,
|
|
615
|
+
media,
|
|
616
|
+
message: caption ?? "",
|
|
617
|
+
entities: captionEntities,
|
|
618
|
+
effect: params?.effectId ? BigInt(params.effectId) : undefined,
|
|
619
|
+
schedule_date: params?.sendAt,
|
|
620
|
+
allow_paid_floodskip: params?.paidBroadcast ? true : undefined,
|
|
621
|
+
}, { businessConnectionId: params?.businessConnectionId });
|
|
622
|
+
return (await this.updatesToMessages(chatId, result, params?.businessConnectionId))[0];
|
|
623
|
+
}
|
|
521
624
|
resolveFileId(maybeFileId, expectedFileType) {
|
|
522
625
|
expectedFileType = Array.isArray(expectedFileType) ? expectedFileType : [expectedFileType];
|
|
523
626
|
let fileId = null;
|
|
@@ -525,7 +628,7 @@ export class MessageManager {
|
|
|
525
628
|
fileId = deserializeFileId(maybeFileId);
|
|
526
629
|
}
|
|
527
630
|
catch (err) {
|
|
528
|
-
|
|
631
|
+
this.#LresolveFileId.warning(err);
|
|
529
632
|
}
|
|
530
633
|
if (fileId != null) {
|
|
531
634
|
if (!expectedFileType.includes(fileId.type)) {
|
|
@@ -540,7 +643,7 @@ export class MessageManager {
|
|
|
540
643
|
return null;
|
|
541
644
|
}
|
|
542
645
|
async sendPoll(chatId, question, options, params) {
|
|
543
|
-
|
|
646
|
+
this.#checkParams(params);
|
|
544
647
|
question = question?.trim();
|
|
545
648
|
if (!question) {
|
|
546
649
|
throw new Error("Question must not be empty.");
|
|
@@ -548,12 +651,12 @@ export class MessageManager {
|
|
|
548
651
|
if (!Array.isArray(options) || options.length < 2) {
|
|
549
652
|
throw new Error("There must be at least two options.");
|
|
550
653
|
}
|
|
551
|
-
const peer = await
|
|
654
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
552
655
|
const randomId = getRandomId();
|
|
553
656
|
const silent = params?.disableNotification ? true : undefined;
|
|
554
657
|
const noforwards = params?.protectContent ? true : undefined;
|
|
555
|
-
const sendAs = params?.sendAs ? await
|
|
556
|
-
const replyMarkup = await
|
|
658
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
659
|
+
const replyMarkup = await this.#constructReplyMarkup(params);
|
|
557
660
|
const explanation = params?.explanation;
|
|
558
661
|
const parseResult = explanation !== undefined ? await this.parseText(explanation, { parseMode: params?.explanationParseMode, entities: params?.explanationEntities }) : undefined;
|
|
559
662
|
const solution = parseResult === undefined ? undefined : parseResult[0];
|
|
@@ -567,14 +670,14 @@ export class MessageManager {
|
|
|
567
670
|
const questionParseResult = await this.parseText(question, { parseMode: params?.questionParseMode, entities: params?.questionEntities });
|
|
568
671
|
const poll = { _: "poll", id: 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 };
|
|
569
672
|
const media = { _: "inputMediaPoll", poll, correct_answers: params?.correctOptionIndex !== undefined ? [encodeText(String(params.correctOptionIndex))] : undefined, solution, solution_entities: solutionEntities };
|
|
570
|
-
const result = await
|
|
673
|
+
const result = await this.#c.invoke({
|
|
571
674
|
_: "messages.sendMedia",
|
|
572
675
|
peer,
|
|
573
676
|
random_id: randomId,
|
|
574
677
|
silent,
|
|
575
678
|
noforwards,
|
|
576
679
|
reply_markup: replyMarkup,
|
|
577
|
-
reply_to: await
|
|
680
|
+
reply_to: await this.#constructReplyTo(params),
|
|
578
681
|
send_as: sendAs,
|
|
579
682
|
media,
|
|
580
683
|
message: "",
|
|
@@ -586,26 +689,26 @@ export class MessageManager {
|
|
|
586
689
|
return assertMessageType(message, "poll");
|
|
587
690
|
}
|
|
588
691
|
async editMessageReplyMarkup(chatId, messageId, params) {
|
|
589
|
-
|
|
590
|
-
const result = await
|
|
692
|
+
this.#checkParams(params);
|
|
693
|
+
const result = await this.#c.invoke({
|
|
591
694
|
_: "messages.editMessage",
|
|
592
695
|
id: checkMessageId(messageId),
|
|
593
|
-
peer: await
|
|
594
|
-
reply_markup: await
|
|
696
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
697
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
595
698
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
596
699
|
const message_ = (await this.updatesToMessages(chatId, result))[0];
|
|
597
700
|
return message_;
|
|
598
701
|
}
|
|
599
702
|
async editInlineMessageReplyMarkup(inlineMessageId, params) {
|
|
600
703
|
const id = await deserializeInlineMessageId(inlineMessageId);
|
|
601
|
-
await
|
|
704
|
+
await this.#c.invoke({
|
|
602
705
|
_: "messages.editInlineBotMessage",
|
|
603
706
|
id,
|
|
604
|
-
reply_markup: await
|
|
707
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
605
708
|
}, { dc: getDc(id.dc_id) });
|
|
606
709
|
}
|
|
607
710
|
async editMessageText(chatId, messageId, text, params) {
|
|
608
|
-
|
|
711
|
+
this.#checkParams(params);
|
|
609
712
|
{
|
|
610
713
|
const message = await this.getMessage(chatId, messageId);
|
|
611
714
|
if (!message) {
|
|
@@ -628,27 +731,28 @@ export class MessageManager {
|
|
|
628
731
|
if (!noWebpage && params?.linkPreview?.url) {
|
|
629
732
|
media = { _: "inputMediaWebPage", url: params.linkPreview.url, force_large_media: params.linkPreview.largeMedia ? true : undefined, force_small_media: params.linkPreview.smallMedia ? true : undefined, optional: message.length ? undefined : true };
|
|
630
733
|
}
|
|
631
|
-
const result = await
|
|
734
|
+
const result = await this.#c.invoke({
|
|
632
735
|
_: "messages.editMessage",
|
|
633
736
|
id: checkMessageId(messageId),
|
|
634
|
-
peer: await
|
|
737
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
635
738
|
entities,
|
|
636
739
|
message,
|
|
637
740
|
media,
|
|
638
741
|
no_webpage: noWebpage,
|
|
639
742
|
invert_media: invertMedia,
|
|
640
|
-
reply_markup: await
|
|
743
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
641
744
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
642
745
|
const message_ = (await this.updatesToMessages(chatId, result))[0];
|
|
643
746
|
return assertMessageType(message_, "text");
|
|
644
747
|
}
|
|
748
|
+
static #CAPTIONABLE_MESSAGE_TYPES = ["photo", "document", "video", "animation", "voice", "audio", "video"];
|
|
645
749
|
async editMessageCaption(chatId, messageId, params) {
|
|
646
750
|
let canHaveCaption = false;
|
|
647
751
|
const message_ = await this.getMessage(chatId, messageId);
|
|
648
752
|
if (!message_) {
|
|
649
753
|
throw new InputError("Message not found.");
|
|
650
754
|
}
|
|
651
|
-
for (const type of
|
|
755
|
+
for (const type of MessageManager.#CAPTIONABLE_MESSAGE_TYPES) {
|
|
652
756
|
if (isMessageType(message_, type)) {
|
|
653
757
|
canHaveCaption = true;
|
|
654
758
|
}
|
|
@@ -657,24 +761,133 @@ export class MessageManager {
|
|
|
657
761
|
throw new InputError("The referenced message cannot have a caption.");
|
|
658
762
|
}
|
|
659
763
|
const [message, entities] = await this.parseText(params?.caption ?? "", params);
|
|
660
|
-
const result = await
|
|
764
|
+
const result = await this.#c.invoke({
|
|
661
765
|
_: "messages.editMessage",
|
|
662
766
|
id: checkMessageId(messageId),
|
|
663
|
-
peer: await
|
|
767
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
664
768
|
entities: message ? entities : [],
|
|
665
769
|
message,
|
|
666
|
-
reply_markup: await
|
|
770
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
667
771
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
668
772
|
return (await this.updatesToMessages(chatId, result))[0];
|
|
669
773
|
}
|
|
774
|
+
async #editInlineMessageTextInner(inlineMessageId, text, params, allowEmpty = true) {
|
|
775
|
+
this.#checkParams(params);
|
|
776
|
+
const [message, entities] = await this.parseText(text, params);
|
|
777
|
+
if (!allowEmpty && !message) {
|
|
778
|
+
throw new InputError("Message text cannot be empty.");
|
|
779
|
+
}
|
|
780
|
+
const id = await deserializeInlineMessageId(inlineMessageId);
|
|
781
|
+
if (params?.linkPreview && params.linkPreview.type != "input") {
|
|
782
|
+
throw new InputError("Expected link preview of type input.");
|
|
783
|
+
}
|
|
784
|
+
const noWebpage = params?.linkPreview && params.linkPreview.type == "input" && params.linkPreview.disable ? true : undefined;
|
|
785
|
+
const invertMedia = params?.linkPreview?.aboveText ? true : undefined;
|
|
786
|
+
let media = undefined;
|
|
787
|
+
if (!noWebpage && params?.linkPreview?.url) {
|
|
788
|
+
media = { _: "inputMediaWebPage", url: params.linkPreview.url, force_large_media: params.linkPreview.largeMedia ? true : undefined, force_small_media: params.linkPreview.smallMedia ? true : undefined, optional: message.length ? undefined : true };
|
|
789
|
+
}
|
|
790
|
+
await this.#c.invoke({
|
|
791
|
+
_: "messages.editInlineBotMessage",
|
|
792
|
+
id,
|
|
793
|
+
entities,
|
|
794
|
+
message,
|
|
795
|
+
media,
|
|
796
|
+
no_webpage: noWebpage,
|
|
797
|
+
invert_media: invertMedia,
|
|
798
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
799
|
+
}, { dc: getDc(id.dc_id) });
|
|
800
|
+
}
|
|
670
801
|
async editInlineMessageText(inlineMessageId, text, params) {
|
|
671
|
-
await
|
|
802
|
+
await this.#editInlineMessageTextInner(inlineMessageId, text, params, false);
|
|
672
803
|
}
|
|
673
804
|
async editInlineMessageCaption(inlineMessageId, params) {
|
|
674
|
-
await
|
|
805
|
+
await this.#editInlineMessageTextInner(inlineMessageId, params?.caption ?? "", params);
|
|
806
|
+
}
|
|
807
|
+
async #resolveInputMediaInner(document, media, fileType, otherAttribs) {
|
|
808
|
+
let media_ = null;
|
|
809
|
+
const spoiler = "hasSpoiler" in media && media.hasSpoiler ? true : undefined;
|
|
810
|
+
if (typeof document === "string") {
|
|
811
|
+
const fileId = this.resolveFileId(document, fileType);
|
|
812
|
+
if (fileId != null) {
|
|
813
|
+
media_ = { _: "inputMediaDocument", id: { ...fileId, _: "inputDocument" }, spoiler, query: otherAttribs.find((v) => Api.is("documentAttributeSticker", v))?.alt || undefined };
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (media_ == null) {
|
|
817
|
+
if (typeof document === "string" && isHttpUrl(document)) {
|
|
818
|
+
media_ = { _: "inputMediaDocumentExternal", url: document, spoiler };
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
let mimeType;
|
|
822
|
+
const file = await this.#c.fileManager.upload(document, media, (name) => {
|
|
823
|
+
mimeType = media?.mimeType ?? contentType(name.split(".").slice(-1)[0]) ?? FALLBACK_MIME_TYPE;
|
|
824
|
+
if (name.endsWith(".tgs") && fileType == FileType.Document) {
|
|
825
|
+
name += "-";
|
|
826
|
+
}
|
|
827
|
+
return name;
|
|
828
|
+
});
|
|
829
|
+
if (Api.is("inputFileStoryDocument", file)) {
|
|
830
|
+
unreachable();
|
|
831
|
+
}
|
|
832
|
+
let thumb = undefined;
|
|
833
|
+
if ("thumbnail" in media && media.thumbnail) {
|
|
834
|
+
thumb = await this.#c.fileManager.upload(media.thumbnail, { chunkSize: media?.chunkSize, signal: media?.signal });
|
|
835
|
+
}
|
|
836
|
+
media_ = { _: "inputMediaUploadedDocument", file, thumb, spoiler, attributes: [{ _: "documentAttributeFilename", file_name: file.name }, ...otherAttribs], mime_type: mimeType, force_file: fileType == FileType.Document ? true : undefined };
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return media_;
|
|
840
|
+
}
|
|
841
|
+
async #resolveInputMedia(media) {
|
|
842
|
+
if ("animation" in media) {
|
|
843
|
+
return await this.#resolveInputMediaInner(media.animation, media, FileType.Animation, [
|
|
844
|
+
{ _: "documentAttributeAnimated" },
|
|
845
|
+
{ _: "documentAttributeVideo", supports_streaming: true, w: media?.width ?? 0, h: media?.height ?? 0, duration: media?.duration ?? 0 },
|
|
846
|
+
]);
|
|
847
|
+
}
|
|
848
|
+
else if ("audio" in media) {
|
|
849
|
+
return await this.#resolveInputMediaInner(media.audio, media, FileType.Audio, [
|
|
850
|
+
{ _: "documentAttributeAudio", duration: media?.duration ?? 0, performer: media?.performer, title: media?.title },
|
|
851
|
+
]);
|
|
852
|
+
}
|
|
853
|
+
else if ("document" in media) {
|
|
854
|
+
return await this.#resolveInputMediaInner(media.document, media, FileType.Document, []);
|
|
855
|
+
}
|
|
856
|
+
else if ("photo" in media) {
|
|
857
|
+
let media_ = null;
|
|
858
|
+
const spoiler = media.hasSpoiler ? true : undefined;
|
|
859
|
+
const ttl_seconds = "selfDestruct" in media && media.selfDestruct !== undefined ? selfDestructOptionToInt(media.selfDestruct) : undefined;
|
|
860
|
+
if (typeof media.photo === "string") {
|
|
861
|
+
const fileId = this.resolveFileId(media.photo, [FileType.Photo, FileType.ProfilePhoto]);
|
|
862
|
+
if (fileId != null) {
|
|
863
|
+
media_ = { _: "inputMediaPhoto", id: { ...fileId, _: "inputPhoto" }, spoiler, ttl_seconds };
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
if (media_ == null) {
|
|
867
|
+
if (typeof media.photo === "string" && isHttpUrl(media.photo)) {
|
|
868
|
+
media_ = { _: "inputMediaPhotoExternal", url: media.photo, spoiler };
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
const file = await this.#c.fileManager.upload(media.photo, media, null, false);
|
|
872
|
+
media_ = { _: "inputMediaUploadedPhoto", file, spoiler, ttl_seconds };
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return media_;
|
|
876
|
+
}
|
|
877
|
+
else if ("video" in media) {
|
|
878
|
+
const ttl_seconds = "selfDestruct" in media && media.selfDestruct !== undefined ? selfDestructOptionToInt(media.selfDestruct) : undefined;
|
|
879
|
+
const media_ = await this.#resolveInputMediaInner(media.video, media, FileType.Video, [
|
|
880
|
+
{ _: "documentAttributeVideo", supports_streaming: media?.supportsStreaming ? true : undefined, w: media?.width ?? 0, h: media?.height ?? 0, duration: media?.duration ?? 0 },
|
|
881
|
+
]);
|
|
882
|
+
media_.ttl_seconds = ttl_seconds;
|
|
883
|
+
return media_;
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
unreachable();
|
|
887
|
+
}
|
|
675
888
|
}
|
|
676
889
|
async editMessageMedia(chatId, messageId, media, params) {
|
|
677
|
-
|
|
890
|
+
this.#checkParams(params);
|
|
678
891
|
const message = await this.getMessage(chatId, messageId);
|
|
679
892
|
if (!message) {
|
|
680
893
|
throw new InputError("Message not found.");
|
|
@@ -683,12 +896,12 @@ export class MessageManager {
|
|
|
683
896
|
throw new InputError("Unexpected message type.");
|
|
684
897
|
}
|
|
685
898
|
const [text, entities] = media.caption !== undefined ? await this.parseText(media.caption, { entities: media.captionEntities, parseMode: media.parseMode }) : ["", []];
|
|
686
|
-
const result = await
|
|
899
|
+
const result = await this.#c.invoke({
|
|
687
900
|
_: "messages.editMessage",
|
|
688
|
-
peer: await
|
|
901
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
689
902
|
id: messageId,
|
|
690
|
-
media: await
|
|
691
|
-
reply_markup: await
|
|
903
|
+
media: await this.#resolveInputMedia(media),
|
|
904
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
692
905
|
message: text,
|
|
693
906
|
entities,
|
|
694
907
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
@@ -696,66 +909,69 @@ export class MessageManager {
|
|
|
696
909
|
return message_;
|
|
697
910
|
}
|
|
698
911
|
async editInlineMessageMedia(inlineMessageId, media, params) {
|
|
699
|
-
|
|
700
|
-
|
|
912
|
+
this.#checkParams(params);
|
|
913
|
+
this.#c.storage.assertBot("editInlineMessageMedia");
|
|
701
914
|
const id = await deserializeInlineMessageId(inlineMessageId);
|
|
702
|
-
await
|
|
915
|
+
await this.#c.invoke({
|
|
703
916
|
_: "messages.editInlineBotMessage",
|
|
704
917
|
id,
|
|
705
|
-
media: await
|
|
706
|
-
reply_markup: await
|
|
918
|
+
media: await this.#resolveInputMedia(media),
|
|
919
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
707
920
|
}, { dc: getDc(id.dc_id) });
|
|
708
921
|
}
|
|
709
922
|
async deleteMessages(chatId, messageIds, params) {
|
|
710
923
|
checkArray(messageIds, checkMessageId);
|
|
711
|
-
const peer = await
|
|
924
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
712
925
|
if (canBeInputChannel(peer)) {
|
|
713
|
-
await
|
|
926
|
+
await this.#c.invoke({ _: "channels.deleteMessages", channel: toInputChannel(peer), id: messageIds });
|
|
714
927
|
}
|
|
715
928
|
else {
|
|
716
|
-
await
|
|
929
|
+
await this.#c.invoke({ _: "messages.deleteMessages", id: messageIds, revoke: params?.onlyForMe ? undefined : true });
|
|
717
930
|
}
|
|
718
931
|
}
|
|
719
932
|
async deleteScheduledMessages(chatId, messageIds) {
|
|
720
|
-
|
|
933
|
+
this.#c.storage.assertUser("sendScheduledMessage");
|
|
721
934
|
checkArray(messageIds, checkMessageId);
|
|
722
|
-
const peer = await
|
|
723
|
-
await
|
|
935
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
936
|
+
await this.#c.invoke({ _: "messages.deleteScheduledMessages", peer, id: messageIds });
|
|
724
937
|
}
|
|
725
938
|
async deleteScheduledMessage(chatId, messageId) {
|
|
726
|
-
|
|
939
|
+
this.#c.storage.assertUser("deleteScheduledMessage");
|
|
727
940
|
return await this.deleteScheduledMessages(chatId, [messageId]);
|
|
728
941
|
}
|
|
729
942
|
async sendScheduledMessages(chatId, messageIds) {
|
|
730
|
-
|
|
943
|
+
this.#c.storage.assertUser("sendScheduledMessages");
|
|
731
944
|
checkArray(messageIds, checkMessageId);
|
|
732
|
-
const peer = await
|
|
733
|
-
const result = await
|
|
945
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
946
|
+
const result = await this.#c.invoke({ _: "messages.sendScheduledMessages", peer, id: messageIds });
|
|
734
947
|
return await this.updatesToMessages(chatId, result);
|
|
735
948
|
}
|
|
736
949
|
async sendScheduledMessage(chatId, messageId) {
|
|
737
|
-
|
|
950
|
+
this.#c.storage.assertUser("sendScheduledMessage");
|
|
738
951
|
return (await this.sendScheduledMessages(chatId, [messageId]))[0];
|
|
739
952
|
}
|
|
740
953
|
async deleteChatMemberMessages(chatId, memberId) {
|
|
741
|
-
|
|
742
|
-
const channel = await
|
|
743
|
-
const participant = await
|
|
744
|
-
await
|
|
954
|
+
this.#c.storage.assertUser("deleteChatMemberMessages");
|
|
955
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
956
|
+
const participant = await this.#c.getInputPeer(memberId);
|
|
957
|
+
await this.#c.invoke({ _: "channels.deleteParticipantHistory", channel, participant });
|
|
745
958
|
}
|
|
746
959
|
async pinMessage(chatId, messageId, params) {
|
|
747
|
-
|
|
748
|
-
await
|
|
960
|
+
this.#checkParams(params);
|
|
961
|
+
await this.#c.invoke({ _: "messages.updatePinnedMessage", peer: await this.#c.getInputPeer(chatId), id: checkMessageId(messageId), silent: params?.disableNotification ? true : undefined, pm_oneside: params?.bothSides ? undefined : true });
|
|
749
962
|
}
|
|
750
963
|
async unpinMessage(chatId, messageId, params) {
|
|
751
|
-
|
|
752
|
-
await
|
|
964
|
+
this.#checkParams(params);
|
|
965
|
+
await this.#c.invoke({ _: "messages.updatePinnedMessage", peer: await this.#c.getInputPeer(chatId), id: checkMessageId(messageId), unpin: true }, { businessConnectionId: params?.businessConnectionId });
|
|
753
966
|
}
|
|
754
967
|
async unpinMessages(chatId) {
|
|
755
|
-
await
|
|
968
|
+
await this.#c.invoke({ _: "messages.unpinAllMessages", peer: await this.#c.getInputPeer(chatId) });
|
|
969
|
+
}
|
|
970
|
+
async #sendReaction(chatId, messageId, reactions, params) {
|
|
971
|
+
await this.#c.invoke({ _: "messages.sendReaction", peer: await this.#c.getInputPeer(chatId), msg_id: checkMessageId(messageId), reaction: reactions.map((v) => reactionToTlObject(v)), big: params?.big ? true : undefined, add_to_recent: params?.addToRecents ? true : undefined });
|
|
756
972
|
}
|
|
757
973
|
async setReactions(chatId, messageId, reactions, params) {
|
|
758
|
-
await
|
|
974
|
+
await this.#sendReaction(chatId, messageId, reactions, params);
|
|
759
975
|
}
|
|
760
976
|
async addReaction(chatId, messageId, reaction, params) {
|
|
761
977
|
const message = await this.getMessage(chatId, messageId);
|
|
@@ -792,7 +1008,7 @@ export class MessageManager {
|
|
|
792
1008
|
if (Api.is("updateNewMessage", update) || Api.is("updateNewChannelMessage", update) || Api.is("updateEditMessage", update) || Api.is("updateEditChannelMessage", update)) {
|
|
793
1009
|
if (Api.is("message", update.message) || Api.is("messageService", update.message)) {
|
|
794
1010
|
const chatId = Api.peerToChatId(update.message.peer_id);
|
|
795
|
-
await
|
|
1011
|
+
await this.#c.messageStorage.setMessage(chatId, update.message.id, update.message);
|
|
796
1012
|
}
|
|
797
1013
|
}
|
|
798
1014
|
if (Api.isOneOf([
|
|
@@ -808,13 +1024,13 @@ export class MessageManager {
|
|
|
808
1024
|
const isOutgoing = update.message.out;
|
|
809
1025
|
let shouldIgnore = false;
|
|
810
1026
|
if (isOutgoing) {
|
|
811
|
-
if (
|
|
812
|
-
|
|
1027
|
+
if (this.#c.outgoingMessages == null) {
|
|
1028
|
+
this.#c.outgoingMessages = this.#c.storage.accountType == "user" ? "all" : "business";
|
|
813
1029
|
}
|
|
814
|
-
if (
|
|
1030
|
+
if (this.#c.outgoingMessages == "none") {
|
|
815
1031
|
shouldIgnore = true;
|
|
816
1032
|
}
|
|
817
|
-
else if (
|
|
1033
|
+
else if (this.#c.outgoingMessages == "business") {
|
|
818
1034
|
if (!Api.is("updateBotNewBusinessMessage", update) && !Api.is("updateBotEditBusinessMessage", update)) {
|
|
819
1035
|
shouldIgnore = true;
|
|
820
1036
|
}
|
|
@@ -839,7 +1055,7 @@ export class MessageManager {
|
|
|
839
1055
|
if (Api.is("updateDeleteMessages", update)) {
|
|
840
1056
|
const deletedMessages = new Array();
|
|
841
1057
|
for (const messageId of update.messages) {
|
|
842
|
-
const chatId = await
|
|
1058
|
+
const chatId = await this.#c.messageStorage.getMessageChat(messageId);
|
|
843
1059
|
if (chatId) {
|
|
844
1060
|
deletedMessages.push({ chatId, messageId });
|
|
845
1061
|
}
|
|
@@ -852,7 +1068,7 @@ export class MessageManager {
|
|
|
852
1068
|
const chatId = Api.getChannelChatId(update.channel_id);
|
|
853
1069
|
const deletedMessages = new Array();
|
|
854
1070
|
for (const messageId of update.messages) {
|
|
855
|
-
const message = await
|
|
1071
|
+
const message = await this.#c.messageStorage.getMessage(chatId, messageId);
|
|
856
1072
|
if (message != null) {
|
|
857
1073
|
deletedMessages.push({ chatId, messageId });
|
|
858
1074
|
}
|
|
@@ -871,13 +1087,13 @@ export class MessageManager {
|
|
|
871
1087
|
}
|
|
872
1088
|
if (Api.is("updateTranscribedAudio", update)) {
|
|
873
1089
|
const voiceTranscription = constructVoiceTranscription(update);
|
|
874
|
-
await
|
|
1090
|
+
await this.#c.messageStorage.setVoiceTranscription(voiceTranscription);
|
|
875
1091
|
return { voiceTranscription };
|
|
876
1092
|
}
|
|
877
1093
|
return null;
|
|
878
1094
|
}
|
|
879
1095
|
async sendChatAction(chatId, action, params) {
|
|
880
|
-
|
|
1096
|
+
this.#checkParams(params);
|
|
881
1097
|
let action_;
|
|
882
1098
|
switch (action) {
|
|
883
1099
|
case "type":
|
|
@@ -916,11 +1132,11 @@ export class MessageManager {
|
|
|
916
1132
|
default:
|
|
917
1133
|
throw new InputError(`Invalid chat action: ${action}`);
|
|
918
1134
|
}
|
|
919
|
-
await
|
|
1135
|
+
await this.#c.invoke({ _: "messages.setTyping", peer: await this.#c.getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId }, { businessConnectionId: params?.businessConnectionId });
|
|
920
1136
|
}
|
|
921
1137
|
async searchMessages(chatId, query, params) {
|
|
922
|
-
|
|
923
|
-
const result = await
|
|
1138
|
+
this.#c.storage.assertUser("searchMessages");
|
|
1139
|
+
const result = await this.#c.invoke({ _: "messages.search", peer: await this.#c.getInputPeer(chatId), q: query, add_offset: 0, filter: messageSearchFilterToTlObject(params?.filter ?? "empty"), hash: 0n, limit: getLimit(params?.limit), max_date: 0, max_id: 0, min_date: 0, min_id: 0, offset_id: params?.after ? params.after : 0, from_id: params?.from ? await this.#c.getInputPeer(params.from) : undefined });
|
|
924
1140
|
if (!("messages" in result)) {
|
|
925
1141
|
unreachable();
|
|
926
1142
|
}
|
|
@@ -932,25 +1148,25 @@ export class MessageManager {
|
|
|
932
1148
|
return messages;
|
|
933
1149
|
}
|
|
934
1150
|
async blockUser(userId) {
|
|
935
|
-
|
|
936
|
-
const id = await
|
|
937
|
-
await
|
|
1151
|
+
this.#c.storage.assertUser("blockUser");
|
|
1152
|
+
const id = await this.#c.getInputPeer(userId);
|
|
1153
|
+
await this.#c.invoke({ _: "contacts.block", id });
|
|
938
1154
|
}
|
|
939
1155
|
async unblockUser(userId) {
|
|
940
|
-
|
|
941
|
-
const id = await
|
|
942
|
-
await
|
|
1156
|
+
this.#c.storage.assertUser("unblockUser");
|
|
1157
|
+
const id = await this.#c.getInputPeer(userId);
|
|
1158
|
+
await this.#c.invoke({ _: "contacts.unblock", id });
|
|
943
1159
|
}
|
|
944
1160
|
async setChatStickerSet(chatId, setName) {
|
|
945
|
-
const channel = await
|
|
946
|
-
await
|
|
1161
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
1162
|
+
await this.#c.invoke({ _: "channels.setStickers", channel, stickerset: { _: "inputStickerSetShortName", short_name: setName } });
|
|
947
1163
|
}
|
|
948
1164
|
async deleteChatStickerSet(chatId) {
|
|
949
|
-
const channel = await
|
|
950
|
-
await
|
|
1165
|
+
const channel = await this.#c.getInputChannel(chatId);
|
|
1166
|
+
await this.#c.invoke({ _: "channels.setStickers", channel, stickerset: { _: "inputStickerSetEmpty" } });
|
|
951
1167
|
}
|
|
952
1168
|
async stopPoll(chatId, messageId, params) {
|
|
953
|
-
|
|
1169
|
+
this.#checkParams(params);
|
|
954
1170
|
const message = await this.getMessage(chatId, messageId);
|
|
955
1171
|
if (!message) {
|
|
956
1172
|
throw new InputError("Message not found.");
|
|
@@ -961,26 +1177,26 @@ export class MessageManager {
|
|
|
961
1177
|
if (message.poll.isClosed) {
|
|
962
1178
|
throw new InputError("Poll is already stopped.");
|
|
963
1179
|
}
|
|
964
|
-
const result = await
|
|
1180
|
+
const result = await this.#c.invoke({
|
|
965
1181
|
_: "messages.editMessage",
|
|
966
|
-
peer: await
|
|
1182
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
967
1183
|
id: messageId,
|
|
968
1184
|
media: ({ _: "inputMediaPoll", poll: ({ _: "poll", id: BigInt(message.poll.id), closed: true, question: { _: "textWithEntities", text: "", entities: [] }, answers: [] }) }),
|
|
969
|
-
reply_markup: await
|
|
1185
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
970
1186
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
971
1187
|
const message_ = (await this.updatesToMessages(chatId, result))[0];
|
|
972
1188
|
return assertMessageType(message_, "poll").poll;
|
|
973
1189
|
}
|
|
974
1190
|
async editMessageLiveLocation(chatId, messageId, latitude, longitude, params) {
|
|
975
|
-
|
|
1191
|
+
this.#checkParams(params);
|
|
976
1192
|
const message = await this.getMessage(chatId, messageId);
|
|
977
1193
|
if (message && "location" in message && message.location.livePeriod) {
|
|
978
|
-
const result = await
|
|
1194
|
+
const result = await this.#c.invoke({
|
|
979
1195
|
_: "messages.editMessage",
|
|
980
|
-
peer: await
|
|
1196
|
+
peer: await this.#c.getInputPeer(chatId),
|
|
981
1197
|
id: messageId,
|
|
982
1198
|
media: ({ _: "inputMediaGeoLive", geo_point: ({ _: "inputGeoPoint", lat: latitude, long: longitude, accuracy_radius: params?.horizontalAccuracy }), heading: params?.heading, proximity_notification_radius: params?.proximityAlertRadius }),
|
|
983
|
-
reply_markup: await
|
|
1199
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
984
1200
|
}, { businessConnectionId: params?.businessConnectionId });
|
|
985
1201
|
const message = (await this.updatesToMessages(chatId, result))[0];
|
|
986
1202
|
return assertMessageType(message, "location");
|
|
@@ -988,19 +1204,19 @@ export class MessageManager {
|
|
|
988
1204
|
unreachable();
|
|
989
1205
|
}
|
|
990
1206
|
async editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params) {
|
|
991
|
-
|
|
992
|
-
|
|
1207
|
+
this.#checkParams(params);
|
|
1208
|
+
this.#c.storage.assertBot("editInlineMessageLiveLocation");
|
|
993
1209
|
const id = await deserializeInlineMessageId(inlineMessageId);
|
|
994
|
-
await
|
|
1210
|
+
await this.#c.invoke({
|
|
995
1211
|
_: "messages.editInlineBotMessage",
|
|
996
1212
|
id,
|
|
997
1213
|
media: ({ _: "inputMediaGeoLive", geo_point: ({ _: "inputGeoPoint", lat: latitude, long: longitude, accuracy_radius: params?.horizontalAccuracy }), heading: params?.heading, proximity_notification_radius: params?.proximityAlertRadius }),
|
|
998
|
-
reply_markup: await
|
|
1214
|
+
reply_markup: await this.#constructReplyMarkup(params),
|
|
999
1215
|
}, { dc: getDc(id.dc_id) });
|
|
1000
1216
|
}
|
|
1001
1217
|
async sendInvoice(chatId, title, description, payload, currency, prices, params) {
|
|
1002
|
-
|
|
1003
|
-
|
|
1218
|
+
this.#c.storage.assertBot("sendInvoice");
|
|
1219
|
+
this.#checkParams(params);
|
|
1004
1220
|
if (title.length < 1) {
|
|
1005
1221
|
throw new InputError("Invoice title cannot be empty.");
|
|
1006
1222
|
}
|
|
@@ -1027,7 +1243,7 @@ export class MessageManager {
|
|
|
1027
1243
|
phone_to_provider: params?.sendPhoneNumberToProvider || undefined,
|
|
1028
1244
|
flexible: params?.flexible || undefined,
|
|
1029
1245
|
};
|
|
1030
|
-
const message = await
|
|
1246
|
+
const message = await this.#sendMedia(chatId, {
|
|
1031
1247
|
_: "inputMediaInvoice",
|
|
1032
1248
|
title,
|
|
1033
1249
|
description,
|
|
@@ -1053,7 +1269,7 @@ export class MessageManager {
|
|
|
1053
1269
|
return assertMessageType(message, "invoice");
|
|
1054
1270
|
}
|
|
1055
1271
|
async sendMediaGroup(chatId, media, params) {
|
|
1056
|
-
|
|
1272
|
+
this.#checkParams(params);
|
|
1057
1273
|
{
|
|
1058
1274
|
if (!Array.isArray(media) || !media.length) {
|
|
1059
1275
|
throw new InputError("Media group must not be empty.");
|
|
@@ -1079,25 +1295,25 @@ export class MessageManager {
|
|
|
1079
1295
|
for (const v of media) {
|
|
1080
1296
|
const randomId = getRandomId();
|
|
1081
1297
|
const [message, entities] = v.caption !== undefined ? await this.parseText(v.caption, { entities: v.captionEntities, parseMode: v.parseMode }) : ["", []];
|
|
1082
|
-
multiMedia.push({ _: "inputSingleMedia", message, entities, random_id: randomId, media: await
|
|
1298
|
+
multiMedia.push({ _: "inputSingleMedia", message, entities, random_id: randomId, media: await this.#resolveInputMedia(v) });
|
|
1083
1299
|
}
|
|
1084
|
-
const peer = await
|
|
1300
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1085
1301
|
for (const [i, media_] of multiMedia.entries()) {
|
|
1086
1302
|
if (Api.is("inputMediaUploadedPhoto", media_.media)) {
|
|
1087
|
-
const result = Api.as("messageMediaPhoto", await
|
|
1303
|
+
const result = Api.as("messageMediaPhoto", await this.#c.invoke({ _: "messages.uploadMedia", media: media_.media, peer }));
|
|
1088
1304
|
const photo = Api.as("photo", result.photo);
|
|
1089
1305
|
multiMedia[i] = { ...media_, media: { _: "inputMediaPhoto", id: { ...photo, _: "inputPhoto" } } };
|
|
1090
1306
|
}
|
|
1091
1307
|
else if (Api.is("inputMediaUploadedDocument", media_.media)) {
|
|
1092
|
-
const result = Api.as("messageMediaDocument", await
|
|
1308
|
+
const result = Api.as("messageMediaDocument", await this.#c.invoke({ _: "messages.uploadMedia", media: media_.media, peer }));
|
|
1093
1309
|
const document = Api.as("document", result.document);
|
|
1094
1310
|
multiMedia[i] = { ...media_, media: { _: "inputMediaDocument", id: { ...document, _: "inputDocument" } } };
|
|
1095
1311
|
}
|
|
1096
1312
|
}
|
|
1097
1313
|
const silent = params?.disableNotification ? true : undefined;
|
|
1098
1314
|
const noforwards = params?.protectContent ? true : undefined;
|
|
1099
|
-
const sendAs = params?.sendAs ? await
|
|
1100
|
-
const result = await
|
|
1315
|
+
const sendAs = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
1316
|
+
const result = await this.#c.invoke({
|
|
1101
1317
|
_: "messages.sendMultiMedia",
|
|
1102
1318
|
peer,
|
|
1103
1319
|
multi_media: multiMedia,
|
|
@@ -1105,19 +1321,19 @@ export class MessageManager {
|
|
|
1105
1321
|
noforwards,
|
|
1106
1322
|
silent,
|
|
1107
1323
|
send_as: sendAs,
|
|
1108
|
-
reply_to: await
|
|
1324
|
+
reply_to: await this.#constructReplyTo(params),
|
|
1109
1325
|
allow_paid_floodskip: params?.paidBroadcast ? true : undefined,
|
|
1110
1326
|
});
|
|
1111
1327
|
return await this.updatesToMessages(chatId, result);
|
|
1112
1328
|
}
|
|
1113
1329
|
async readMessages(chatId, untilMessageId) {
|
|
1114
|
-
|
|
1115
|
-
const peer = await
|
|
1330
|
+
this.#c.storage.assertUser("readMessages");
|
|
1331
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1116
1332
|
const max_id = untilMessageId;
|
|
1117
|
-
await
|
|
1333
|
+
await this.#c.invoke({ _: "messages.readHistory", peer, max_id });
|
|
1118
1334
|
}
|
|
1119
1335
|
async startBot(botId, params) {
|
|
1120
|
-
|
|
1336
|
+
this.#c.storage.assertUser("startBot");
|
|
1121
1337
|
const start_param = params?.deeplink?.trim() || "";
|
|
1122
1338
|
if (params?.chatId !== undefined && !start_param) {
|
|
1123
1339
|
throw new InputError("deeplink cannot be unspecified while chatId is specified.");
|
|
@@ -1125,13 +1341,13 @@ export class MessageManager {
|
|
|
1125
1341
|
if (!params?.deeplink) {
|
|
1126
1342
|
return await this.sendMessage(botId, "/start");
|
|
1127
1343
|
}
|
|
1128
|
-
const bot = await
|
|
1129
|
-
const peer = await
|
|
1130
|
-
const result = await
|
|
1344
|
+
const bot = await this.#c.getInputUser(botId);
|
|
1345
|
+
const peer = await this.#c.getInputPeer(params?.chatId || botId);
|
|
1346
|
+
const result = await this.#c.invoke({ _: "messages.startBot", bot, peer, random_id: getRandomId(), start_param });
|
|
1131
1347
|
return (await this.updatesToMessages(botId, result))[0];
|
|
1132
1348
|
}
|
|
1133
1349
|
async transcribeVoice(chatId, messageId) {
|
|
1134
|
-
|
|
1350
|
+
this.#c.storage.assertUser("transcribeVoice");
|
|
1135
1351
|
const message = await this.getMessage(chatId, messageId);
|
|
1136
1352
|
if (message == null) {
|
|
1137
1353
|
throw new InputError("Message not found.");
|
|
@@ -1139,16 +1355,32 @@ export class MessageManager {
|
|
|
1139
1355
|
if (!isMessageType(message, "voice")) {
|
|
1140
1356
|
throw new InputError("Message not voice.");
|
|
1141
1357
|
}
|
|
1142
|
-
const cachedTranscription = await
|
|
1358
|
+
const cachedTranscription = await this.#getCachedVoiceTranscription(message);
|
|
1143
1359
|
if (cachedTranscription) {
|
|
1144
1360
|
return cachedTranscription;
|
|
1145
1361
|
}
|
|
1146
|
-
const peer = await
|
|
1147
|
-
const result = await
|
|
1148
|
-
return await
|
|
1362
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1363
|
+
const result = await this.#c.invoke({ _: "messages.transcribeAudio", peer, msg_id: messageId });
|
|
1364
|
+
return await this.#cacheVoiceTranscription(message, constructVoiceTranscription(result));
|
|
1365
|
+
}
|
|
1366
|
+
async #getCachedVoiceTranscription(message) {
|
|
1367
|
+
const reference = await this.#c.messageStorage.getVoiceTranscriptionReference(message.chat.id, message.id, fromUnixTimestamp(message.editDate ?? message.date));
|
|
1368
|
+
if (!reference) {
|
|
1369
|
+
return null;
|
|
1370
|
+
}
|
|
1371
|
+
const voiceTranscription = await this.#c.messageStorage.getVoiceTranscription(reference);
|
|
1372
|
+
if (!voiceTranscription || !voiceTranscription.done) {
|
|
1373
|
+
return null;
|
|
1374
|
+
}
|
|
1375
|
+
return voiceTranscription;
|
|
1376
|
+
}
|
|
1377
|
+
async #cacheVoiceTranscription(message, voiceTranscription) {
|
|
1378
|
+
await this.#c.messageStorage.setVoiceTranscriptionReference(message.chat.id, message.id, fromUnixTimestamp(message.editDate ?? message.date), BigInt(voiceTranscription.id));
|
|
1379
|
+
await this.#c.messageStorage.setVoiceTranscription(voiceTranscription);
|
|
1380
|
+
return voiceTranscription;
|
|
1149
1381
|
}
|
|
1150
1382
|
async resolveMessageLink(link) {
|
|
1151
|
-
const parseResult =
|
|
1383
|
+
const parseResult = MessageManager.parseMessageLink(link);
|
|
1152
1384
|
if (parseResult == null) {
|
|
1153
1385
|
throw new InputError("Invalid messsage link.");
|
|
1154
1386
|
}
|
|
@@ -1235,20 +1467,20 @@ export class MessageManager {
|
|
|
1235
1467
|
return [peer, id];
|
|
1236
1468
|
}
|
|
1237
1469
|
async openMiniApp(botId, chatId, params) {
|
|
1238
|
-
|
|
1470
|
+
this.#c.storage.assertUser("openMiniApp");
|
|
1239
1471
|
const from_bot_menu = params?.fromMenu ? true : undefined;
|
|
1240
1472
|
const silent = params?.disableNotification ? true : undefined;
|
|
1241
1473
|
const compact = params?.mode === "compact" ? true : undefined;
|
|
1242
1474
|
const fullscreen = params?.mode === "fullscreen" ? true : undefined;
|
|
1243
|
-
const peer = await
|
|
1244
|
-
const bot = await
|
|
1475
|
+
const peer = await this.#c.getInputPeer(chatId);
|
|
1476
|
+
const bot = await this.#c.getInputUser(botId);
|
|
1245
1477
|
const url = params?.url;
|
|
1246
1478
|
const start_param = params?.startParameter;
|
|
1247
1479
|
const theme_params = params?.themeParameters ? { _: "dataJSON", data: params.themeParameters } : undefined;
|
|
1248
|
-
const platform =
|
|
1249
|
-
const reply_to = await
|
|
1250
|
-
const send_as = params?.sendAs ? await
|
|
1251
|
-
const result = await
|
|
1480
|
+
const platform = this.#c.langPack ?? "";
|
|
1481
|
+
const reply_to = await this.#constructReplyTo(params);
|
|
1482
|
+
const send_as = params?.sendAs ? await this.#c.getInputPeer(params.sendAs) : undefined;
|
|
1483
|
+
const result = await this.#c.invoke({
|
|
1252
1484
|
_: "messages.requestWebView",
|
|
1253
1485
|
from_bot_menu,
|
|
1254
1486
|
silent,
|
|
@@ -1266,242 +1498,3 @@ export class MessageManager {
|
|
|
1266
1498
|
return constructMiniAppInfo(result);
|
|
1267
1499
|
}
|
|
1268
1500
|
}
|
|
1269
|
-
_a = MessageManager, _MessageManager_c = new WeakMap(), _MessageManager_LresolveFileId = new WeakMap(), _MessageManager_instances = new WeakSet(), _MessageManager_checkParams = function _MessageManager_checkParams(params) {
|
|
1270
|
-
if (params && "replyMarkup" in params && params.replyMarkup !== undefined) {
|
|
1271
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertBot("replyMarkup");
|
|
1272
|
-
}
|
|
1273
|
-
if (params && "businessConnectionId" in params && params.businessConnectionId !== undefined) {
|
|
1274
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertBot("businessConnectionId");
|
|
1275
|
-
}
|
|
1276
|
-
if (params && "sendAs" in params && params.sendAs !== undefined) {
|
|
1277
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("sendAs");
|
|
1278
|
-
}
|
|
1279
|
-
if (params && "sendAt" in params && params.sendAt !== undefined) {
|
|
1280
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("businessConsendAtnectionId");
|
|
1281
|
-
}
|
|
1282
|
-
}, _MessageManager_constructReplyMarkup = async function _MessageManager_constructReplyMarkup(params) {
|
|
1283
|
-
if (params?.replyMarkup) {
|
|
1284
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertBot("replyMarkup");
|
|
1285
|
-
return await replyMarkupToTlObject(params.replyMarkup, this.usernameResolver.bind(this));
|
|
1286
|
-
}
|
|
1287
|
-
}, _MessageManager_resolveSendAs = async function _MessageManager_resolveSendAs(params) {
|
|
1288
|
-
const sendAs = params?.sendAs;
|
|
1289
|
-
if (sendAs !== undefined) {
|
|
1290
|
-
__classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("sendAs");
|
|
1291
|
-
return sendAs ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(sendAs) : undefined;
|
|
1292
|
-
}
|
|
1293
|
-
}, _MessageManager_constructReplyTo = async function _MessageManager_constructReplyTo(params) {
|
|
1294
|
-
const topMsgId = params?.messageThreadId;
|
|
1295
|
-
if (!params?.replyTo) {
|
|
1296
|
-
if (topMsgId) {
|
|
1297
|
-
return { _: "inputReplyToMessage", reply_to_msg_id: topMsgId };
|
|
1298
|
-
}
|
|
1299
|
-
else {
|
|
1300
|
-
return undefined;
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
if ("messageId" in params.replyTo) {
|
|
1304
|
-
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) => messageEntityToTlObject(v, __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity)) ?? []), quote_offset: params.replyTo.quote?.offset };
|
|
1305
|
-
}
|
|
1306
|
-
else {
|
|
1307
|
-
return { _: "inputReplyToStory", peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(params.replyTo.chatId), story_id: params.replyTo.storyId };
|
|
1308
|
-
}
|
|
1309
|
-
}, _MessageManager_sendDocumentInner = async function _MessageManager_sendDocumentInner(chatId, document, params, fileType, otherAttribs, urlSupported = true, expectedMimeTypes) {
|
|
1310
|
-
let media = null;
|
|
1311
|
-
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
1312
|
-
const ttl_seconds = params && "selfDestruct" in params && typeof params.selfDestruct !== undefined ? selfDestructOptionToInt(params.selfDestruct) : undefined;
|
|
1313
|
-
if (typeof document === "string") {
|
|
1314
|
-
const fileId = this.resolveFileId(document, fileType);
|
|
1315
|
-
if (fileId != null) {
|
|
1316
|
-
media = { _: "inputMediaDocument", id: { ...fileId, _: "inputDocument" }, spoiler, query: otherAttribs.find((v) => Api.is("documentAttributeSticker", v))?.alt || undefined, ttl_seconds };
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
if (media == null) {
|
|
1320
|
-
if (typeof document === "string" && isHttpUrl(document)) {
|
|
1321
|
-
if (!urlSupported) {
|
|
1322
|
-
throw new InputError("URL not supported.");
|
|
1323
|
-
}
|
|
1324
|
-
media = { _: "inputMediaDocumentExternal", url: document, spoiler, ttl_seconds };
|
|
1325
|
-
}
|
|
1326
|
-
else {
|
|
1327
|
-
let mimeType;
|
|
1328
|
-
const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(document, params, (name) => {
|
|
1329
|
-
mimeType = params?.mimeType ?? contentType(name.split(".").slice(-1)[0]) ?? FALLBACK_MIME_TYPE;
|
|
1330
|
-
if (expectedMimeTypes && !expectedMimeTypes.includes(mimeType)) {
|
|
1331
|
-
unreachable();
|
|
1332
|
-
}
|
|
1333
|
-
if (name.endsWith(".tgs") && fileType == FileType.Document) {
|
|
1334
|
-
name += "-";
|
|
1335
|
-
}
|
|
1336
|
-
return name;
|
|
1337
|
-
});
|
|
1338
|
-
if (Api.is("inputFileStoryDocument", file)) {
|
|
1339
|
-
unreachable();
|
|
1340
|
-
}
|
|
1341
|
-
let thumb = undefined;
|
|
1342
|
-
if (params?.thumbnail) {
|
|
1343
|
-
thumb = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(params.thumbnail, { chunkSize: params?.chunkSize, signal: params?.signal });
|
|
1344
|
-
}
|
|
1345
|
-
media = { _: "inputMediaUploadedDocument", file, thumb, spoiler, attributes: [{ _: "documentAttributeFilename", file_name: file.name }, ...otherAttribs], mime_type: mimeType, force_file: fileType == FileType.Document ? true : undefined, ttl_seconds };
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
const message = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_sendMedia).call(this, chatId, media, params);
|
|
1349
|
-
return message;
|
|
1350
|
-
}, _MessageManager_sendMedia = async function _MessageManager_sendMedia(chatId, media, params) {
|
|
1351
|
-
if (params?.starCount !== undefined) {
|
|
1352
|
-
if (params.starCount <= 0) {
|
|
1353
|
-
throw new InputError("starCount cannot be zero or negative");
|
|
1354
|
-
}
|
|
1355
|
-
media = { _: "inputMediaPaidMedia", stars_amount: BigInt(params.starCount), extended_media: [media] };
|
|
1356
|
-
}
|
|
1357
|
-
const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
1358
|
-
const randomId = getRandomId();
|
|
1359
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
1360
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
1361
|
-
const sendAs = params?.sendAs ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(params.sendAs) : undefined;
|
|
1362
|
-
const replyMarkup = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params);
|
|
1363
|
-
const caption_ = params?.caption;
|
|
1364
|
-
const parseResult = caption_ !== undefined ? await this.parseText(caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
1365
|
-
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
1366
|
-
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
1367
|
-
const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").invoke({
|
|
1368
|
-
_: "messages.sendMedia",
|
|
1369
|
-
peer,
|
|
1370
|
-
random_id: randomId,
|
|
1371
|
-
silent,
|
|
1372
|
-
noforwards,
|
|
1373
|
-
reply_markup: replyMarkup,
|
|
1374
|
-
reply_to: await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyTo).call(this, params),
|
|
1375
|
-
send_as: sendAs,
|
|
1376
|
-
media,
|
|
1377
|
-
message: caption ?? "",
|
|
1378
|
-
entities: captionEntities,
|
|
1379
|
-
effect: params?.effectId ? BigInt(params.effectId) : undefined,
|
|
1380
|
-
schedule_date: params?.sendAt,
|
|
1381
|
-
allow_paid_floodskip: params?.paidBroadcast ? true : undefined,
|
|
1382
|
-
}, { businessConnectionId: params?.businessConnectionId });
|
|
1383
|
-
return (await this.updatesToMessages(chatId, result, params?.businessConnectionId))[0];
|
|
1384
|
-
}, _MessageManager_editInlineMessageTextInner = async function _MessageManager_editInlineMessageTextInner(inlineMessageId, text, params, allowEmpty = true) {
|
|
1385
|
-
__classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_checkParams).call(this, params);
|
|
1386
|
-
const [message, entities] = await this.parseText(text, params);
|
|
1387
|
-
if (!allowEmpty && !message) {
|
|
1388
|
-
throw new InputError("Message text cannot be empty.");
|
|
1389
|
-
}
|
|
1390
|
-
const id = await deserializeInlineMessageId(inlineMessageId);
|
|
1391
|
-
if (params?.linkPreview && params.linkPreview.type != "input") {
|
|
1392
|
-
throw new InputError("Expected link preview of type input.");
|
|
1393
|
-
}
|
|
1394
|
-
const noWebpage = params?.linkPreview && params.linkPreview.type == "input" && params.linkPreview.disable ? true : undefined;
|
|
1395
|
-
const invertMedia = params?.linkPreview?.aboveText ? true : undefined;
|
|
1396
|
-
let media = undefined;
|
|
1397
|
-
if (!noWebpage && params?.linkPreview?.url) {
|
|
1398
|
-
media = { _: "inputMediaWebPage", url: params.linkPreview.url, force_large_media: params.linkPreview.largeMedia ? true : undefined, force_small_media: params.linkPreview.smallMedia ? true : undefined, optional: message.length ? undefined : true };
|
|
1399
|
-
}
|
|
1400
|
-
await __classPrivateFieldGet(this, _MessageManager_c, "f").invoke({
|
|
1401
|
-
_: "messages.editInlineBotMessage",
|
|
1402
|
-
id,
|
|
1403
|
-
entities,
|
|
1404
|
-
message,
|
|
1405
|
-
media,
|
|
1406
|
-
no_webpage: noWebpage,
|
|
1407
|
-
invert_media: invertMedia,
|
|
1408
|
-
reply_markup: await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params),
|
|
1409
|
-
}, { dc: getDc(id.dc_id) });
|
|
1410
|
-
}, _MessageManager_resolveInputMediaInner = async function _MessageManager_resolveInputMediaInner(document, media, fileType, otherAttribs) {
|
|
1411
|
-
let media_ = null;
|
|
1412
|
-
const spoiler = "hasSpoiler" in media && media.hasSpoiler ? true : undefined;
|
|
1413
|
-
if (typeof document === "string") {
|
|
1414
|
-
const fileId = this.resolveFileId(document, fileType);
|
|
1415
|
-
if (fileId != null) {
|
|
1416
|
-
media_ = { _: "inputMediaDocument", id: { ...fileId, _: "inputDocument" }, spoiler, query: otherAttribs.find((v) => Api.is("documentAttributeSticker", v))?.alt || undefined };
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
if (media_ == null) {
|
|
1420
|
-
if (typeof document === "string" && isHttpUrl(document)) {
|
|
1421
|
-
media_ = { _: "inputMediaDocumentExternal", url: document, spoiler };
|
|
1422
|
-
}
|
|
1423
|
-
else {
|
|
1424
|
-
let mimeType;
|
|
1425
|
-
const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(document, media, (name) => {
|
|
1426
|
-
mimeType = media?.mimeType ?? contentType(name.split(".").slice(-1)[0]) ?? FALLBACK_MIME_TYPE;
|
|
1427
|
-
if (name.endsWith(".tgs") && fileType == FileType.Document) {
|
|
1428
|
-
name += "-";
|
|
1429
|
-
}
|
|
1430
|
-
return name;
|
|
1431
|
-
});
|
|
1432
|
-
if (Api.is("inputFileStoryDocument", file)) {
|
|
1433
|
-
unreachable();
|
|
1434
|
-
}
|
|
1435
|
-
let thumb = undefined;
|
|
1436
|
-
if ("thumbnail" in media && media.thumbnail) {
|
|
1437
|
-
thumb = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(media.thumbnail, { chunkSize: media?.chunkSize, signal: media?.signal });
|
|
1438
|
-
}
|
|
1439
|
-
media_ = { _: "inputMediaUploadedDocument", file, thumb, spoiler, attributes: [{ _: "documentAttributeFilename", file_name: file.name }, ...otherAttribs], mime_type: mimeType, force_file: fileType == FileType.Document ? true : undefined };
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
return media_;
|
|
1443
|
-
}, _MessageManager_resolveInputMedia = async function _MessageManager_resolveInputMedia(media) {
|
|
1444
|
-
if ("animation" in media) {
|
|
1445
|
-
return await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_resolveInputMediaInner).call(this, media.animation, media, FileType.Animation, [
|
|
1446
|
-
{ _: "documentAttributeAnimated" },
|
|
1447
|
-
{ _: "documentAttributeVideo", supports_streaming: true, w: media?.width ?? 0, h: media?.height ?? 0, duration: media?.duration ?? 0 },
|
|
1448
|
-
]);
|
|
1449
|
-
}
|
|
1450
|
-
else if ("audio" in media) {
|
|
1451
|
-
return await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_resolveInputMediaInner).call(this, media.audio, media, FileType.Audio, [
|
|
1452
|
-
{ _: "documentAttributeAudio", duration: media?.duration ?? 0, performer: media?.performer, title: media?.title },
|
|
1453
|
-
]);
|
|
1454
|
-
}
|
|
1455
|
-
else if ("document" in media) {
|
|
1456
|
-
return await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_resolveInputMediaInner).call(this, media.document, media, FileType.Document, []);
|
|
1457
|
-
}
|
|
1458
|
-
else if ("photo" in media) {
|
|
1459
|
-
let media_ = null;
|
|
1460
|
-
const spoiler = media.hasSpoiler ? true : undefined;
|
|
1461
|
-
const ttl_seconds = "selfDestruct" in media && media.selfDestruct !== undefined ? selfDestructOptionToInt(media.selfDestruct) : undefined;
|
|
1462
|
-
if (typeof media.photo === "string") {
|
|
1463
|
-
const fileId = this.resolveFileId(media.photo, [FileType.Photo, FileType.ProfilePhoto]);
|
|
1464
|
-
if (fileId != null) {
|
|
1465
|
-
media_ = { _: "inputMediaPhoto", id: { ...fileId, _: "inputPhoto" }, spoiler, ttl_seconds };
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
if (media_ == null) {
|
|
1469
|
-
if (typeof media.photo === "string" && isHttpUrl(media.photo)) {
|
|
1470
|
-
media_ = { _: "inputMediaPhotoExternal", url: media.photo, spoiler };
|
|
1471
|
-
}
|
|
1472
|
-
else {
|
|
1473
|
-
const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(media.photo, media, null, false);
|
|
1474
|
-
media_ = { _: "inputMediaUploadedPhoto", file, spoiler, ttl_seconds };
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
return media_;
|
|
1478
|
-
}
|
|
1479
|
-
else if ("video" in media) {
|
|
1480
|
-
const ttl_seconds = "selfDestruct" in media && media.selfDestruct !== undefined ? selfDestructOptionToInt(media.selfDestruct) : undefined;
|
|
1481
|
-
const media_ = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_resolveInputMediaInner).call(this, media.video, media, FileType.Video, [
|
|
1482
|
-
{ _: "documentAttributeVideo", supports_streaming: media?.supportsStreaming ? true : undefined, w: media?.width ?? 0, h: media?.height ?? 0, duration: media?.duration ?? 0 },
|
|
1483
|
-
]);
|
|
1484
|
-
media_.ttl_seconds = ttl_seconds;
|
|
1485
|
-
return media_;
|
|
1486
|
-
}
|
|
1487
|
-
else {
|
|
1488
|
-
unreachable();
|
|
1489
|
-
}
|
|
1490
|
-
}, _MessageManager_sendReaction = async function _MessageManager_sendReaction(chatId, messageId, reactions, params) {
|
|
1491
|
-
await __classPrivateFieldGet(this, _MessageManager_c, "f").invoke({ _: "messages.sendReaction", peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), msg_id: checkMessageId(messageId), reaction: reactions.map((v) => reactionToTlObject(v)), big: params?.big ? true : undefined, add_to_recent: params?.addToRecents ? true : undefined });
|
|
1492
|
-
}, _MessageManager_getCachedVoiceTranscription = async function _MessageManager_getCachedVoiceTranscription(message) {
|
|
1493
|
-
const reference = await __classPrivateFieldGet(this, _MessageManager_c, "f").messageStorage.getVoiceTranscriptionReference(message.chat.id, message.id, fromUnixTimestamp(message.editDate ?? message.date));
|
|
1494
|
-
if (!reference) {
|
|
1495
|
-
return null;
|
|
1496
|
-
}
|
|
1497
|
-
const voiceTranscription = await __classPrivateFieldGet(this, _MessageManager_c, "f").messageStorage.getVoiceTranscription(reference);
|
|
1498
|
-
if (!voiceTranscription || !voiceTranscription.done) {
|
|
1499
|
-
return null;
|
|
1500
|
-
}
|
|
1501
|
-
return voiceTranscription;
|
|
1502
|
-
}, _MessageManager_cacheVoiceTranscription = async function _MessageManager_cacheVoiceTranscription(message, voiceTranscription) {
|
|
1503
|
-
await __classPrivateFieldGet(this, _MessageManager_c, "f").messageStorage.setVoiceTranscriptionReference(message.chat.id, message.id, fromUnixTimestamp(message.editDate ?? message.date), BigInt(voiceTranscription.id));
|
|
1504
|
-
await __classPrivateFieldGet(this, _MessageManager_c, "f").messageStorage.setVoiceTranscription(voiceTranscription);
|
|
1505
|
-
return voiceTranscription;
|
|
1506
|
-
};
|
|
1507
|
-
_MessageManager_CAPTIONABLE_MESSAGE_TYPES = { value: ["photo", "document", "video", "animation", "voice", "audio", "video"] };
|