@mtkruto/node 0.0.991 → 0.0.992

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 (254) hide show
  1. package/esm/1_utilities.d.ts +12 -0
  2. package/esm/1_utilities.js +12 -0
  3. package/esm/2_connection.d.ts +2 -0
  4. package/esm/2_connection.js +2 -0
  5. package/esm/2_tl.d.ts +10 -0
  6. package/esm/2_tl.js +10 -0
  7. package/esm/3_storage.d.ts +6 -0
  8. package/esm/3_storage.js +6 -0
  9. package/esm/3_transport.d.ts +4 -0
  10. package/esm/3_transport.js +4 -0
  11. package/esm/3_types.d.ts +35 -0
  12. package/esm/3_types.js +35 -0
  13. package/esm/{constants.d.ts → 4_constants.d.ts} +2 -2
  14. package/esm/{constants.js → 4_constants.js} +1 -1
  15. package/esm/5_client.d.ts +2 -0
  16. package/esm/5_client.js +2 -0
  17. package/esm/client/0_html.d.ts +1 -1
  18. package/esm/client/0_html.js +1 -1
  19. package/esm/client/0_message.d.ts +1 -2
  20. package/esm/client/0_message.js +7 -14
  21. package/esm/client/0_password.d.ts +2 -2
  22. package/esm/client/0_password.js +2 -4
  23. package/esm/client/0_utilities.d.ts +3 -5
  24. package/esm/client/0_utilities.js +3 -22
  25. package/esm/client/1_client_abstract.d.ts +2 -2
  26. package/esm/client/1_client_abstract.js +3 -3
  27. package/esm/client/2_client_plain.d.ts +3 -3
  28. package/esm/client/2_client_plain.js +13 -20
  29. package/esm/client/3_client.d.ts +33 -18
  30. package/esm/client/3_client.js +47 -35
  31. package/esm/connection/0_connection.d.ts +1 -1
  32. package/esm/connection/1_connection_web_socket.js +1 -1
  33. package/esm/mod.d.ts +7 -21
  34. package/esm/mod.js +7 -21
  35. package/esm/storage/0_storage.d.ts +4 -5
  36. package/esm/storage/0_storage.js +3 -8
  37. package/esm/storage/0_utilities.js +2 -2
  38. package/esm/storage/1_storage_local_storage.d.ts +1 -1
  39. package/esm/storage/1_storage_memory.d.ts +1 -1
  40. package/esm/storage/1_storage_session_storage.d.ts +1 -1
  41. package/esm/tl/0_tl_raw_reader.js +1 -1
  42. package/esm/tl/0_tl_raw_writer.js +1 -1
  43. package/esm/tl/1_tl_object.js +1 -1
  44. package/esm/tl/3_deserialize.js +1 -1
  45. package/esm/tl/3_utilities.d.ts +3 -0
  46. package/esm/tl/3_utilities.js +20 -0
  47. package/esm/tl/4_tl_writer.js +1 -1
  48. package/esm/transport/0_obfuscation.d.ts +2 -2
  49. package/esm/transport/0_obfuscation.js +1 -2
  50. package/esm/transport/0_transport.d.ts +1 -2
  51. package/esm/transport/1_transport_abridged.d.ts +1 -1
  52. package/esm/transport/1_transport_abridged.js +1 -1
  53. package/esm/transport/1_transport_intermediate.d.ts +1 -1
  54. package/esm/transport/1_transport_intermediate.js +1 -1
  55. package/esm/transport/2_transport_provider.d.ts +1 -1
  56. package/esm/transport/2_transport_provider.js +1 -1
  57. package/esm/types/!0_file_id.js +6 -9
  58. package/esm/types/!0_misc.d.ts +7 -0
  59. package/esm/types/!0_misc.js +1 -0
  60. package/esm/types/0_audio.d.ts +3 -3
  61. package/esm/types/0_audio.js +1 -1
  62. package/esm/types/0_chat_administrator_rights.d.ts +1 -1
  63. package/esm/types/0_chat_administrator_rights.js +1 -1
  64. package/esm/types/0_chat_photo.d.ts +3 -3
  65. package/esm/types/0_chat_photo.js +1 -1
  66. package/esm/types/0_color.d.ts +2 -0
  67. package/esm/types/0_color.js +16 -0
  68. package/esm/types/0_contact.d.ts +2 -2
  69. package/esm/types/0_dice.d.ts +1 -1
  70. package/esm/types/0_force_reply.d.ts +1 -1
  71. package/esm/types/0_force_reply.js +1 -1
  72. package/esm/types/0_location.d.ts +1 -1
  73. package/esm/types/0_location.js +1 -2
  74. package/esm/types/0_mask_position.d.ts +1 -1
  75. package/esm/types/0_message_entity.d.ts +5 -5
  76. package/esm/types/0_message_entity.js +1 -1
  77. package/esm/types/0_poll_option.d.ts +1 -1
  78. package/esm/types/0_reply_keyboard_remove.d.ts +1 -1
  79. package/esm/types/0_reply_keyboard_remove.js +2 -2
  80. package/esm/types/0_thumbnail.d.ts +2 -2
  81. package/esm/types/0_thumbnail.js +1 -1
  82. package/esm/types/0_venue.d.ts +1 -1
  83. package/esm/types/0_venue.js +1 -2
  84. package/esm/types/0_voice.d.ts +3 -3
  85. package/esm/types/0_web_app_info.d.ts +2 -2
  86. package/esm/types/1_animation.d.ts +3 -3
  87. package/esm/types/1_animation.js +1 -1
  88. package/esm/types/1_chat.d.ts +5 -4
  89. package/esm/types/1_chat.js +8 -9
  90. package/esm/types/1_document.d.ts +4 -4
  91. package/esm/types/1_document.js +1 -1
  92. package/esm/types/1_inline_keyboard_button.d.ts +4 -4
  93. package/esm/types/1_inline_keyboard_button.js +2 -2
  94. package/esm/types/1_keyboard_button.d.ts +8 -8
  95. package/esm/types/1_keyboard_button.js +2 -2
  96. package/esm/types/1_photo.d.ts +2 -2
  97. package/esm/types/1_photo.js +1 -1
  98. package/esm/types/1_poll.d.ts +8 -8
  99. package/esm/types/1_poll.js +1 -1
  100. package/esm/types/1_sticker.d.ts +3 -3
  101. package/esm/types/1_sticker.js +1 -2
  102. package/esm/types/1_user.d.ts +4 -3
  103. package/esm/types/1_user.js +4 -4
  104. package/esm/types/1_video.d.ts +3 -3
  105. package/esm/types/1_video.js +1 -1
  106. package/esm/types/1_video_note.d.ts +2 -2
  107. package/esm/types/1_video_note.js +1 -1
  108. package/esm/types/2_game.d.ts +3 -3
  109. package/esm/types/2_game.js +2 -3
  110. package/esm/types/2_inline_keyboard_markup.d.ts +2 -2
  111. package/esm/types/2_inline_keyboard_markup.js +1 -1
  112. package/esm/types/2_inline_query.d.ts +19 -0
  113. package/esm/types/2_inline_query.js +41 -0
  114. package/esm/types/2_reply_keyboard_markup.d.ts +2 -2
  115. package/esm/types/2_reply_keyboard_markup.js +1 -1
  116. package/esm/types/3_message.d.ts +21 -23
  117. package/esm/types/3_message.js +16 -18
  118. package/esm/types/4_callback_query.d.ts +14 -0
  119. package/esm/types/4_callback_query.js +24 -0
  120. package/esm/utilities/0_base64.js +1 -1
  121. package/esm/utilities/0_crypto.js +1 -1
  122. package/esm/utilities/0_queue.js +1 -1
  123. package/esm/utilities/1_auth.js +1 -1
  124. package/package.json +1 -1
  125. package/script/1_utilities.d.ts +12 -0
  126. package/script/1_utilities.js +28 -0
  127. package/script/2_connection.d.ts +2 -0
  128. package/script/2_connection.js +18 -0
  129. package/script/2_tl.d.ts +10 -0
  130. package/script/2_tl.js +40 -0
  131. package/script/3_storage.d.ts +6 -0
  132. package/script/3_storage.js +22 -0
  133. package/script/3_transport.d.ts +4 -0
  134. package/script/3_transport.js +20 -0
  135. package/script/3_types.d.ts +35 -0
  136. package/script/3_types.js +51 -0
  137. package/script/{constants.d.ts → 4_constants.d.ts} +2 -2
  138. package/script/{constants.js → 4_constants.js} +1 -1
  139. package/script/5_client.d.ts +2 -0
  140. package/script/5_client.js +18 -0
  141. package/script/client/0_html.d.ts +1 -1
  142. package/script/client/0_html.js +2 -2
  143. package/script/client/0_message.d.ts +1 -2
  144. package/script/client/0_message.js +32 -39
  145. package/script/client/0_password.d.ts +2 -2
  146. package/script/client/0_password.js +20 -22
  147. package/script/client/0_utilities.d.ts +3 -5
  148. package/script/client/0_utilities.js +24 -68
  149. package/script/client/1_client_abstract.d.ts +2 -2
  150. package/script/client/1_client_abstract.js +6 -6
  151. package/script/client/2_client_plain.d.ts +3 -3
  152. package/script/client/2_client_plain.js +45 -52
  153. package/script/client/3_client.d.ts +33 -18
  154. package/script/client/3_client.js +291 -303
  155. package/script/connection/0_connection.d.ts +1 -1
  156. package/script/connection/1_connection_web_socket.js +5 -5
  157. package/script/mod.d.ts +7 -21
  158. package/script/mod.js +17 -45
  159. package/script/storage/0_storage.d.ts +4 -5
  160. package/script/storage/0_storage.js +11 -39
  161. package/script/storage/0_utilities.js +6 -6
  162. package/script/storage/1_storage_local_storage.d.ts +1 -1
  163. package/script/storage/1_storage_memory.d.ts +1 -1
  164. package/script/storage/1_storage_session_storage.d.ts +1 -1
  165. package/script/tl/0_tl_raw_reader.js +6 -6
  166. package/script/tl/0_tl_raw_writer.js +7 -7
  167. package/script/tl/1_tl_object.js +3 -3
  168. package/script/tl/3_deserialize.js +2 -2
  169. package/script/tl/3_utilities.d.ts +3 -0
  170. package/script/tl/3_utilities.js +48 -0
  171. package/script/tl/4_tl_writer.js +2 -2
  172. package/script/transport/0_obfuscation.d.ts +2 -2
  173. package/script/transport/0_obfuscation.js +5 -6
  174. package/script/transport/0_transport.d.ts +1 -2
  175. package/script/transport/1_transport_abridged.d.ts +1 -1
  176. package/script/transport/1_transport_abridged.js +3 -3
  177. package/script/transport/1_transport_intermediate.d.ts +1 -1
  178. package/script/transport/1_transport_intermediate.js +3 -3
  179. package/script/transport/2_transport_provider.d.ts +1 -1
  180. package/script/transport/2_transport_provider.js +2 -2
  181. package/script/types/!0_file_id.js +24 -27
  182. package/script/types/!0_misc.d.ts +7 -0
  183. package/script/types/!0_misc.js +2 -0
  184. package/script/types/0_audio.d.ts +3 -3
  185. package/script/types/0_audio.js +2 -25
  186. package/script/types/0_chat_administrator_rights.d.ts +1 -1
  187. package/script/types/0_chat_administrator_rights.js +2 -25
  188. package/script/types/0_chat_photo.d.ts +3 -3
  189. package/script/types/0_chat_photo.js +2 -25
  190. package/script/types/0_color.d.ts +2 -0
  191. package/script/types/{!0_id_color.js → 0_color.js} +10 -10
  192. package/script/types/0_contact.d.ts +2 -2
  193. package/script/types/0_dice.d.ts +1 -1
  194. package/script/types/0_force_reply.d.ts +1 -1
  195. package/script/types/0_force_reply.js +2 -25
  196. package/script/types/0_location.d.ts +1 -1
  197. package/script/types/0_location.js +5 -29
  198. package/script/types/0_mask_position.d.ts +1 -1
  199. package/script/types/0_message_entity.d.ts +5 -5
  200. package/script/types/0_message_entity.js +39 -62
  201. package/script/types/0_poll_option.d.ts +1 -1
  202. package/script/types/0_reply_keyboard_remove.d.ts +1 -1
  203. package/script/types/0_reply_keyboard_remove.js +4 -27
  204. package/script/types/0_thumbnail.d.ts +2 -2
  205. package/script/types/0_thumbnail.js +2 -25
  206. package/script/types/0_venue.d.ts +1 -1
  207. package/script/types/0_venue.js +2 -26
  208. package/script/types/0_voice.d.ts +3 -3
  209. package/script/types/0_web_app_info.d.ts +2 -2
  210. package/script/types/1_animation.d.ts +3 -3
  211. package/script/types/1_animation.js +2 -25
  212. package/script/types/1_chat.d.ts +5 -4
  213. package/script/types/1_chat.js +20 -44
  214. package/script/types/1_document.d.ts +4 -4
  215. package/script/types/1_document.js +2 -25
  216. package/script/types/1_inline_keyboard_button.d.ts +4 -4
  217. package/script/types/1_inline_keyboard_button.js +19 -42
  218. package/script/types/1_keyboard_button.d.ts +8 -8
  219. package/script/types/1_keyboard_button.js +24 -47
  220. package/script/types/1_photo.d.ts +2 -2
  221. package/script/types/1_photo.js +4 -27
  222. package/script/types/1_poll.d.ts +8 -8
  223. package/script/types/1_poll.js +2 -2
  224. package/script/types/1_sticker.d.ts +3 -3
  225. package/script/types/1_sticker.js +6 -30
  226. package/script/types/1_user.d.ts +4 -3
  227. package/script/types/1_user.js +6 -29
  228. package/script/types/1_video.d.ts +3 -3
  229. package/script/types/1_video.js +2 -25
  230. package/script/types/1_video_note.d.ts +2 -2
  231. package/script/types/1_video_note.js +2 -25
  232. package/script/types/2_game.d.ts +3 -3
  233. package/script/types/2_game.js +6 -30
  234. package/script/types/2_inline_keyboard_markup.d.ts +2 -2
  235. package/script/types/2_inline_keyboard_markup.js +3 -26
  236. package/script/types/2_inline_query.d.ts +19 -0
  237. package/script/types/2_inline_query.js +45 -0
  238. package/script/types/2_reply_keyboard_markup.d.ts +2 -2
  239. package/script/types/2_reply_keyboard_markup.js +3 -26
  240. package/script/types/3_message.d.ts +21 -23
  241. package/script/types/3_message.js +94 -119
  242. package/script/types/4_callback_query.d.ts +14 -0
  243. package/script/types/4_callback_query.js +28 -0
  244. package/script/utilities/0_base64.js +3 -3
  245. package/script/utilities/0_crypto.js +3 -3
  246. package/script/utilities/0_queue.js +2 -2
  247. package/script/utilities/1_auth.js +5 -5
  248. package/esm/types/!0_id_color.d.ts +0 -1
  249. package/esm/types/!0_id_color.js +0 -16
  250. package/script/types/!0_id_color.d.ts +0 -1
  251. /package/esm/{deps.d.ts → 0_deps.d.ts} +0 -0
  252. /package/esm/{deps.js → 0_deps.js} +0 -0
  253. /package/script/{deps.d.ts → 0_deps.d.ts} +0 -0
  254. /package/script/{deps.js → 0_deps.js} +0 -0
@@ -1,28 +1,11 @@
1
- import { debug, gunzip, Mutex } from "../deps.js";
2
- 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, ZERO_CHANNEL_ID } from "../constants.js";
3
- import { drop, mustPrompt, mustPromptOneOf } from "../utilities/1_misc.js";
4
- import { bigIntFromBuffer, getRandomBigInt, getRandomId } from "../utilities/0_bigint.js";
5
- import { getChannelChatId, hasChannelPts, hasPts, peerToChatId } from "./0_utilities.js";
6
- import { UNREACHABLE } from "../utilities/0_control.js";
7
- import { Queue } from "../utilities/0_queue.js";
8
- import { sha1 } from "../utilities/0_hash.js";
9
- import { TLError } from "../tl/0_tl_raw_reader.js";
10
- import { as } from "../tl/1_tl_object.js";
11
- import * as types from "../tl/2_types.js";
12
- import { TLReader } from "../tl/3_tl_reader.js";
13
- import * as functions from "../tl/3_functions.js";
14
- import { RPCResult } from "../tl/5_rpc_result.js";
15
- import { Message as Message_ } from "../tl/6_message.js"; // MTProto API message
16
- import { MessageContainer } from "../tl/7_message_container.js";
17
- import { FileID, FileType, ThumbnailSource } from "../types/!0_file_id.js";
18
- import { replyKeyboardRemoveToTlObject } from "../types/0_reply_keyboard_remove.js";
19
- import { messageEntityToTlObject } from "../types/0_message_entity.js";
20
- import { forceReplyToTlObject } from "../types/0_force_reply.js";
21
- import { constructUser } from "../types/1_user.js";
22
- import { inlineKeyboardMarkupToTlObject } from "../types/2_inline_keyboard_markup.js";
23
- import { replyKeyboardMarkupToTlObject } from "../types/2_reply_keyboard_markup.js";
24
- import { constructMessage } from "../types/3_message.js"; // high-level wrapper for Telegram API's message
25
- import { StorageMemory } from "../storage/1_storage_memory.js";
1
+ import { debug, gunzip, Mutex } from "../0_deps.js";
2
+ import { bigIntFromBuffer, drop, getRandomBigInt, getRandomId, mustPrompt, mustPromptOneOf, Queue, sha1, UNREACHABLE } from "../1_utilities.js";
3
+ import { as, functions, getChannelChatId, Message as Message_, // MTProto API message
4
+ MessageContainer, peerToChatId, RPCResult, TLError, TLReader, types, } from "../2_tl.js";
5
+ import { StorageMemory } from "../3_storage.js";
6
+ import { constructCallbackQuery, constructInlineQuery, constructMessage, constructUser, FileID, FileType, forceReplyToTlObject, inlineKeyboardMarkupToTlObject, messageEntityToTlObject, replyKeyboardMarkupToTlObject, replyKeyboardRemoveToTlObject, ThumbnailSource, } from "../3_types.js";
7
+ 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, ZERO_CHANNEL_ID } from "../4_constants.js";
8
+ import { isChannelPtsUpdate, isPtsUpdate } from "./0_utilities.js";
26
9
  import { decryptMessage, encryptMessage, getMessageId } from "./0_message.js";
27
10
  import { checkPassword } from "./0_password.js";
28
11
  import { parseHtml } from "./0_html.js";
@@ -36,6 +19,7 @@ const dRecv = debug("Client/receiveLoop");
36
19
  export const getEntity = Symbol();
37
20
  export const getStickerSetName = Symbol();
38
21
  export const handleMigrationError = Symbol();
22
+ export const getMessageWithReply = Symbol();
39
23
  export const restartAuth = Symbol();
40
24
  export var ParseMode;
41
25
  (function (ParseMode) {
@@ -820,7 +804,7 @@ export class Client extends ClientAbstract {
820
804
  let originalPts = null;
821
805
  const channelPtsMap = new Map();
822
806
  for (const update of updates) {
823
- if (hasPts(update)) {
807
+ if (isPtsUpdate(update)) {
824
808
  if (update.pts == 0) {
825
809
  continue;
826
810
  }
@@ -834,7 +818,7 @@ export class Client extends ClientAbstract {
834
818
  localState.pts = update.pts;
835
819
  }
836
820
  }
837
- else if (hasChannelPts(update)) {
821
+ else if (isChannelPtsUpdate(update)) {
838
822
  if (update.pts == 0) {
839
823
  continue;
840
824
  }
@@ -1304,13 +1288,7 @@ export class Client extends ClientAbstract {
1304
1288
  const noWebpage = params?.disableWebPagePreview ? true : undefined;
1305
1289
  await this.invoke(new functions.MessagesEditMessage({ id, peer, entities, message, noWebpage, replyMarkup }));
1306
1290
  }
1307
- /**
1308
- * Retrieve multiple messages.
1309
- *
1310
- * @param chatId The identifier of the chat to retrieve the messages from.
1311
- * @param messageIds The identifiers of the messages to retrieve.
1312
- */
1313
- async getMessages(chatId_, messageIds) {
1291
+ async getMessagesInner(chatId_, messageIds) {
1314
1292
  const peer = await this.getInputPeer(chatId_);
1315
1293
  let messages_ = new Array();
1316
1294
  const chatId = peerToChatId(peer);
@@ -1341,10 +1319,25 @@ export class Client extends ClientAbstract {
1341
1319
  }
1342
1320
  const messages = new Array();
1343
1321
  for (const message_ of messages_) {
1344
- messages.push(await constructMessage(message_, this[getEntity].bind(this), null, this[getStickerSetName].bind(this)));
1322
+ const message = await constructMessage(message_, this[getEntity].bind(this), null, this[getStickerSetName].bind(this));
1323
+ const isReplyToMessage = message_ instanceof types.Message && message_.replyTo instanceof types.MessageReplyHeader;
1324
+ messages.push({ message, isReplyToMessage });
1345
1325
  }
1346
1326
  return messages;
1347
1327
  }
1328
+ /**
1329
+ * Retrieve multiple messages.
1330
+ *
1331
+ * @param chatId The identifier of the chat to retrieve the messages from.
1332
+ * @param messageIds The identifiers of the messages to retrieve.
1333
+ */
1334
+ async getMessages(chatId_, messageIds) {
1335
+ return await this.getMessagesInner(chatId_, messageIds).then((v) => v.map((v) => v.message));
1336
+ }
1337
+ async [getMessageWithReply](chatId, messageId) {
1338
+ const messages = await this.getMessagesInner(chatId, [messageId]);
1339
+ return messages[0]?.message ?? null;
1340
+ }
1348
1341
  /**
1349
1342
  * Retrieve a single message.
1350
1343
  *
@@ -1524,6 +1517,12 @@ export class Client extends ClientAbstract {
1524
1517
  await this.handler({ deletedMessages: deletedMessages }, resolve);
1525
1518
  }
1526
1519
  }
1520
+ if (update instanceof types.UpdateBotCallbackQuery || update instanceof types.UpdateInlineBotCallbackQuery) {
1521
+ await this.handler({ callbackQuery: await constructCallbackQuery(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }, resolve);
1522
+ }
1523
+ else if (update instanceof types.UpdateBotInlineQuery) {
1524
+ await this.handler({ inlineQuery: await constructInlineQuery(update, this[getEntity].bind(this)) }, resolve);
1525
+ }
1527
1526
  }
1528
1527
  use(middleware) {
1529
1528
  const handler = this.handler;
@@ -1560,5 +1559,18 @@ export class Client extends ClientAbstract {
1560
1559
  }
1561
1560
  });
1562
1561
  }
1562
+ /**
1563
+ * Answer a callback query. Bot-only.
1564
+ *
1565
+ * @param id ID of the callback query to answer.
1566
+ */
1567
+ async answerCallbackQuery(id, params) {
1568
+ await this.invoke(new functions.MessagesSetBotCallbackAnswer({
1569
+ queryId: BigInt(id),
1570
+ cacheTime: params?.cacheTime ?? 0,
1571
+ message: params?.text,
1572
+ alert: params?.alert ? true : undefined,
1573
+ }));
1574
+ }
1563
1575
  }
1564
1576
  const resolve = () => Promise.resolve();
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../utilities/0_types.js";
1
+ import { MaybePromise } from "../1_utilities.js";
2
2
  declare abstract class Foundation {
3
3
  abstract get connected(): boolean;
4
4
  stateChangeHandler?: (connected: boolean) => void;
@@ -1,5 +1,5 @@
1
1
  import * as dntShim from "../_dnt.shims.js";
2
- import { debug, Mutex } from "../deps.js";
2
+ import { debug, Mutex } from "../0_deps.js";
3
3
  import { ConnectionUnframed } from "./0_connection.js";
4
4
  const d = debug("ConnectionWebSocket");
5
5
  export class ConnectionWebSocket extends ConnectionUnframed {
package/esm/mod.d.ts CHANGED
@@ -1,26 +1,12 @@
1
- import { getRandomId } from "./utilities/0_bigint.js";
1
+ import { getRandomId } from "./1_utilities.js";
2
2
  import { checkPassword } from "./client/0_password.js";
3
3
  export declare const utils: {
4
4
  checkPassword: typeof checkPassword;
5
5
  getRandomId: typeof getRandomId;
6
6
  };
7
- export { as, serialize } from "./tl/1_tl_object.js";
8
- export * as types from "./tl/2_types.js";
9
- export * as functions from "./tl/3_functions.js";
10
- export * from "./tl/5_rpc_result.js";
11
- export * from "./tl/6_message.js";
12
- export * from "./tl/7_message_container.js";
13
- export * from "./client/2_client_plain.js";
14
- export * from "./client/3_client.js";
15
- export * from "./storage/0_storage.js";
16
- export * from "./storage/1_storage_memory.js";
17
- export * from "./storage/1_storage_local_storage.js";
18
- export * from "./storage/1_storage_session_storage.js";
19
- export * from "./storage/1_storage_indexed_db.js";
20
- export * from "./transport/1_transport_abridged.js";
21
- export * from "./transport/1_transport_intermediate.js";
22
- export * from "./transport/0_transport.js";
23
- export * from "./transport/2_transport_provider.js";
24
- export * from "./connection/0_connection.js";
25
- export * from "./connection/1_connection_web_socket.js";
26
- export { APP_VERSION, DEVICE_MODEL, INITIAL_DC, LANG_CODE, LANG_PACK, LAYER, SYSTEM_LANG_CODE, SYSTEM_VERSION } from "./constants.js";
7
+ export * from "./2_tl.js";
8
+ export * from "./2_connection.js";
9
+ export * from "./3_storage.js";
10
+ export * from "./3_transport.js";
11
+ export { APP_VERSION, DEVICE_MODEL, INITIAL_DC, LANG_CODE, LANG_PACK, LAYER, SYSTEM_LANG_CODE, SYSTEM_VERSION } from "./4_constants.js";
12
+ export * from "./5_client.js";
package/esm/mod.js CHANGED
@@ -1,23 +1,9 @@
1
- import { getRandomId } from "./utilities/0_bigint.js";
1
+ import { getRandomId } from "./1_utilities.js";
2
2
  import { checkPassword } from "./client/0_password.js";
3
3
  export const utils = { checkPassword, getRandomId };
4
- export { as, serialize } from "./tl/1_tl_object.js";
5
- export * as types from "./tl/2_types.js";
6
- export * as functions from "./tl/3_functions.js";
7
- export * from "./tl/5_rpc_result.js";
8
- export * from "./tl/6_message.js";
9
- export * from "./tl/7_message_container.js";
10
- export * from "./client/2_client_plain.js";
11
- export * from "./client/3_client.js";
12
- export * from "./storage/0_storage.js";
13
- export * from "./storage/1_storage_memory.js";
14
- export * from "./storage/1_storage_local_storage.js";
15
- export * from "./storage/1_storage_session_storage.js";
16
- export * from "./storage/1_storage_indexed_db.js";
17
- export * from "./transport/1_transport_abridged.js";
18
- export * from "./transport/1_transport_intermediate.js";
19
- export * from "./transport/0_transport.js";
20
- export * from "./transport/2_transport_provider.js";
21
- export * from "./connection/0_connection.js";
22
- export * from "./connection/1_connection_web_socket.js";
23
- export { APP_VERSION, DEVICE_MODEL, INITIAL_DC, LANG_CODE, LANG_PACK, LAYER, SYSTEM_LANG_CODE, SYSTEM_VERSION } from "./constants.js";
4
+ export * from "./2_tl.js";
5
+ export * from "./2_connection.js";
6
+ export * from "./3_storage.js";
7
+ export * from "./3_transport.js";
8
+ export { APP_VERSION, DEVICE_MODEL, INITIAL_DC, LANG_CODE, LANG_PACK, LAYER, SYSTEM_LANG_CODE, SYSTEM_VERSION } from "./4_constants.js";
9
+ export * from "./5_client.js";
@@ -1,7 +1,6 @@
1
- import { MaybePromise } from "../utilities/0_types.js";
2
- import { DC } from "../transport/2_transport_provider.js";
3
- import { TLObject } from "../tl/1_tl_object.js";
4
- import * as types from "../tl/2_types.js";
1
+ import { MaybePromise } from "../1_utilities.js";
2
+ import { TLObject, types } from "../2_tl.js";
3
+ import { DC } from "../3_transport.js";
5
4
  export type StorageKeyPart = string | number | bigint | Uint8Array;
6
5
  export declare abstract class Storage {
7
6
  private _authKeyId;
@@ -21,7 +20,7 @@ export declare abstract class Storage {
21
20
  updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
22
21
  getUsername(username: string): Promise<["channel" | "user", bigint, Date] | null>;
23
22
  setTlObject(key: readonly StorageKeyPart[], value: TLObject | null): Promise<void>;
24
- getTLObject(key: readonly StorageKeyPart[]): Promise<import("../tl/3_tl_reader.js").ReadObject | null>;
23
+ getTLObject(key: readonly StorageKeyPart[]): Promise<import("../2_tl.js").ReadObject | null>;
25
24
  setState(state: types.UpdatesState): Promise<void>;
26
25
  getState(): Promise<types.UpdatesState | null>;
27
26
  setMessage(chatId: number, messageId: number, message: types.TypeMessage | null): Promise<void>;
@@ -1,11 +1,6 @@
1
- import { UNREACHABLE } from "../utilities/0_control.js";
2
- import { sha1 } from "../utilities/0_hash.js";
3
- import { bigIntFromBuffer } from "../utilities/0_bigint.js";
4
- import { serialize } from "../tl/1_tl_object.js";
5
- import * as types from "../tl/2_types.js";
6
- import { TLReader } from "../tl/3_tl_reader.js";
7
- import { rleDecode, rleEncode } from "../utilities/0_rle.js";
8
- import { ZERO_CHANNEL_ID } from "../constants.js";
1
+ import { bigIntFromBuffer, rleDecode, rleEncode, sha1, UNREACHABLE } from "../1_utilities.js";
2
+ import { serialize, TLReader, types } from "../2_tl.js";
3
+ import { ZERO_CHANNEL_ID } from "../4_constants.js";
9
4
  const KPARTS__DC = ["dc"];
10
5
  const KPARTS__AUTH_KEY = ["authKey"];
11
6
  const KPARTS__CHANNEL_ACCESS_HASH = (v) => ["channelAccessHash", v];
@@ -1,5 +1,5 @@
1
- import { base64Decode, base64Encode } from "../deps.js";
2
- import { UNREACHABLE } from "../utilities/0_control.js";
1
+ import { base64Decode, base64Encode } from "../0_deps.js";
2
+ import { UNREACHABLE } from "../1_utilities.js";
3
3
  export var ValueType;
4
4
  (function (ValueType) {
5
5
  ValueType[ValueType["Boolean"] = 0] = "Boolean";
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../utilities/0_types.js";
1
+ import { MaybePromise } from "../1_utilities.js";
2
2
  import { Storage, StorageKeyPart } from "./0_storage.js";
3
3
  export declare class StorageLocalStorage extends Storage implements Storage {
4
4
  private readonly prefix;
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../utilities/0_types.js";
1
+ import { MaybePromise } from "../1_utilities.js";
2
2
  import { Storage, StorageKeyPart } from "./0_storage.js";
3
3
  export declare class StorageMemory extends Storage implements Storage {
4
4
  protected map: Map<string, unknown>;
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../utilities/0_types.js";
1
+ import { MaybePromise } from "../1_utilities.js";
2
2
  import { Storage, StorageKeyPart } from "./0_storage.js";
3
3
  export declare class StorageSessionStorage extends Storage implements Storage {
4
4
  private readonly prefix;
@@ -1,4 +1,4 @@
1
- import { bigIntFromBuffer } from "../utilities/0_bigint.js";
1
+ import { bigIntFromBuffer } from "../1_utilities.js";
2
2
  export class TLError extends Error {
3
3
  }
4
4
  export class TLRawReader {
@@ -1,4 +1,4 @@
1
- import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
1
+ import { bufferFromBigInt, concat } from "../1_utilities.js";
2
2
  export class TLRawWriter {
3
3
  constructor() {
4
4
  Object.defineProperty(this, "_buffer", {
@@ -1,4 +1,4 @@
1
- import { assertEquals, assertFalse } from "../deps.js";
1
+ import { assertEquals, assertFalse } from "../0_deps.js";
2
2
  import { TLRawWriter } from "./0_tl_raw_writer.js";
3
3
  export const flags = Symbol("flags");
4
4
  export const id = Symbol("id");
@@ -1,4 +1,4 @@
1
- import { assertEquals } from "../deps.js";
1
+ import { assertEquals } from "../0_deps.js";
2
2
  import { analyzeOptionalParam, flags, isOptionalParam, isTLObjectConstructor, paramDesc } from "./1_tl_object.js";
3
3
  import { map } from "./2_types.js";
4
4
  function deserializeSingleParam(reader, type, ntype) {
@@ -0,0 +1,3 @@
1
+ import * as types from "./2_types.js";
2
+ export declare function getChannelChatId(channelId: bigint): number;
3
+ export declare function peerToChatId(peer: types.TypePeer | types.TypeInputPeer): number;
@@ -0,0 +1,20 @@
1
+ import { UNREACHABLE } from "../1_utilities.js";
2
+ import { ZERO_CHANNEL_ID } from "../4_constants.js";
3
+ import * as types from "./2_types.js";
4
+ export function getChannelChatId(channelId) {
5
+ return ZERO_CHANNEL_ID + -Number(channelId);
6
+ }
7
+ export function peerToChatId(peer) {
8
+ if (peer instanceof types.PeerUser || peer instanceof types.InputPeerUser) {
9
+ return Number(peer.userId);
10
+ }
11
+ else if (peer instanceof types.PeerChat || peer instanceof types.InputPeerChat) {
12
+ return -Number(peer.chatId);
13
+ }
14
+ else if (peer instanceof types.PeerChannel || peer instanceof types.InputPeerChannel) {
15
+ return getChannelChatId(peer.channelId);
16
+ }
17
+ else {
18
+ UNREACHABLE();
19
+ }
20
+ }
@@ -1,4 +1,4 @@
1
- import { VECTOR_CONSTRUCTOR } from "../constants.js";
1
+ import { VECTOR_CONSTRUCTOR } from "../4_constants.js";
2
2
  import { TLRawWriter } from "./0_tl_raw_writer.js";
3
3
  import { serialize } from "./1_tl_object.js";
4
4
  export class TLWriter extends TLRawWriter {
@@ -1,5 +1,5 @@
1
- import { CTR } from "../utilities/0_crypto.js";
2
- import { Connection } from "../connection/0_connection.js";
1
+ import { CTR } from "../1_utilities.js";
2
+ import { Connection } from "../2_connection.js";
3
3
  export declare function getObfuscationParameters(protocol: number, connection: Connection): Promise<{
4
4
  encryptionCTR: CTR;
5
5
  decryptionCTR: CTR;
@@ -1,6 +1,5 @@
1
1
  import * as dntShim from "../_dnt.shims.js";
2
- import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
3
- import { CTR } from "../utilities/0_crypto.js";
2
+ import { bufferFromBigInt, concat, CTR } from "../1_utilities.js";
4
3
  export async function getObfuscationParameters(protocol, connection) {
5
4
  const dc = 0xFCFF;
6
5
  let init;
@@ -1,5 +1,4 @@
1
- import { MaybePromise } from "../utilities/0_types.js";
2
- import { CTR } from "../utilities/0_crypto.js";
1
+ import { CTR, MaybePromise } from "../1_utilities.js";
3
2
  export declare abstract class Transport {
4
3
  protected initialized: boolean;
5
4
  protected obfuscationParameters: {
@@ -1,4 +1,4 @@
1
- import { Connection } from "../connection/0_connection.js";
1
+ import { Connection } from "../2_connection.js";
2
2
  import { Transport } from "./0_transport.js";
3
3
  export declare class TransportAbridged extends Transport implements Transport {
4
4
  private readonly connection;
@@ -1,4 +1,4 @@
1
- import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
1
+ import { bufferFromBigInt, concat } from "../1_utilities.js";
2
2
  import { getObfuscationParameters } from "./0_obfuscation.js";
3
3
  import { Transport } from "./0_transport.js";
4
4
  export class TransportAbridged extends Transport {
@@ -1,4 +1,4 @@
1
- import { Connection } from "../connection/0_connection.js";
1
+ import { Connection } from "../2_connection.js";
2
2
  import { Transport } from "./0_transport.js";
3
3
  export declare class TransportIntermediate extends Transport implements Transport {
4
4
  private readonly connection;
@@ -1,4 +1,4 @@
1
- import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
1
+ import { bufferFromBigInt, concat } from "../1_utilities.js";
2
2
  import { getObfuscationParameters } from "./0_obfuscation.js";
3
3
  import { Transport } from "./0_transport.js";
4
4
  export class TransportIntermediate extends Transport {
@@ -1,4 +1,4 @@
1
- import { Connection } from "../connection/0_connection.js";
1
+ import { Connection } from "../2_connection.js";
2
2
  import { Transport } from "./0_transport.js";
3
3
  export type DC = "1" | "2" | "3" | "4" | "5" | "1-test" | "2-test" | "3-test";
4
4
  export interface TransportProviderParams {
@@ -1,4 +1,4 @@
1
- import { ConnectionWebSocket } from "../connection/1_connection_web_socket.js";
1
+ import { ConnectionWebSocket } from "../2_connection.js";
2
2
  import { TransportIntermediate } from "./1_transport_intermediate.js";
3
3
  const dcToNameMap = {
4
4
  "1": "pluto",
@@ -1,9 +1,6 @@
1
1
  // Direct port from Pyrogram
2
- import { base64DecodeUrlSafe, base64EncodeUrlSafe } from "../utilities/0_base64.js";
3
- import { UNREACHABLE } from "../utilities/0_control.js";
4
- import { rleDecode, rleEncode } from "../utilities/0_rle.js";
5
- import { TLRawWriter } from "../tl/0_tl_raw_writer.js";
6
- import { TLRawReader } from "../tl/0_tl_raw_reader.js";
2
+ import { base64DecodeUrlSafe, base64EncodeUrlSafe, rleDecode, rleEncode, UNREACHABLE } from "../1_utilities.js";
3
+ import { TLReader, TLWriter } from "../2_tl.js";
7
4
  export var FileType;
8
5
  (function (FileType) {
9
6
  FileType[FileType["Thumbnail"] = 0] = "Thumbnail";
@@ -96,7 +93,7 @@ class FileID {
96
93
  minor = decoded[decoded.length - 2];
97
94
  buffer = decoded.slice(0, -2);
98
95
  }
99
- const reader = new TLRawReader(buffer);
96
+ const reader = new TLReader(buffer);
100
97
  let fileType = reader.readInt32();
101
98
  const dcId = reader.readInt32();
102
99
  const hasWebLocation = Boolean(fileType & WEB_LOCATION_FLAG);
@@ -159,7 +156,7 @@ class FileID {
159
156
  encode(major, minor) {
160
157
  major ??= this.major;
161
158
  minor ??= this.minor;
162
- const writer = new TLRawWriter();
159
+ const writer = new TLWriter();
163
160
  let fileType = this.fileType;
164
161
  if (this.params.url) {
165
162
  fileType |= WEB_LOCATION_FLAG;
@@ -274,7 +271,7 @@ export class FileUniqueID {
274
271
  });
275
272
  }
276
273
  static decode(fileId) {
277
- const reader = new TLRawReader(rleDecode(base64DecodeUrlSafe(fileId)));
274
+ const reader = new TLReader(rleDecode(base64DecodeUrlSafe(fileId)));
278
275
  const fileUniqueType = reader.readInt32();
279
276
  switch (fileUniqueType) {
280
277
  case FileUniqueType.Web: {
@@ -295,7 +292,7 @@ export class FileUniqueID {
295
292
  }
296
293
  }
297
294
  encode() {
298
- const writer = new TLRawWriter();
295
+ const writer = new TLWriter();
299
296
  writer.writeInt32(this.fileUniqueType);
300
297
  switch (this.fileUniqueType) {
301
298
  case FileUniqueType.Web:
@@ -0,0 +1,7 @@
1
+ import { MaybePromise } from "../1_utilities.js";
2
+ import { types } from "../2_tl.js";
3
+ export interface EntityGetter {
4
+ (peer: types.PeerUser): MaybePromise<types.User | null>;
5
+ (peer: types.PeerChat): MaybePromise<types.Chat | null>;
6
+ (peer: types.PeerChannel): MaybePromise<types.Channel | null>;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,10 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  import { Thumbnail } from "./0_thumbnail.js";
3
3
  /** This object represents an audio file to be treated as music by the Telegram clients. */
4
4
  export interface Audio {
5
5
  /** Identifier for this file, which can be used to download or reuse the file */
6
6
  fileId: string;
7
- /** Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. */
7
+ /** Unique identifier for this file, which is supposed to be the same over time and for different users and bots. Can't be used to download or reuse the file. */
8
8
  fileUniqueId: string;
9
9
  /** Duration of the audio in seconds as defined by sender */
10
10
  duration: number;
@@ -14,7 +14,7 @@ export interface Audio {
14
14
  title?: string;
15
15
  /** MIME type of the file as defined by sender */
16
16
  mimeType: string;
17
- /** File size in bytes. It can be bigger than 2^31 and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this value. */
17
+ /** File size in bytes */
18
18
  fileSize: number;
19
19
  /** Thumbnail of the album cover to which the music file belongs */
20
20
  thumbnails: Thumbnail[];
@@ -1,4 +1,4 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  import { constructThumbnail } from "./0_thumbnail.js";
3
3
  export function constructAudio(document, audioAttribute, fileId, fileUniqueId) {
4
4
  return {
@@ -1,4 +1,4 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  /** Represents the rights of an administrator in a chat. */
3
3
  export interface ChatAdministratorRights {
4
4
  /** True, if the user's presence in the chat is hidden */
@@ -1,4 +1,4 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  export function constructChatAdministratorRights(rights_) {
3
3
  const rights = {
4
4
  isAnonymous: rights_.anonymous || false,
@@ -1,13 +1,13 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  export declare namespace ChatPhoto {
3
3
  interface Base {
4
4
  /** File identifier of small (160x160) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed. */
5
5
  smallFileId: string;
6
- /** Unique file identifier of small (160x160) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. */
6
+ /** Unique file identifier of small (160x160) chat photo, which is supposed to be the same over time and for different users and bots. Can't be used to download or reuse the file. */
7
7
  smallFileUniqueId: string;
8
8
  /** File identifier of big (640x640) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed. */
9
9
  bigFileId: string;
10
- /** Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. */
10
+ /** Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different users and bots. Can't be used to download or reuse the file. */
11
11
  bigFileUniqueId: string;
12
12
  /** True, if an [animated profile picture](https://core.telegram.org/api/files#animated-profile-pictures) is available for the user */
13
13
  hasVideo: boolean;
@@ -1,4 +1,4 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  import { FileID, FileType, FileUniqueID, FileUniqueType, ThumbnailSource } from "./!0_file_id.js";
3
3
  export function constructChatPhoto(photo, chatId, chatAccessHash) {
4
4
  const smallFileId = new FileID(null, null, FileType.ChatPhoto, photo.dcId, {
@@ -0,0 +1,2 @@
1
+ export type Color = "red" | "orange" | "violet" | "green" | "cyan" | "blue" | "pink";
2
+ export declare function getColor(id: number): Color;
@@ -0,0 +1,16 @@
1
+ const colors = [
2
+ "red",
3
+ "orange",
4
+ "violet",
5
+ "green",
6
+ "cyan",
7
+ "blue",
8
+ "pink",
9
+ ];
10
+ export function getColor(id) {
11
+ id = Number(String(id).replaceAll("-100", "-"));
12
+ if (id < 0) {
13
+ id = -id;
14
+ }
15
+ return colors[id % 7];
16
+ }
@@ -1,4 +1,4 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  /** This object represents a phone contact. */
3
3
  export interface Contact {
4
4
  /** Contact's phone number */
@@ -7,7 +7,7 @@ export interface Contact {
7
7
  firstName: string;
8
8
  /** Contact's last name */
9
9
  lastName?: string;
10
- /** Contact's user identifier in Telegram. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. */
10
+ /** Contact's user identifier in Telegram */
11
11
  userId?: number;
12
12
  /** Additional data about the contact in the form of a [vCard](https://en.wikipedia.org/wiki/VCard) */
13
13
  vcard?: string;
@@ -1,4 +1,4 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  /** This object represents an animated emoji that displays a random value. */
3
3
  export interface Dice {
4
4
  /** Emoji on which the dice throw animation is based */
@@ -1,4 +1,4 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  /** Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot's message and tapped 'Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode. */
3
3
  export interface ForceReply {
4
4
  /** Shows reply interface to the user, as if they manually selected the bot's message and tapped 'Reply' */
@@ -1,4 +1,4 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  export function constructForceReply(replyMarkup_) {
3
3
  const replyMarkup = { forceReply: true };
4
4
  if (replyMarkup_.placeholder) {
@@ -1,4 +1,4 @@
1
- import * as types from "../tl/2_types.js";
1
+ import { types } from "../2_tl.js";
2
2
  /** This object represents a point on the map. */
3
3
  export interface Location {
4
4
  /** Latitude as defined by sender */