@mtkruto/node 0.1.129 → 0.1.131

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.
Files changed (41) hide show
  1. package/esm/0_deps.d.ts +1 -0
  2. package/esm/0_deps.js +9 -0
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/client/3_types.d.ts +363 -3
  6. package/esm/client/5_client.d.ts +113 -5
  7. package/esm/client/5_client.js +561 -103
  8. package/esm/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
  9. package/esm/deps/deno.land/std@0.209.0/media_types/extension.js +26 -0
  10. package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
  11. package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +31 -0
  12. package/esm/storage/0_storage.d.ts +3 -1
  13. package/esm/storage/0_storage.js +18 -5
  14. package/esm/tl/0_tl_raw_reader.js +1 -1
  15. package/esm/tl/3_utilities.d.ts +1 -0
  16. package/esm/tl/3_utilities.js +11 -0
  17. package/esm/types/1__getters.d.ts +1 -0
  18. package/esm/types/1_sticker.js +5 -4
  19. package/esm/types/4_chat.d.ts +3 -2
  20. package/esm/types/4_chat.js +16 -27
  21. package/package.json +1 -1
  22. package/script/0_deps.d.ts +1 -0
  23. package/script/0_deps.js +11 -1
  24. package/script/4_constants.d.ts +1 -1
  25. package/script/4_constants.js +1 -1
  26. package/script/client/3_types.d.ts +363 -3
  27. package/script/client/5_client.d.ts +113 -5
  28. package/script/client/5_client.js +558 -100
  29. package/script/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
  30. package/script/deps/deno.land/std@0.209.0/media_types/extension.js +30 -0
  31. package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
  32. package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +35 -0
  33. package/script/storage/0_storage.d.ts +3 -1
  34. package/script/storage/0_storage.js +18 -5
  35. package/script/tl/0_tl_raw_reader.js +1 -1
  36. package/script/tl/3_utilities.d.ts +1 -0
  37. package/script/tl/3_utilities.js +13 -1
  38. package/script/types/1__getters.d.ts +1 -0
  39. package/script/types/1_sticker.js +4 -3
  40. package/script/types/4_chat.d.ts +3 -2
  41. package/script/types/4_chat.js +17 -27
@@ -9,12 +9,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  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");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia, _Client_sendChatUpdate, _Client_reassignChatLastMessage, _Client_chats, _Client_archivedChats, _Client_chatsLoadedFromStorage, _Client_getChatAnywhere, _Client_getChatList, _Client_loadChatsFromStorage, _Client_getLoadedChats, _Client_pinnedChats, _Client_pinnedArchiveChats, _Client_storageHadPinnedChats, _Client_pinnedChatsLoaded, _Client_loadPinnedChats, _Client_fetchPinnedChats, _Client_getPinnedChats, _Client_updateOrAddChat, _Client_removeChat, _Client_updatePinnedChats, _Client_fetchChats;
13
- import { contentType, debug, gunzip, Mutex } from "../0_deps.js";
12
+ var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia, _Client_sendDocumentInner, _Client_sendChatUpdate, _Client_reassignChatLastMessage, _Client_chats, _Client_archivedChats, _Client_chatsLoadedFromStorage, _Client_tryGetChatId, _Client_getChatAnywhere, _Client_getChatList, _Client_loadChatsFromStorage, _Client_getLoadedChats, _Client_pinnedChats, _Client_pinnedArchiveChats, _Client_storageHadPinnedChats, _Client_pinnedChatsLoaded, _Client_loadPinnedChats, _Client_fetchPinnedChats, _Client_getPinnedChats, _Client_updateOrAddChat, _Client_removeChat, _Client_updatePinnedChats, _Client_fetchChats;
13
+ import { contentType, debug, extension, gunzip, Mutex } from "../0_deps.js";
14
14
  import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mod, mustPrompt, mustPromptOneOf, Queue, sha1, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
15
15
  import { as, functions, getChannelChatId, Message_, MessageContainer, name, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
16
16
  import { StorageMemory } from "../3_storage.js";
17
- import { botCommandScopeToTlObject, constructCallbackQuery, constructChat, constructChat2, constructChat3, constructChosenInlineResult, constructInlineQuery, constructMessage, constructUser, FileID, FileType, getChatOrder, inlineQueryResultToTlObject, messageEntityToTlObject, replyMarkupToTlObject, ThumbnailSource } from "../3_types.js";
17
+ import { botCommandScopeToTlObject, constructCallbackQuery, constructChat, constructChat2, constructChat3, constructChat4, constructChosenInlineResult, constructDocument, constructInlineQuery, constructMessage, constructUser, FileID, FileType, FileUniqueID, FileUniqueType, getChatOrder, inlineQueryResultToTlObject, messageEntityToTlObject, replyMarkupToTlObject, ThumbnailSource } from "../3_types.js";
18
18
  import { ACK_THRESHOLD, APP_VERSION, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, STICKER_SET_NAME_TTL, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL } from "../4_constants.js";
19
19
  import { AuthKeyUnregistered, FloodWait, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded, upgradeInstance } from "../4_errors.js";
20
20
  import { parseHtml } from "./0_html.js";
@@ -23,7 +23,7 @@ import { checkPassword } from "./0_password.js";
23
23
  import { getFileContents, getUsername, isChannelPtsUpdate, isHttpUrl, isPtsUpdate, resolve } from "./0_utilities.js";
24
24
  import { ClientAbstract } from "./1_client_abstract.js";
25
25
  import { ClientPlain } from "./2_client_plain.js";
26
- import { getChatListId, } from "./3_types.js";
26
+ import { getChatListId } from "./3_types.js";
27
27
  import { Composer, concat, flatten, skip } from "./4_composer.js";
28
28
  const d = debug("Client");
29
29
  const dGap = debug("Client/recoverUpdateGap");
@@ -226,6 +226,51 @@ export class Client extends ClientAbstract {
226
226
  const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
227
227
  return this.sendDocument(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
228
228
  },
229
+ replyContact: (firstName, number, params) => {
230
+ const effectiveMessage = mustGetMsg();
231
+ const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
232
+ return this.sendContact(effectiveMessage.chat.id, firstName, number, { ...params, replyToMessageId });
233
+ },
234
+ replyLocation: (latitude, longitude, params) => {
235
+ const effectiveMessage = mustGetMsg();
236
+ const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
237
+ return this.sendLocation(effectiveMessage.chat.id, latitude, longitude, { ...params, replyToMessageId });
238
+ },
239
+ replyDice: (params) => {
240
+ const effectiveMessage = mustGetMsg();
241
+ const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
242
+ return this.sendDice(effectiveMessage.chat.id, { ...params, replyToMessageId });
243
+ },
244
+ replyVenue: (latitude, longitude, title, address, params) => {
245
+ const effectiveMessage = mustGetMsg();
246
+ const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
247
+ return this.sendVenue(effectiveMessage.chat.id, latitude, longitude, title, address, { ...params, replyToMessageId });
248
+ },
249
+ replyVideo: (document, params) => {
250
+ const effectiveMessage = mustGetMsg();
251
+ const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
252
+ return this.sendDocument(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
253
+ },
254
+ replyAnimation: (document, params) => {
255
+ const effectiveMessage = mustGetMsg();
256
+ const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
257
+ return this.sendAnimation(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
258
+ },
259
+ replyVoice: (document, params) => {
260
+ const effectiveMessage = mustGetMsg();
261
+ const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
262
+ return this.sendVoice(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
263
+ },
264
+ replyAudio: (document, params) => {
265
+ const effectiveMessage = mustGetMsg();
266
+ const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
267
+ return this.sendAudio(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
268
+ },
269
+ replyVideoNote: (videoNote, params) => {
270
+ const effectiveMessage = mustGetMsg();
271
+ const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
272
+ return this.sendVideoNote(effectiveMessage.chat.id, videoNote, { ...params, replyToMessageId });
273
+ },
229
274
  delete: () => {
230
275
  const effectiveMessage = mustGetMsg();
231
276
  return this.deleteMessage(effectiveMessage.chat.id, effectiveMessage.id);
@@ -517,7 +562,7 @@ export class Client extends ClientAbstract {
517
562
  throw new Error(`${source}: not a bot client`);
518
563
  }
519
564
  }, _Client_fetchState = async function _Client_fetchState(source) {
520
- const state = await this.invoke(new functions.updates.getState());
565
+ const state = await this.api.updates.getState();
521
566
  __classPrivateFieldSet(this, _Client_updateState, state, "f");
522
567
  d("state fetched [%s]", source);
523
568
  }, handleMigrationError)](err) {
@@ -583,7 +628,7 @@ export class Client extends ClientAbstract {
583
628
  if (typeof params === "string") {
584
629
  while (true) {
585
630
  try {
586
- const auth = await this.invoke(new functions.auth.importBotAuthorization({ api_id: this.apiId, api_hash: this.apiHash, bot_auth_token: params, flags: 0 }));
631
+ const auth = await this.api.auth.importBotAuthorization({ api_id: this.apiId, api_hash: this.apiHash, bot_auth_token: params, flags: 0 });
587
632
  __classPrivateFieldSet(this, _Client_selfId, Number(auth[as](types.auth.Authorization).user.id), "f");
588
633
  await this.storage.setAccountType("bot");
589
634
  break;
@@ -605,7 +650,7 @@ export class Client extends ClientAbstract {
605
650
  return;
606
651
  }
607
652
  if (params instanceof types.auth.ExportedAuthorization) {
608
- await this.invoke(new functions.auth.importAuthorization({ id: params.id, bytes: params.bytes }));
653
+ await this.api.auth.importAuthorization({ id: params.id, bytes: params.bytes });
609
654
  dAuth("authorization imported");
610
655
  return;
611
656
  }
@@ -616,12 +661,12 @@ export class Client extends ClientAbstract {
616
661
  while (true) {
617
662
  try {
618
663
  phone = typeof params.phone === "string" ? params.phone : await params.phone();
619
- const sendCode = () => this.invoke(new functions.auth.sendCode({
664
+ const sendCode = () => this.api.auth.sendCode({
620
665
  phone_number: phone,
621
666
  api_id: this.apiId,
622
667
  api_hash: this.apiHash,
623
668
  settings: new types.CodeSettings(),
624
- })).then((v) => v[as](types.auth.SentCode));
669
+ }).then((v) => v[as](types.auth.SentCode));
625
670
  try {
626
671
  sentCode = await sendCode();
627
672
  }
@@ -651,11 +696,11 @@ export class Client extends ClientAbstract {
651
696
  code: while (true) {
652
697
  const code = typeof params.code === "string" ? params.code : await params.code();
653
698
  try {
654
- const auth = await this.invoke(new functions.auth.signIn({
699
+ const auth = await this.api.auth.signIn({
655
700
  phone_number: phone,
656
701
  phone_code: code,
657
702
  phone_code_hash: sentCode.phone_code_hash,
658
- }));
703
+ });
659
704
  __classPrivateFieldSet(this, _Client_selfId, Number(auth[as](types.auth.Authorization).user.id), "f");
660
705
  await this.storage.setAccountType("user");
661
706
  dAuth("authorized as user");
@@ -677,14 +722,14 @@ export class Client extends ClientAbstract {
677
722
  throw err;
678
723
  }
679
724
  password: while (true) {
680
- const ap = await this.invoke(new functions.account.getPassword());
725
+ const ap = await this.api.account.getPassword();
681
726
  if (!(ap.current_algo instanceof types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow)) {
682
727
  throw new Error(`Handling ${ap.current_algo?.[name]} not implemented`);
683
728
  }
684
729
  try {
685
730
  const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
686
731
  const input = await checkPassword(password, ap);
687
- const auth = await this.invoke(new functions.auth.checkPassword({ password: input }));
732
+ const auth = await this.api.auth.checkPassword({ password: input });
688
733
  __classPrivateFieldSet(this, _Client_selfId, Number(auth[as](types.auth.Authorization).user.id), "f");
689
734
  await this.storage.setAccountType("user");
690
735
  dAuth("authorized as user");
@@ -732,7 +777,7 @@ export class Client extends ClientAbstract {
732
777
  return this.invoke(function_, true);
733
778
  }
734
779
  async getUserAccessHash(userId) {
735
- const users = await this.invoke(new functions.users.getUsers({ id: [new types.InputUser({ user_id: userId, access_hash: 0n })] }));
780
+ const users = await this.api.users.getUsers({ id: [new types.InputUser({ user_id: userId, access_hash: 0n })] });
736
781
  return users[0]?.[as](types.User).access_hash ?? 0n;
737
782
  }
738
783
  async getInputPeer(id) {
@@ -750,7 +795,7 @@ export class Client extends ClientAbstract {
750
795
  }
751
796
  [(_Client_initConnection = async function _Client_initConnection() {
752
797
  if (!__classPrivateFieldGet(this, _Client_connectionInited, "f")) {
753
- await this.invoke(new functions.initConnection({
798
+ await this.api.initConnection({
754
799
  api_id: this.apiId,
755
800
  app_version: this.appVersion,
756
801
  device_model: this.deviceModel,
@@ -762,7 +807,7 @@ export class Client extends ClientAbstract {
762
807
  }),
763
808
  system_lang_code: this.systemLangCode,
764
809
  system_version: this.systemVersion,
765
- }));
810
+ });
766
811
  __classPrivateFieldSet(this, _Client_connectionInited, true, "f");
767
812
  d("connection inited");
768
813
  }
@@ -905,7 +950,7 @@ export class Client extends ClientAbstract {
905
950
  reject(__classPrivateFieldGet(this, _Client_pingLoopAbortSignal, "f")?.signal.reason);
906
951
  };
907
952
  });
908
- await this.invoke(new functions.ping_delay_disconnect({ ping_id: getRandomId(), disconnect_delay: __classPrivateFieldGet(this, _Client_pingInterval, "f") / 1000 + 15 }));
953
+ await this.api.ping_delay_disconnect({ ping_id: getRandomId(), disconnect_delay: __classPrivateFieldGet(this, _Client_pingInterval, "f") / 1000 + 15 });
909
954
  if (Date.now() - __classPrivateFieldGet(this, _Client_lastUpdates, "f").getTime() >= 15 * 60 * 1000) {
910
955
  drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "lastUpdates"));
911
956
  }
@@ -915,20 +960,20 @@ export class Client extends ClientAbstract {
915
960
  }
916
961
  }
917
962
  }, _Client_invoke = async function _Client_invoke(function_, noWait) {
918
- if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
919
- if (__classPrivateFieldGet(this, _Client_autoStart, "f") && !__classPrivateFieldGet(this, _Client_autoStarted, "f")) {
920
- await this.start();
921
- }
922
- else {
923
- throw new ConnectionError("Not connected");
924
- }
925
- }
926
- if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
927
- UNREACHABLE();
928
- }
929
963
  let n = 1;
930
964
  while (true) {
931
965
  try {
966
+ if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
967
+ if (__classPrivateFieldGet(this, _Client_autoStart, "f") && !__classPrivateFieldGet(this, _Client_autoStarted, "f")) {
968
+ await this.start();
969
+ }
970
+ else {
971
+ throw new ConnectionError("Not connected");
972
+ }
973
+ }
974
+ if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
975
+ UNREACHABLE();
976
+ }
932
977
  let seqNo = __classPrivateFieldGet(this, _Client_state, "f").seqNo * 2;
933
978
  if (!(function_ instanceof functions.ping) && !(function_ instanceof types.Msgs_ack)) {
934
979
  seqNo++;
@@ -1231,7 +1276,7 @@ export class Client extends ClientAbstract {
1231
1276
  try {
1232
1277
  let state = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1233
1278
  while (true) {
1234
- const difference = await this.invoke(new functions.updates.getDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 }));
1279
+ const difference = await this.api.updates.getDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 });
1235
1280
  if (difference instanceof types.updates.Difference || difference instanceof types.updates.DifferenceSlice) {
1236
1281
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
1237
1282
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
@@ -1280,12 +1325,12 @@ export class Client extends ClientAbstract {
1280
1325
  let pts = pts_ == null ? 1 : pts_;
1281
1326
  while (true) {
1282
1327
  const { access_hash } = await this.getInputPeer(ZERO_CHANNEL_ID + -Number(channelId)).then((v) => v[as](types.InputPeerChannel));
1283
- const difference = await this.invoke(new functions.updates.getChannelDifference({
1328
+ const difference = await this.api.updates.getChannelDifference({
1284
1329
  pts,
1285
1330
  channel: new types.InputChannel({ channel_id: channelId, access_hash }),
1286
1331
  filter: new types.ChannelMessagesFilterEmpty(),
1287
1332
  limit: await this.storage.getAccountType() == "user" ? CHANNEL_DIFFERENCE_LIMIT_USER : CHANNEL_DIFFERENCE_LIMIT_BOT,
1288
- }));
1333
+ });
1289
1334
  if (difference instanceof types.updates.ChannelDifference) {
1290
1335
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
1291
1336
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
@@ -1322,7 +1367,7 @@ export class Client extends ClientAbstract {
1322
1367
  }
1323
1368
  }
1324
1369
  }, _Client_getChannelAccessHash = async function _Client_getChannelAccessHash(channelId) {
1325
- const channels = await this.invoke(new functions.channels.getChannels({ id: [new types.InputChannel({ channel_id: channelId, access_hash: 0n })] }));
1370
+ const channels = await this.api.channels.getChannels({ id: [new types.InputChannel({ channel_id: channelId, access_hash: 0n })] });
1326
1371
  return channels.chats[0][as](types.Channel).access_hash ?? 0n;
1327
1372
  }, _Client_getInputPeerInner = async function _Client_getInputPeerInner(id) {
1328
1373
  if (typeof id === "string") {
@@ -1340,7 +1385,7 @@ export class Client extends ClientAbstract {
1340
1385
  }
1341
1386
  }
1342
1387
  else {
1343
- const resolved = await this.invoke(new functions.contacts.resolveUsername({ username: id }));
1388
+ const resolved = await this.api.contacts.resolveUsername({ username: id });
1344
1389
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, resolved.chats);
1345
1390
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, resolved.users);
1346
1391
  if (resolved.peer instanceof types.PeerUser) {
@@ -1462,7 +1507,7 @@ export class Client extends ClientAbstract {
1462
1507
  const replyToMsgId = params?.replyToMessageId;
1463
1508
  const topMsgId = params?.messageThreadId;
1464
1509
  const sendAs = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveSendAs).call(this, params);
1465
- const result = await this.invoke(new functions.messages.sendMessage({
1510
+ const result = await this.api.messages.sendMessage({
1466
1511
  peer,
1467
1512
  random_id: randomId,
1468
1513
  message,
@@ -1473,7 +1518,7 @@ export class Client extends ClientAbstract {
1473
1518
  send_as: sendAs,
1474
1519
  entities,
1475
1520
  reply_markup: replyMarkup,
1476
- }));
1521
+ });
1477
1522
  const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1478
1523
  return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message_, "text");
1479
1524
  }
@@ -1488,14 +1533,14 @@ export class Client extends ClientAbstract {
1488
1533
  */
1489
1534
  async editMessageText(chatId, messageId, text, params) {
1490
1535
  const [message, entities] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, text, params);
1491
- const result = await this.invoke(new functions.messages.editMessage({
1536
+ const result = await this.api.messages.editMessage({
1492
1537
  id: messageId,
1493
1538
  peer: await this.getInputPeer(chatId),
1494
1539
  entities,
1495
1540
  message,
1496
1541
  no_webpage: params?.disableWebPagePreview ? true : undefined,
1497
1542
  reply_markup: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params),
1498
- }));
1543
+ });
1499
1544
  const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1500
1545
  return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message_, "text");
1501
1546
  }
@@ -1578,15 +1623,15 @@ export class Client extends ClientAbstract {
1578
1623
  }
1579
1624
  if (shouldFetch) {
1580
1625
  if (peer instanceof types.InputPeerChannel) {
1581
- messages_ = await this.invoke(new functions.channels.getMessages({
1626
+ messages_ = await this.api.channels.getMessages({
1582
1627
  channel: new types.InputChannel(peer),
1583
1628
  id: messageIds.map((v) => new types.InputMessageID({ id: v })),
1584
- })).then((v) => v[as](types.messages.ChannelMessages).messages);
1629
+ }).then((v) => v[as](types.messages.ChannelMessages).messages);
1585
1630
  }
1586
1631
  else {
1587
- messages_ = await this.invoke(new functions.messages.getMessages({
1632
+ messages_ = await this.api.messages.getMessages({
1588
1633
  id: messageIds.map((v) => new types.InputMessageID({ id: v })),
1589
- })).then((v) => v[as](types.messages.Messages).messages);
1634
+ }).then((v) => v[as](types.messages.Messages).messages);
1590
1635
  }
1591
1636
  }
1592
1637
  const messages = new Array();
@@ -1630,14 +1675,17 @@ export class Client extends ClientAbstract {
1630
1675
  * ```
1631
1676
  * @returns A generator yielding the contents of the file.
1632
1677
  */
1633
- async download(fileId, params) {
1678
+ async *download(fileId, params) {
1634
1679
  const fileId_ = FileID.decode(fileId);
1635
1680
  switch (fileId_.fileType) {
1636
1681
  case FileType.ChatPhoto: {
1637
1682
  const big = fileId_.params.thumbnailSource == ThumbnailSource.ChatPhotoBig;
1638
1683
  const peer = await this.getInputPeer(fileId_.params.chatId);
1639
1684
  const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photo_id: fileId_.params.mediaId });
1640
- return __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params);
1685
+ for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
1686
+ yield chunk;
1687
+ }
1688
+ break;
1641
1689
  }
1642
1690
  case FileType.Photo: {
1643
1691
  if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
@@ -1649,7 +1697,31 @@ export class Client extends ClientAbstract {
1649
1697
  file_reference: fileId_.params.fileReference,
1650
1698
  thumb_size: fileId_.params.thumbnailSize,
1651
1699
  });
1652
- return __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params);
1700
+ for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
1701
+ yield chunk;
1702
+ }
1703
+ break;
1704
+ }
1705
+ case FileType.Document:
1706
+ case FileType.Sticker:
1707
+ case FileType.VideoNote:
1708
+ case FileType.Video:
1709
+ case FileType.Audio:
1710
+ case FileType.Voice:
1711
+ case FileType.Animation: {
1712
+ if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
1713
+ UNREACHABLE();
1714
+ }
1715
+ const location = new types.InputDocumentFileLocation({
1716
+ id: fileId_.params.mediaId,
1717
+ access_hash: fileId_.params.accessHash,
1718
+ file_reference: fileId_.params.fileReference,
1719
+ thumb_size: fileId_.params.thumbnailSize,
1720
+ });
1721
+ for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
1722
+ yield chunk;
1723
+ }
1724
+ break;
1653
1725
  }
1654
1726
  default:
1655
1727
  UNREACHABLE();
@@ -1690,7 +1762,7 @@ export class Client extends ClientAbstract {
1690
1762
  client.invoke.use(async (ctx, next) => {
1691
1763
  if (ctx.error instanceof AuthKeyUnregistered) {
1692
1764
  try {
1693
- const exportedAuth = await this.invoke(new functions.auth.exportAuthorization({ dc_id: dcId }));
1765
+ const exportedAuth = await this.api.auth.exportAuthorization({ dc_id: dcId });
1694
1766
  await client.authorize(exportedAuth);
1695
1767
  return true;
1696
1768
  }
@@ -1733,7 +1805,7 @@ export class Client extends ClientAbstract {
1733
1805
  return maybeStickerSetName[0];
1734
1806
  }
1735
1807
  else {
1736
- const stickerSet = await this.invoke(new functions.messages.getStickerSet({ stickerset: inputStickerSet, hash }));
1808
+ const stickerSet = await this.api.messages.getStickerSet({ stickerset: inputStickerSet, hash });
1737
1809
  const name = stickerSet[as](types.messages.StickerSet).set.short_name;
1738
1810
  await this.storage.updateStickerSetName(inputStickerSet.id, inputStickerSet.access_hash, name);
1739
1811
  return name;
@@ -1749,7 +1821,7 @@ export class Client extends ClientAbstract {
1749
1821
  * @returns The forwarded messages.
1750
1822
  */
1751
1823
  async forwardMessages(from, to, messageIds, params) {
1752
- const result = await this.invoke(new functions.messages.forwardMessages({
1824
+ const result = await this.api.messages.forwardMessages({
1753
1825
  from_peer: await this.getInputPeer(from),
1754
1826
  to_peer: await this.getInputPeer(to),
1755
1827
  id: messageIds,
@@ -1760,7 +1832,7 @@ export class Client extends ClientAbstract {
1760
1832
  send_as: params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined,
1761
1833
  drop_author: params?.dropSenderName || undefined,
1762
1834
  drop_media_captions: params?.dropCaption || undefined,
1763
- }));
1835
+ });
1764
1836
  return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, to, result);
1765
1837
  }
1766
1838
  /**
@@ -1781,7 +1853,7 @@ export class Client extends ClientAbstract {
1781
1853
  * @method
1782
1854
  */
1783
1855
  async getMe() {
1784
- const users = await this.invoke(new functions.users.getUsers({ id: [new types.InputUserSelf()] }));
1856
+ const users = await this.api.users.getUsers({ id: [new types.InputUserSelf()] });
1785
1857
  if (users.length < 1) {
1786
1858
  UNREACHABLE();
1787
1859
  }
@@ -1797,12 +1869,12 @@ export class Client extends ClientAbstract {
1797
1869
  */
1798
1870
  async answerCallbackQuery(id, params) {
1799
1871
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "answerCallbackQuery");
1800
- await this.invoke(new functions.messages.setBotCallbackAnswer({
1872
+ await this.api.messages.setBotCallbackAnswer({
1801
1873
  query_id: BigInt(id),
1802
1874
  cache_time: params?.cacheTime ?? 0,
1803
1875
  message: params?.text,
1804
1876
  alert: params?.alert ? true : undefined,
1805
- }));
1877
+ });
1806
1878
  }
1807
1879
  /**
1808
1880
  * Send a poll.
@@ -1844,7 +1916,7 @@ export class Client extends ClientAbstract {
1844
1916
  solution,
1845
1917
  solution_entities: solutionEntities,
1846
1918
  });
1847
- const result = await this.invoke(new functions.messages.sendMedia({
1919
+ const result = await this.api.messages.sendMedia({
1848
1920
  peer,
1849
1921
  random_id: randomId,
1850
1922
  silent,
@@ -1854,7 +1926,7 @@ export class Client extends ClientAbstract {
1854
1926
  send_as: sendAs,
1855
1927
  media,
1856
1928
  message: "",
1857
- }));
1929
+ });
1858
1930
  const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1859
1931
  return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "poll");
1860
1932
  }
@@ -1905,7 +1977,7 @@ export class Client extends ClientAbstract {
1905
1977
  default:
1906
1978
  throw new Error("Invalid chat action: " + action);
1907
1979
  }
1908
- await this.invoke(new functions.messages.setTyping({ peer: await this.getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId }));
1980
+ await this.api.messages.setTyping({ peer: await this.getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId });
1909
1981
  }
1910
1982
  /**
1911
1983
  * Upload a file.
@@ -2005,20 +2077,20 @@ export class Client extends ClientAbstract {
2005
2077
  * @param commands The commands to set.
2006
2078
  */
2007
2079
  async setMyCommands(commands, params) {
2008
- await this.invoke(new functions.bots.setBotCommands({
2080
+ await this.api.bots.setBotCommands({
2009
2081
  commands: commands.map((v) => new types.BotCommand(v)),
2010
2082
  lang_code: params?.languageCode ?? "",
2011
2083
  scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
2012
- }));
2084
+ });
2013
2085
  }
2014
2086
  /**
2015
2087
  * Get the bot's commands in the given scope and/or language. Bot-only.
2016
2088
  */
2017
2089
  async getMyCommands(params) {
2018
- const commands_ = await this.invoke(new functions.bots.getBotCommands({
2090
+ const commands_ = await this.api.bots.getBotCommands({
2019
2091
  lang_code: params?.languageCode ?? "",
2020
2092
  scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
2021
- }));
2093
+ });
2022
2094
  return commands_.map((v) => ({ command: v.command, description: v.description }));
2023
2095
  }
2024
2096
  /**
@@ -2029,7 +2101,7 @@ export class Client extends ClientAbstract {
2029
2101
  * @param results The results to answer with.
2030
2102
  */
2031
2103
  async answerInlineQuery(id, results, params) {
2032
- await this.invoke(new functions.messages.setInlineBotResults({
2104
+ await this.api.messages.setInlineBotResults({
2033
2105
  query_id: BigInt(id),
2034
2106
  results: await Promise.all(results.map((v) => inlineQueryResultToTlObject(v, __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).bind(this), __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this)))),
2035
2107
  cache_time: params?.cacheTime ?? 300,
@@ -2038,7 +2110,7 @@ export class Client extends ClientAbstract {
2038
2110
  switch_pm: params?.button && params.button.startParameter ? new types.InlineBotSwitchPM({ text: params.button.text, start_param: params.button.startParameter }) : undefined,
2039
2111
  gallery: params?.isGallery ? true : undefined,
2040
2112
  next_offset: params?.nextOffset,
2041
- }));
2113
+ });
2042
2114
  }
2043
2115
  use(...middleware) {
2044
2116
  const composer = new Composer(...middleware);
@@ -2190,10 +2262,10 @@ export class Client extends ClientAbstract {
2190
2262
  async deleteMessages(chatId, messageIds, params) {
2191
2263
  const peer = await this.getInputPeer(chatId);
2192
2264
  if (peer instanceof types.InputPeerChannel) {
2193
- await this.invoke(new functions.channels.deleteMessages({ channel: new types.InputChannel(peer), id: messageIds }));
2265
+ await this.api.channels.deleteMessages({ channel: new types.InputChannel(peer), id: messageIds });
2194
2266
  }
2195
2267
  else {
2196
- await this.invoke(new functions.messages.deleteMessages({ id: messageIds, revoke: params?.onlyForMe ? undefined : true }));
2268
+ await this.api.messages.deleteMessages({ id: messageIds, revoke: params?.onlyForMe ? undefined : true });
2197
2269
  }
2198
2270
  }
2199
2271
  /**
@@ -2246,37 +2318,255 @@ export class Client extends ClientAbstract {
2246
2318
  * @param document The document to send.
2247
2319
  */
2248
2320
  async sendDocument(chatId, document, params) {
2249
- let media = null;
2250
- const spoiler = params?.hasSpoiler ? true : undefined;
2251
- if (typeof document === "string") {
2252
- const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, document, FileType.Document);
2253
- if (fileId != null) {
2254
- media = new types.InputMediaDocument({
2255
- id: new types.InputDocument(fileId),
2256
- spoiler,
2257
- });
2258
- }
2259
- }
2260
- if (media == null) {
2261
- if (typeof document === "string" && isHttpUrl(document)) {
2262
- media = new types.InputMediaDocumentExternal({ url: document, spoiler });
2263
- }
2264
- else {
2265
- const [contents, fileName_] = await getFileContents(document);
2266
- const fileName = params?.fileName ?? fileName_;
2267
- const mimeType = params?.mimeType ?? contentType(fileName.split(".").slice(-1)[0]) ?? "application/octet-stream";
2268
- const file = await this.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal });
2269
- media = new types.InputMediaUploadedDocument({
2270
- file,
2271
- spoiler,
2272
- attributes: [new types.DocumentAttributeFilename({ file_name: fileName })],
2273
- mime_type: mimeType,
2274
- });
2275
- }
2276
- }
2277
- const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
2321
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, document, params, FileType.Document, []);
2278
2322
  return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "document");
2279
2323
  }
2324
+ /**
2325
+ * Send a video.
2326
+ *
2327
+ * @method
2328
+ * @param chatId The chat to send the video to.
2329
+ * @param video The video to send.
2330
+ */
2331
+ async sendVideo(chatId, video, params) {
2332
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, video, params, FileType.Video, [
2333
+ new types.DocumentAttributeVideo({
2334
+ supports_streaming: params?.supportsStreaming ? true : undefined,
2335
+ w: params?.width ?? 0,
2336
+ h: params?.height ?? 0,
2337
+ duration: params?.duration ?? 0,
2338
+ }),
2339
+ ]);
2340
+ return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "video");
2341
+ }
2342
+ /**
2343
+ * Send an animation.
2344
+ *
2345
+ * @method
2346
+ * @param chatId The chat to send the animation to.
2347
+ * @param animation The animation to send.
2348
+ */
2349
+ async sendAnimation(chatId, animation, params) {
2350
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, animation, params, FileType.Animation, [
2351
+ new types.DocumentAttributeAnimated(),
2352
+ new types.DocumentAttributeVideo({
2353
+ supports_streaming: true,
2354
+ w: params?.width ?? 0,
2355
+ h: params?.height ?? 0,
2356
+ duration: params?.duration ?? 0,
2357
+ }),
2358
+ ]);
2359
+ return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "animation");
2360
+ }
2361
+ /**
2362
+ * Send a voice message.
2363
+ *
2364
+ * @method
2365
+ * @param chatId The chat to send the voice message to.
2366
+ * @param voice The voice to send.
2367
+ */
2368
+ async sendVoice(chatId, voice, params) {
2369
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, voice, params, FileType.Voice, [
2370
+ new types.DocumentAttributeAudio({
2371
+ voice: true,
2372
+ duration: params?.duration ?? 0,
2373
+ }),
2374
+ ]);
2375
+ return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "voice");
2376
+ }
2377
+ /**
2378
+ * Send an audio file.
2379
+ *
2380
+ * @method
2381
+ * @param chatId The chat to send the audio file to.
2382
+ * @param audio The audio to send.
2383
+ */
2384
+ async sendAudio(chatId, audio, params) {
2385
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, audio, params, FileType.Audio, [
2386
+ new types.DocumentAttributeAudio({
2387
+ duration: params?.duration ?? 0,
2388
+ performer: params?.performer,
2389
+ title: params?.title,
2390
+ }),
2391
+ ]);
2392
+ return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "audio");
2393
+ }
2394
+ /**
2395
+ * Send a video note.
2396
+ *
2397
+ * @method
2398
+ * @param chatId The chat to send the video note to.
2399
+ * @param videoNote The video note to send.
2400
+ */
2401
+ async sendVideoNote(chatId, audio, params) {
2402
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, audio, params, FileType.VideoNote, [
2403
+ new types.DocumentAttributeVideo({
2404
+ round_message: true,
2405
+ w: params?.length ?? 0,
2406
+ h: params?.length ?? 0,
2407
+ duration: params?.duration ?? 0,
2408
+ }),
2409
+ ], false);
2410
+ return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "videoNote");
2411
+ }
2412
+ /**
2413
+ * Send a location.
2414
+ *
2415
+ * @method
2416
+ * @param chatId The chat to send the location to.
2417
+ * @param latitude The location's latitude.
2418
+ * @param longitude The location's longitude.
2419
+ */
2420
+ async sendLocation(chatId, latitude, longitude, params) {
2421
+ const peer = await this.getInputPeer(chatId);
2422
+ const randomId = getRandomId();
2423
+ const silent = params?.disableNotification ? true : undefined;
2424
+ const noforwards = params?.protectContent ? true : undefined;
2425
+ const replyToMsgId = params?.replyToMessageId;
2426
+ const topMsgId = params?.messageThreadId;
2427
+ const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
2428
+ const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
2429
+ const result = await this.api.messages.sendMedia({
2430
+ peer,
2431
+ random_id: randomId,
2432
+ silent,
2433
+ noforwards,
2434
+ reply_to: replyToMsgId !== undefined ? new types.InputReplyToMessage({ reply_to_msg_id: replyToMsgId, top_msg_id: topMsgId }) : undefined,
2435
+ send_as: sendAs,
2436
+ reply_markup: replyMarkup,
2437
+ media: params?.livePeriod !== undefined
2438
+ ? new types.InputMediaGeoLive({
2439
+ geo_point: new types.InputGeoPoint({
2440
+ lat: latitude,
2441
+ long: longitude,
2442
+ accuracy_radius: params?.horizontalAccuracy,
2443
+ }),
2444
+ heading: params?.heading,
2445
+ period: params.livePeriod,
2446
+ proximity_notification_radius: params?.proximityAlertRadius,
2447
+ })
2448
+ : new types.InputMediaGeoPoint({
2449
+ geo_point: new types.InputGeoPoint({
2450
+ lat: latitude,
2451
+ long: longitude,
2452
+ accuracy_radius: params?.horizontalAccuracy,
2453
+ }),
2454
+ }),
2455
+ message: "",
2456
+ });
2457
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2458
+ return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "location");
2459
+ }
2460
+ /**
2461
+ * Send a contact.
2462
+ *
2463
+ * @method
2464
+ * @param chatId The chat to send the contact to.
2465
+ * @param firstName The contact's first name.
2466
+ * @param number The contact's phone number.
2467
+ */
2468
+ async sendContact(chatId, firstName, number, params) {
2469
+ const peer = await this.getInputPeer(chatId);
2470
+ const randomId = getRandomId();
2471
+ const silent = params?.disableNotification ? true : undefined;
2472
+ const noforwards = params?.protectContent ? true : undefined;
2473
+ const replyToMsgId = params?.replyToMessageId;
2474
+ const topMsgId = params?.messageThreadId;
2475
+ const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
2476
+ const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
2477
+ const result = await this.api.messages.sendMedia({
2478
+ peer,
2479
+ random_id: randomId,
2480
+ silent,
2481
+ noforwards,
2482
+ reply_to: replyToMsgId !== undefined ? new types.InputReplyToMessage({ reply_to_msg_id: replyToMsgId, top_msg_id: topMsgId }) : undefined,
2483
+ send_as: sendAs,
2484
+ reply_markup: replyMarkup,
2485
+ media: new types.InputMediaContact({
2486
+ phone_number: number,
2487
+ first_name: firstName,
2488
+ last_name: params?.lastName ?? "",
2489
+ vcard: params?.vcard ?? "",
2490
+ }),
2491
+ message: "",
2492
+ });
2493
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2494
+ return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "contact");
2495
+ }
2496
+ /**
2497
+ * Send a dice.
2498
+ *
2499
+ * @method
2500
+ * @param chatId The chat to send the dice to.
2501
+ */
2502
+ async sendDice(chatId, params) {
2503
+ const peer = await this.getInputPeer(chatId);
2504
+ const randomId = getRandomId();
2505
+ const silent = params?.disableNotification ? true : undefined;
2506
+ const noforwards = params?.protectContent ? true : undefined;
2507
+ const replyToMsgId = params?.replyToMessageId;
2508
+ const topMsgId = params?.messageThreadId;
2509
+ const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
2510
+ const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
2511
+ const result = await this.api.messages.sendMedia({
2512
+ peer,
2513
+ random_id: randomId,
2514
+ silent,
2515
+ noforwards,
2516
+ reply_to: replyToMsgId !== undefined ? new types.InputReplyToMessage({ reply_to_msg_id: replyToMsgId, top_msg_id: topMsgId }) : undefined,
2517
+ send_as: sendAs,
2518
+ reply_markup: replyMarkup,
2519
+ media: new types.InputMediaDice({
2520
+ emoticon: params?.emoji ?? "🎲",
2521
+ }),
2522
+ message: "",
2523
+ });
2524
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2525
+ return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "dice");
2526
+ }
2527
+ /**
2528
+ * Send a venue.
2529
+ *
2530
+ * @method
2531
+ * @param chatId The chat to send the venue to.
2532
+ * @param latitude The latitude of the venue.
2533
+ * @param longitude The longitude of the venue.
2534
+ * @param title The title of the venue.
2535
+ * @param address The written address of the venue.
2536
+ */
2537
+ async sendVenue(chatId, latitude, longitude, title, address, params) {
2538
+ const peer = await this.getInputPeer(chatId);
2539
+ const randomId = getRandomId();
2540
+ const silent = params?.disableNotification ? true : undefined;
2541
+ const noforwards = params?.protectContent ? true : undefined;
2542
+ const replyToMsgId = params?.replyToMessageId;
2543
+ const topMsgId = params?.messageThreadId;
2544
+ const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
2545
+ const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
2546
+ const result = await this.api.messages.sendMedia({
2547
+ peer,
2548
+ random_id: randomId,
2549
+ silent,
2550
+ noforwards,
2551
+ reply_to: replyToMsgId !== undefined ? new types.InputReplyToMessage({ reply_to_msg_id: replyToMsgId, top_msg_id: topMsgId }) : undefined,
2552
+ send_as: sendAs,
2553
+ reply_markup: replyMarkup,
2554
+ media: new types.InputMediaVenue({
2555
+ geo_point: new types.InputGeoPoint({
2556
+ lat: latitude,
2557
+ long: longitude,
2558
+ }),
2559
+ title,
2560
+ address,
2561
+ venue_id: params?.foursquareId ?? "",
2562
+ venue_type: params?.foursquareType ?? "",
2563
+ provider: "foursquare",
2564
+ }),
2565
+ message: "",
2566
+ });
2567
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2568
+ return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "dice");
2569
+ }
2280
2570
  /**
2281
2571
  * Get network statistics. This might not always be available.
2282
2572
  *
@@ -2300,7 +2590,7 @@ export class Client extends ClientAbstract {
2300
2590
  return { messages, cdn };
2301
2591
  }
2302
2592
  /**
2303
- * Get chats.
2593
+ * Get chats from a chat list. User-only.
2304
2594
  *
2305
2595
  * @method
2306
2596
  */
@@ -2333,7 +2623,77 @@ export class Client extends ClientAbstract {
2333
2623
  return chats;
2334
2624
  }
2335
2625
  /**
2336
- * Get chat history.
2626
+ * Get a chat.
2627
+ *
2628
+ * @method
2629
+ */
2630
+ async getChat(chatId) {
2631
+ if (await this.storage.getAccountType() == "user") {
2632
+ let maybeChatId = null;
2633
+ if (typeof chatId === "number") {
2634
+ maybeChatId = chatId;
2635
+ }
2636
+ else if (typeof chatId === "string") {
2637
+ maybeChatId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_tryGetChatId).call(this, getUsername(chatId));
2638
+ }
2639
+ else {
2640
+ UNREACHABLE();
2641
+ }
2642
+ if (maybeChatId != null) {
2643
+ const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, maybeChatId);
2644
+ if (chat !== undefined) {
2645
+ return chat;
2646
+ }
2647
+ }
2648
+ }
2649
+ let inputPeer = null;
2650
+ if (typeof chatId === "number") {
2651
+ const chat = await constructChat3(chatId, -1, undefined, this[getEntity].bind(this));
2652
+ if (chat != null) {
2653
+ return chat;
2654
+ }
2655
+ }
2656
+ else {
2657
+ inputPeer = await this.getInputPeer(chatId);
2658
+ const chatId_ = peerToChatId(inputPeer);
2659
+ const chat = await constructChat3(chatId_, -1, undefined, this[getEntity].bind(this));
2660
+ if (chat != null) {
2661
+ return chat;
2662
+ }
2663
+ }
2664
+ if (inputPeer == null) {
2665
+ inputPeer = await this.getInputPeer(chatId);
2666
+ }
2667
+ if (inputPeer instanceof types.InputPeerChat) {
2668
+ const chats = await this.api.messages.getChats({ id: [inputPeer.chat_id] }).then((v) => v[as](types.messages.Chats));
2669
+ const chat = chats.chats[0];
2670
+ if (chat instanceof types.ChatEmpty) {
2671
+ UNREACHABLE();
2672
+ }
2673
+ return constructChat2(chat, -1, undefined);
2674
+ }
2675
+ else if (inputPeer instanceof types.InputPeerChannel) {
2676
+ const channels = await this.api.channels.getChannels({ id: [new types.InputChannel(inputPeer)] });
2677
+ const channel = channels.chats[0];
2678
+ if (channel instanceof types.ChatEmpty) {
2679
+ UNREACHABLE();
2680
+ }
2681
+ return constructChat2(channel, -1, undefined);
2682
+ }
2683
+ else if (inputPeer instanceof types.InputPeerUser) {
2684
+ const users = await this.api.users.getUsers({ id: [new types.InputUser(inputPeer)] });
2685
+ const user = users[0];
2686
+ if (user instanceof types.UserEmpty) {
2687
+ UNREACHABLE();
2688
+ }
2689
+ return constructChat2(user, -1, undefined);
2690
+ }
2691
+ else {
2692
+ UNREACHABLE();
2693
+ }
2694
+ }
2695
+ /**
2696
+ * Get chat history. User-only.
2337
2697
  *
2338
2698
  * @param chatId The identifier of the chat to get its history.
2339
2699
  * @method
@@ -2381,6 +2741,53 @@ export class Client extends ClientAbstract {
2381
2741
  }
2382
2742
  return messages;
2383
2743
  }
2744
+ /**
2745
+ * Get custom emoji documents for download.
2746
+ *
2747
+ * @param id Identifier of one or more of custom emojis.
2748
+ * @method
2749
+ */
2750
+ async getCustomEmojiDocuments(id) {
2751
+ id = Array.isArray(id) ? id : [id];
2752
+ if (!id.length) {
2753
+ throw new Error("No custom emoji ID provided");
2754
+ }
2755
+ const documents = new Array();
2756
+ let shouldFetch = false;
2757
+ for (const [i, id_] of id.entries()) {
2758
+ const maybeDocument = await this.storage.getCustomEmojiDocument(BigInt(id_));
2759
+ if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <= 30 * 60 * 1000) {
2760
+ const document_ = maybeDocument[0];
2761
+ const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document_.id }).encode();
2762
+ const fileId = new FileID(null, null, FileType.Document, document_.dc_id, {
2763
+ mediaId: document_.id,
2764
+ accessHash: document_.access_hash,
2765
+ fileReference: document_.file_reference,
2766
+ }).encode();
2767
+ const document = constructDocument(document_, new types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${extension(document_.mime_type)}` }), fileId, fileUniqueId);
2768
+ documents.push(document);
2769
+ }
2770
+ else {
2771
+ shouldFetch = true;
2772
+ break;
2773
+ }
2774
+ }
2775
+ if (!shouldFetch) {
2776
+ return documents;
2777
+ }
2778
+ const documents_ = await this.api.messages.getCustomEmojiDocuments({ document_id: id.map(BigInt) }).then((v) => v.map((v) => v[as](types.Document)));
2779
+ for (const [i, document_] of documents_.entries()) {
2780
+ const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document_.id }).encode();
2781
+ const fileId = new FileID(null, null, FileType.Document, document_.dc_id, {
2782
+ mediaId: document_.id,
2783
+ accessHash: document_.access_hash,
2784
+ fileReference: document_.file_reference,
2785
+ }).encode();
2786
+ const document = constructDocument(document_, new types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${extension(document_.mime_type)}` }), fileId, fileUniqueId);
2787
+ documents.push(document);
2788
+ }
2789
+ return documents;
2790
+ }
2384
2791
  }
2385
2792
  _a = Client, _Client_getMe = async function _Client_getMe() {
2386
2793
  if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
@@ -2552,9 +2959,9 @@ async function _Client_handleUpdate(update) {
2552
2959
  }, _Client_setMyInfo =
2553
2960
  //#endregion
2554
2961
  async function _Client_setMyInfo(info) {
2555
- await this.invoke(new functions.bots.setBotInfo({ bot: new types.InputUserSelf(), ...info }));
2962
+ await this.api.bots.setBotInfo({ bot: new types.InputUserSelf(), ...info });
2556
2963
  }, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
2557
- return this.invoke(new functions.bots.getBotInfo({ bot: new types.InputUserSelf(), lang_code: languageCode ?? "" }));
2964
+ return this.api.bots.getBotInfo({ bot: new types.InputUserSelf(), lang_code: languageCode ?? "" });
2558
2965
  }, _Client_resolveFileId = function _Client_resolveFileId(maybeFileId, expectedFileType) {
2559
2966
  let fileId = null;
2560
2967
  try {
@@ -2590,7 +2997,7 @@ async function _Client_setMyInfo(info) {
2590
2997
  const parseResult = caption_ !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
2591
2998
  const caption = parseResult === undefined ? undefined : parseResult[0];
2592
2999
  const captionEntities = parseResult === undefined ? undefined : parseResult[1];
2593
- const result = await this.invoke(new functions.messages.sendMedia({
3000
+ const result = await this.api.messages.sendMedia({
2594
3001
  peer,
2595
3002
  random_id: randomId,
2596
3003
  silent,
@@ -2601,8 +3008,42 @@ async function _Client_setMyInfo(info) {
2601
3008
  media,
2602
3009
  message: caption ?? "",
2603
3010
  entities: captionEntities,
2604
- }));
3011
+ });
2605
3012
  return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
3013
+ }, _Client_sendDocumentInner = async function _Client_sendDocumentInner(chatId, document, params, fileType, otherAttribs, urlSupported = false) {
3014
+ let media = null;
3015
+ const spoiler = params?.hasSpoiler ? true : undefined;
3016
+ if (typeof document === "string") {
3017
+ const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, document, fileType);
3018
+ if (fileId != null) {
3019
+ media = new types.InputMediaDocument({
3020
+ id: new types.InputDocument(fileId),
3021
+ spoiler,
3022
+ });
3023
+ }
3024
+ }
3025
+ if (media == null) {
3026
+ if (typeof document === "string" && isHttpUrl(document)) {
3027
+ if (!urlSupported) {
3028
+ throw new Error("URL not supported");
3029
+ }
3030
+ media = new types.InputMediaDocumentExternal({ url: document, spoiler });
3031
+ }
3032
+ else {
3033
+ const [contents, fileName_] = await getFileContents(document);
3034
+ const fileName = params?.fileName ?? fileName_;
3035
+ const mimeType = params?.mimeType ?? contentType(fileName.split(".").slice(-1)[0]) ?? "application/octet-stream";
3036
+ const file = await this.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal });
3037
+ media = new types.InputMediaUploadedDocument({
3038
+ file,
3039
+ spoiler,
3040
+ attributes: [new types.DocumentAttributeFilename({ file_name: fileName }), ...otherAttribs],
3041
+ mime_type: mimeType,
3042
+ });
3043
+ }
3044
+ }
3045
+ const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
3046
+ return message;
2606
3047
  }, _Client_sendChatUpdate = async function _Client_sendChatUpdate(chatId, added) {
2607
3048
  try {
2608
3049
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
@@ -2636,7 +3077,7 @@ async function _Client_setMyInfo(info) {
2636
3077
  }
2637
3078
  else {
2638
3079
  const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
2639
- const chat = await constructChat2(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
3080
+ const chat = await constructChat3(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
2640
3081
  if (chat == null) {
2641
3082
  UNREACHABLE();
2642
3083
  }
@@ -2657,7 +3098,7 @@ async function _Client_setMyInfo(info) {
2657
3098
  }
2658
3099
  else {
2659
3100
  const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
2660
- const chat = await constructChat2(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
3101
+ const chat = await constructChat3(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
2661
3102
  if (chat == null) {
2662
3103
  UNREACHABLE();
2663
3104
  }
@@ -2675,6 +3116,23 @@ async function _Client_setMyInfo(info) {
2675
3116
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2676
3117
  }
2677
3118
  }
3119
+ }, _Client_tryGetChatId = function _Client_tryGetChatId(username) {
3120
+ username = username.toLowerCase();
3121
+ for (const chat of __classPrivateFieldGet(this, _Client_chats, "f").values()) {
3122
+ if ("username" in chat) {
3123
+ if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
3124
+ return chat.id;
3125
+ }
3126
+ }
3127
+ }
3128
+ for (const chat of __classPrivateFieldGet(this, _Client_archivedChats, "f").values()) {
3129
+ if ("username" in chat) {
3130
+ if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
3131
+ return chat.id;
3132
+ }
3133
+ }
3134
+ }
3135
+ return null;
2678
3136
  }, _Client_getChatAnywhere = function _Client_getChatAnywhere(chatId) {
2679
3137
  let chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
2680
3138
  if (chat) {
@@ -2698,14 +3156,14 @@ async function _Client_setMyInfo(info) {
2698
3156
  const chats = await this.storage.getChats(0);
2699
3157
  const archivedChats = await this.storage.getChats(1);
2700
3158
  for (const { chatId, pinned, topMessageId } of chats) {
2701
- const chat = await constructChat3(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
3159
+ const chat = await constructChat4(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
2702
3160
  if (chat == null) {
2703
3161
  continue;
2704
3162
  }
2705
3163
  __classPrivateFieldGet(this, _Client_chats, "f").set(chat.id, chat);
2706
3164
  }
2707
3165
  for (const { chatId, pinned, topMessageId } of archivedChats) {
2708
- const chat = await constructChat3(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
3166
+ const chat = await constructChat4(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
2709
3167
  if (chat == null) {
2710
3168
  continue;
2711
3169
  }
@@ -2769,14 +3227,14 @@ async function _Client_setMyInfo(info) {
2769
3227
  }, _Client_updateOrAddChat = async function _Client_updateOrAddChat(chatId) {
2770
3228
  const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2771
3229
  if (chat !== undefined) {
2772
- const newChat = await constructChat2(chatId, chat.pinned, chat.lastMessage, this[getEntity].bind(this));
3230
+ const newChat = await constructChat3(chatId, chat.pinned, chat.lastMessage, this[getEntity].bind(this));
2773
3231
  if (newChat != null) {
2774
3232
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).set(chatId, newChat);
2775
3233
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2776
3234
  }
2777
3235
  }
2778
3236
  else {
2779
- const chat = await constructChat3(chatId, -1, -1, this[getEntity].bind(this), this.getMessage.bind(this));
3237
+ const chat = await constructChat4(chatId, -1, -1, this[getEntity].bind(this), this.getMessage.bind(this));
2780
3238
  if (chat != null) {
2781
3239
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, 0).set(chatId, chat);
2782
3240
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId, false, false);