@mtkruto/node 0.1.157 → 0.1.161

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 (83) hide show
  1. package/esm/4_constants.d.ts +2 -2
  2. package/esm/4_constants.js +2 -2
  3. package/esm/client/1_composer.d.ts +2 -2
  4. package/esm/client/1_composer.js +4 -4
  5. package/esm/client/1_file_manager.js +53 -56
  6. package/esm/client/2_message_manager.js +8 -11
  7. package/esm/client/4_client.d.ts +2 -2
  8. package/esm/client/4_client.js +4 -4
  9. package/esm/tl/2_types.d.ts +596 -1
  10. package/esm/tl/2_types.js +1824 -319
  11. package/esm/tl/3_functions.d.ts +374 -2
  12. package/esm/tl/3_functions.js +943 -31
  13. package/esm/types/0__file_id.d.ts +79 -54
  14. package/esm/types/0__file_id.js +259 -277
  15. package/esm/types/0_chat_photo.js +15 -21
  16. package/esm/types/0_giveaway_parameters.d.ts +5 -0
  17. package/esm/types/0_login_url.d.ts +4 -0
  18. package/esm/types/0_message_reference.d.ts +2 -0
  19. package/esm/types/0_price_tag.d.ts +2 -0
  20. package/esm/types/0_thumbnail.js +16 -14
  21. package/esm/types/1_giveaway.d.ts +2 -0
  22. package/esm/types/1_inline_query_result_button.d.ts +3 -0
  23. package/esm/types/1_photo.js +20 -14
  24. package/esm/types/1_poll.d.ts +13 -0
  25. package/esm/types/1_reaction_count.d.ts +2 -0
  26. package/esm/types/1_reply_quote.d.ts +3 -0
  27. package/esm/types/1_user.d.ts +13 -13
  28. package/esm/types/2_chosen_inline_result.d.ts +5 -0
  29. package/esm/types/2_game.d.ts +6 -0
  30. package/esm/types/2_game.js +11 -7
  31. package/esm/types/2_inactive_chat.d.ts +3 -0
  32. package/esm/types/2_inline_query.d.ts +6 -0
  33. package/esm/types/2_message_interactions.d.ts +5 -0
  34. package/esm/types/2_message_reaction_count.d.ts +4 -0
  35. package/esm/types/2_message_reactions.d.ts +7 -0
  36. package/esm/types/2_story_content.js +4 -7
  37. package/esm/types/4_inline_query_result.js +5 -5
  38. package/esm/types/4_message.js +24 -19
  39. package/esm/types/5_callback_query.d.ts +7 -0
  40. package/esm/utilities/0_buffer.d.ts +1 -1
  41. package/esm/utilities/0_buffer.js +26 -24
  42. package/package.json +1 -1
  43. package/script/4_constants.d.ts +2 -2
  44. package/script/4_constants.js +2 -2
  45. package/script/client/1_composer.d.ts +2 -2
  46. package/script/client/1_composer.js +4 -4
  47. package/script/client/1_file_manager.js +52 -55
  48. package/script/client/2_message_manager.js +6 -9
  49. package/script/client/4_client.d.ts +2 -2
  50. package/script/client/4_client.js +4 -4
  51. package/script/tl/2_types.d.ts +596 -1
  52. package/script/tl/2_types.js +1904 -345
  53. package/script/tl/3_functions.d.ts +374 -2
  54. package/script/tl/3_functions.js +977 -41
  55. package/script/types/0__file_id.d.ts +79 -54
  56. package/script/types/0__file_id.js +263 -280
  57. package/script/types/0_chat_photo.js +14 -20
  58. package/script/types/0_giveaway_parameters.d.ts +5 -0
  59. package/script/types/0_login_url.d.ts +4 -0
  60. package/script/types/0_message_reference.d.ts +2 -0
  61. package/script/types/0_price_tag.d.ts +2 -0
  62. package/script/types/0_thumbnail.js +15 -13
  63. package/script/types/1_giveaway.d.ts +2 -0
  64. package/script/types/1_inline_query_result_button.d.ts +3 -0
  65. package/script/types/1_photo.js +19 -13
  66. package/script/types/1_poll.d.ts +13 -0
  67. package/script/types/1_reaction_count.d.ts +2 -0
  68. package/script/types/1_reply_quote.d.ts +3 -0
  69. package/script/types/1_user.d.ts +13 -13
  70. package/script/types/2_chosen_inline_result.d.ts +5 -0
  71. package/script/types/2_game.d.ts +6 -0
  72. package/script/types/2_game.js +10 -6
  73. package/script/types/2_inactive_chat.d.ts +3 -0
  74. package/script/types/2_inline_query.d.ts +6 -0
  75. package/script/types/2_message_interactions.d.ts +5 -0
  76. package/script/types/2_message_reaction_count.d.ts +4 -0
  77. package/script/types/2_message_reactions.d.ts +7 -0
  78. package/script/types/2_story_content.js +3 -6
  79. package/script/types/4_inline_query_result.js +4 -4
  80. package/script/types/4_message.js +23 -18
  81. package/script/types/5_callback_query.d.ts +7 -0
  82. package/script/utilities/0_buffer.d.ts +1 -1
  83. package/script/utilities/0_buffer.js +26 -24
@@ -1,5 +1,7 @@
1
1
  /** A price tag. */
2
2
  export interface PriceTag {
3
+ /** Portion label. */
3
4
  label: string;
5
+ /** Price of the product in the smallest units of the currency (integer, not float/double). */
4
6
  amount: number;
5
7
  }
@@ -1,21 +1,23 @@
1
1
  import { types } from "../2_tl.js";
2
- import { FileID, FileType, FileUniqueID, FileUniqueType, ThumbnailSource } from "./0__file_id.js";
2
+ import { FileType, PhotoSourceType, serializeFileId, toUniqueFileId } from "./0__file_id.js";
3
3
  export function constructThumbnail(size, file) {
4
4
  const fileType = file instanceof types.Photo ? FileType.Photo : FileType.Document;
5
- const fileId = new FileID(null, null, fileType, file.dc_id, {
6
- mediaId: file.id,
7
- accessHash: file.access_hash,
8
- fileReference: file.file_reference,
9
- thumbnailFileType: fileType,
10
- thumbnailSource: ThumbnailSource.Thumbnail,
11
- thumbnailSize: size.type,
12
- volumeId: 0n,
13
- localId: 0,
14
- }).encode();
15
- const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: file.id }).encode();
5
+ const fileId_ = file instanceof types.Photo
6
+ ? {
7
+ type: FileType.Photo,
8
+ dcId: file.dc_id,
9
+ fileReference: file.file_reference,
10
+ location: { type: "photo", id: file.id, accessHash: file.access_hash, source: { type: PhotoSourceType.Thumbnail, fileType, thumbnailType: size.type.charCodeAt(0) } },
11
+ }
12
+ : {
13
+ type: FileType.Photo,
14
+ dcId: file.dc_id,
15
+ fileReference: file.file_reference,
16
+ location: { type: "common", id: file.id, accessHash: file.access_hash },
17
+ };
16
18
  return {
17
- fileId,
18
- fileUniqueId,
19
+ fileId: serializeFileId(fileId_),
20
+ fileUniqueId: toUniqueFileId(fileId_),
19
21
  width: size.w,
20
22
  height: size.h,
21
23
  fileSize: size.size,
@@ -3,7 +3,9 @@ import { GiveawayParameters } from "./0_giveaway_parameters.js";
3
3
  /** A giveaway. */
4
4
  export interface Giveaway {
5
5
  parameters: GiveawayParameters;
6
+ /** The quantity of the Telegram Premium subscriptions that will be given away.. */
6
7
  winnerCount: number;
8
+ /** The duration of each Telegram Premium subscription that is to be given away in months. */
7
9
  monthCount: number;
8
10
  }
9
11
  export declare function constructGiveaway(g: types.MessageMediaGiveaway): Giveaway;
@@ -1,7 +1,10 @@
1
1
  import { MiniAppInfo } from "./0_mini_app_info.js";
2
2
  /** A button to be shown along with the results of an inline query. */
3
3
  export interface InlineQueryResultButton {
4
+ /** Label text on the button. */
4
5
  text: string;
6
+ /** Description of the Mini App that will be launched when the user presses the button. */
5
7
  miniApp?: MiniAppInfo;
8
+ /** Deep linking parameter for the /start message. */
6
9
  startParameter?: string;
7
10
  }
@@ -1,5 +1,6 @@
1
1
  import { types } from "../2_tl.js";
2
- import { FileID, FileType, FileUniqueID, FileUniqueType, ThumbnailSource } from "./0__file_id.js";
2
+ import { PhotoSourceType } from "./0__file_id.js";
3
+ import { FileType, serializeFileId, toUniqueFileId } from "./0__file_id.js";
3
4
  import { constructThumbnail } from "./0_thumbnail.js";
4
5
  export function constructPhoto(photo) {
5
6
  const sizes = photo.sizes
@@ -14,20 +15,25 @@ export function constructPhoto(photo) {
14
15
  .filter((v) => v instanceof types.PhotoSize)
15
16
  .sort((a, b) => a.size - b.size);
16
17
  const largest = sizes.slice(-1)[0];
17
- const { dc_id: dcId, id: mediaId, access_hash: accessHash, file_reference: fileReference } = photo;
18
- const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: photo.id }).encode();
19
- return {
20
- fileId: new FileID(null, null, FileType.Photo, dcId, {
21
- mediaId,
18
+ const { dc_id: dcId, id, access_hash: accessHash, file_reference: fileReference } = photo;
19
+ const fileId_ = {
20
+ type: FileType.Photo,
21
+ dcId,
22
+ fileReference,
23
+ location: {
24
+ type: "photo",
25
+ id,
22
26
  accessHash,
23
- fileReference,
24
- thumbnailSource: ThumbnailSource.Thumbnail,
25
- thumbnailFileType: FileType.Photo,
26
- thumbnailSize: largest.type,
27
- volumeId: 0n,
28
- localId: 0,
29
- }).encode(),
30
- fileUniqueId,
27
+ source: {
28
+ type: PhotoSourceType.Thumbnail,
29
+ fileType: FileType.Photo,
30
+ thumbnailType: largest.type.charCodeAt(0),
31
+ },
32
+ },
33
+ };
34
+ return {
35
+ fileId: serializeFileId(fileId_),
36
+ fileUniqueId: toUniqueFileId(fileId_),
31
37
  width: largest.w,
32
38
  height: largest.h,
33
39
  fileSize: largest.size,
@@ -3,18 +3,31 @@ import { MessageEntity } from "./0_message_entity.js";
3
3
  import { PollOption } from "./0_poll_option.js";
4
4
  /** A poll. */
5
5
  export interface Poll {
6
+ /** The identifier of the poll. */
6
7
  id: string;
8
+ /** The poll's question. */
7
9
  question: string;
10
+ /** The poll's options. */
8
11
  options: PollOption[];
12
+ /** The number of users who have participated in the poll. */
9
13
  totalVoterCount: number;
14
+ /** Whether the poll is closed. */
10
15
  isClosed: boolean;
16
+ /** Whether the poll is anonymous. */
11
17
  isAnonymous: boolean;
18
+ /** The type of the poll. */
12
19
  type: "regular" | "quiz";
20
+ /** Whether the poll allows multiple answers. */
13
21
  allowMultipleAnswers?: boolean;
22
+ /** Index of the correct option. */
14
23
  correctOptionIndex?: number;
24
+ /** A text that is shown to the user when the poll is answered. */
15
25
  explanation?: string;
26
+ /** The explanation's entities. */
16
27
  explanationEntities?: MessageEntity[];
28
+ /** Duration of the poll in seconds. */
17
29
  openPeriod?: number;
30
+ /** The time in which the poll will be closed. */
18
31
  closeDate?: Date;
19
32
  }
20
33
  export declare function constructPoll(media_: types.MessageMediaPoll): Poll;
@@ -2,7 +2,9 @@ import { types } from "../2_tl.js";
2
2
  import { Reaction } from "./0_reaction.js";
3
3
  /** The count of a specific reaction. */
4
4
  export interface ReactionCount {
5
+ /** The type of the reaction. */
5
6
  reaction: Reaction;
7
+ /** Number of times the reaction was added. */
6
8
  count: number;
7
9
  }
8
10
  export declare function constructReactionCount(reaction_: types.ReactionCount): ReactionCount;
@@ -2,8 +2,11 @@ import { enums } from "../2_tl.js";
2
2
  import { MessageEntity } from "./0_message_entity.js";
3
3
  /** A reference to a specific part of a message that is being replied to. */
4
4
  export interface ReplyQuote {
5
+ /** The byte offset of the quoted text. */
5
6
  offset: number;
7
+ /** The quoted text. */
6
8
  text: string;
9
+ /** The entities of the quoted text. */
7
10
  entities: MessageEntity[];
8
11
  }
9
12
  export declare function constructReplyQuote(quoteText: string | undefined, quoteOffset: number | undefined, quoteEntities: enums.MessageEntity[] | undefined): ReplyQuote;
@@ -6,31 +6,31 @@ export interface User {
6
6
  id: number;
7
7
  /** Identifier of color that can be displayed instead of the user's photo. */
8
8
  color: number;
9
- /** True, if this user is a bot */
9
+ /** Whether the user is a bot. */
10
10
  isBot: boolean;
11
- /** User's or bot's first name */
11
+ /** The first name of the user. */
12
12
  firstName: string;
13
- /** User's or bot's last name */
13
+ /** The last name of the user. */
14
14
  lastName?: string;
15
- /** User's or bot's username */
15
+ /** The user’s main username. */
16
16
  username?: string;
17
- /** Additional usernames */
17
+ /** The user's additional usernames. */
18
18
  also?: string[];
19
- /** The user's photo. */
19
+ /** The user's profile photo. */
20
20
  photo?: ChatPhotoUser;
21
- /** [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) of the user's language */
21
+ /** The user's [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag). */
22
22
  languageCode?: string;
23
- /** True, if the user is a scam user */
23
+ /** Whether the user has been identified as scam. */
24
24
  isScam: boolean;
25
- /** True, if this user was reported by many users as a fake or scam user: be careful when interacting with them. */
25
+ /** Whether the user has been identified as an impersonator. */
26
26
  isFake: boolean;
27
- /** True, if this user is a Telegram Premium user */
27
+ /** Whether the user is subscribed to Telegram Premium. */
28
28
  isPremium: boolean;
29
- /** True, if the user is verified */
29
+ /** Whether the user has been verified. */
30
30
  isVerified: boolean;
31
- /** True, if the user is an official support user */
31
+ /** Whether the user is official support. */
32
32
  isSupport: boolean;
33
- /** True, if this user added the bot to the attachment menu */
33
+ /** Whether the user is a bot that has been added to the attachment menu by the current user. */
34
34
  addedToAttachmentMenu: boolean;
35
35
  }
36
36
  export declare function constructUser(user_: types.User): User;
@@ -4,10 +4,15 @@ import { EntityGetter } from "./1__getters.js";
4
4
  import { User } from "./1_user.js";
5
5
  /** A chosen inline result. */
6
6
  export interface ChosenInlineResult {
7
+ /** The identifier of the inline result that was chosen. */
7
8
  resultId: string;
9
+ /** The user who chose the result. */
8
10
  from: User;
11
+ /** The location of the user who chose the result. */
9
12
  location?: Location;
13
+ /** Identifier of the sent inline message. */
10
14
  inlineMessageId?: string;
15
+ /** The query that was used to obtain the result. */
11
16
  query: string;
12
17
  }
13
18
  export declare function constructChosenInlineResult(ubis: types.UpdateBotInlineSend, getEntity: EntityGetter): Promise<ChosenInlineResult>;
@@ -4,11 +4,17 @@ import { Animation } from "./1_animation.js";
4
4
  import { Photo } from "./1_photo.js";
5
5
  /** A game. */
6
6
  export interface Game {
7
+ /** The title of the game. */
7
8
  title: string;
9
+ /** The description of the game. */
8
10
  description: string;
11
+ /** A photo that is displayed when the game is shared. */
9
12
  photo: Photo;
13
+ /** A text that is displayed when the game is shared. */
10
14
  text?: string;
15
+ /** The text's entities. */
11
16
  textEntities?: MessageEntity[];
17
+ /** An animation that is displayed when the game is shared. */
12
18
  animation?: Animation;
13
19
  }
14
20
  export declare function constructGame(media_: types.MessageMediaGame): Game;
@@ -1,21 +1,25 @@
1
1
  import { cleanObject } from "../1_utilities.js";
2
2
  import { as, types } from "../2_tl.js";
3
- import { FileID, FileType, FileUniqueID, FileUniqueType } from "./0__file_id.js";
3
+ import { FileType, serializeFileId, toUniqueFileId } from "./0__file_id.js";
4
4
  import { constructAnimation } from "./1_animation.js";
5
5
  import { constructPhoto } from "./1_photo.js";
6
6
  export function constructGame(media_) {
7
7
  const game_ = media_.game;
8
8
  const document_ = game_.document ? game_.document[as](types.Document) : undefined;
9
+ const fileId_ = document_
10
+ ? {
11
+ type: FileType.Animation,
12
+ dcId: document_.dc_id,
13
+ fileReference: document_.file_reference,
14
+ location: { type: "common", id: document_.id, accessHash: document_.access_hash },
15
+ }
16
+ : undefined;
9
17
  return cleanObject({
10
18
  title: game_.title,
11
19
  description: media_.game.description,
12
20
  photo: constructPhoto(game_.photo[as](types.Photo)),
13
- animation: document_
14
- ? constructAnimation(document_, document_.attributes.find((v) => v instanceof types.DocumentAttributeVideo), document_.attributes.find((v) => v instanceof types.DocumentAttributeFilename), new FileID(null, null, FileType.Animation, document_.dc_id, {
15
- mediaId: document_.id,
16
- accessHash: document_.access_hash,
17
- fileReference: document_.file_reference,
18
- }).encode(), new FileUniqueID(FileUniqueType.Document, { mediaId: document_.id }).encode())
21
+ animation: fileId_ && document_
22
+ ? constructAnimation(document_, document_.attributes.find((v) => v instanceof types.DocumentAttributeVideo), document_.attributes.find((v) => v instanceof types.DocumentAttributeFilename), serializeFileId(fileId_), toUniqueFileId(fileId_))
19
23
  : undefined,
20
24
  });
21
25
  }
@@ -1,7 +1,10 @@
1
1
  import { enums } from "../2_tl.js";
2
2
  import { ChatP } from "./1_chat_p.js";
3
+ /** An inactive chat. */
3
4
  export interface InactiveChat {
5
+ /** The point of time in which the chat was last active. */
4
6
  lastActivity: Date;
7
+ /** The chat that has been marked as inactive. */
5
8
  chat: ChatP;
6
9
  }
7
10
  export declare function constructInactiveChat(chat_: enums.Chat, lastActivity: number): InactiveChat;
@@ -4,11 +4,17 @@ import { EntityGetter } from "./1__getters.js";
4
4
  import { User } from "./1_user.js";
5
5
  /** An incoming inline query. */
6
6
  export interface InlineQuery {
7
+ /** The identifier of the inline query. */
7
8
  id: string;
9
+ /** The user who made the inline query. */
8
10
  from: User;
11
+ /** The query that was made. */
9
12
  query: string;
13
+ /** The offset parameter that was passed to the last [answerInlineQuery](/methods/answerInlineQuery) call. */
10
14
  offset: string;
15
+ /** The type of the chat from which the inline query was made. */
11
16
  chatType?: "sender" | "private" | "group" | "supergroup" | "channel";
17
+ /** The location of the user who made the inline query. */
12
18
  location?: Location;
13
19
  }
14
20
  export declare function constructInlineQuery(query_: types.UpdateBotInlineQuery, getEntity: EntityGetter): Promise<InlineQuery>;
@@ -1,9 +1,14 @@
1
1
  import { MessageReaction } from "./1_message_reaction.js";
2
2
  /** The interactions made with a message. */
3
3
  export interface MessageInteractions {
4
+ /** The identifier of the message's chat. */
4
5
  chatId: number;
6
+ /** The message's identifier. */
5
7
  messageId: number;
8
+ /** The reactions made to the message. */
6
9
  reactions: MessageReaction[];
10
+ /** The number of times the message was viewed. */
7
11
  views: number;
12
+ /** The number of times the message was forwarded. */
8
13
  forwards: number;
9
14
  }
@@ -4,9 +4,13 @@ import { ChatP } from "./1_chat_p.js";
4
4
  import { ReactionCount } from "./1_reaction_count.js";
5
5
  /** Information on the reactions made to a channel post. */
6
6
  export interface MessageReactionCount {
7
+ /** The chat containing the message. */
7
8
  chat: ChatP;
9
+ /** The message's identifier. */
8
10
  messageId: number;
11
+ /** This reaction state's point of time. */
9
12
  date: Date;
13
+ /** The reactions made to the post. */
10
14
  reactions: ReactionCount[];
11
15
  }
12
16
  export declare function constructMessageReactionCount(update: types.UpdateBotMessageReactions, getEntity: EntityGetter): Promise<MessageReactionCount | null>;
@@ -5,12 +5,19 @@ import { ChatP } from "./1_chat_p.js";
5
5
  import { User } from "./1_user.js";
6
6
  /** The reactions of a user to a messages in a group. */
7
7
  export interface MessageReactions {
8
+ /** The chat containing the message the user reacted to. */
8
9
  chat: ChatP;
10
+ /** The message's identifier. */
9
11
  messageId: number;
12
+ /** The user who changed their reactions to the message. Unset if done on behalf of a chat. */
10
13
  user?: User;
14
+ /** The chat that changed its reactions to the message. Unset if done on behalf of a user. */
11
15
  actorChat?: ChatP;
16
+ /** The point of time in which the change was made. */
12
17
  date: Date;
18
+ /** The previous reactions. */
13
19
  oldReactions: Reaction[];
20
+ /** The current reactions. */
14
21
  newReactions: Reaction[];
15
22
  }
16
23
  export declare function constructMessageReactions(update: types.UpdateBotMessageReaction, getEntity: EntityGetter): Promise<MessageReactions | null>;
@@ -1,6 +1,6 @@
1
1
  import { UNREACHABLE } from "../1_utilities.js";
2
2
  import { as, types } from "../2_tl.js";
3
- import { FileID, FileType, FileUniqueID, FileUniqueType } from "./0__file_id.js";
3
+ import { FileType, serializeFileId, toUniqueFileId } from "./0__file_id.js";
4
4
  import { constructPhoto } from "./1_photo.js";
5
5
  import { constructVideo } from "./1_video.js";
6
6
  export function constructStoryContent(media) {
@@ -20,12 +20,9 @@ export function constructStoryContent(media) {
20
20
  if (!video) {
21
21
  UNREACHABLE();
22
22
  }
23
- const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document.id }).encode();
24
- const fileId = new FileID(null, null, FileType.Video, document.dc_id, {
25
- mediaId: document.id,
26
- accessHash: document.access_hash,
27
- fileReference: document.file_reference,
28
- }).encode();
23
+ const fileId_ = { type: FileType.Video, dcId: document.dc_id, fileReference: document.file_reference, location: { type: "common", id: document.id, accessHash: document.access_hash } };
24
+ const fileUniqueId = toUniqueFileId(fileId_);
25
+ const fileId = serializeFileId(fileId_);
29
26
  const video_ = constructVideo(document, video, undefined, fileId, fileUniqueId);
30
27
  return { video: video_ };
31
28
  }
@@ -1,6 +1,6 @@
1
1
  import { UNREACHABLE } from "../1_utilities.js";
2
2
  import { types } from "../2_tl.js";
3
- import { FileID } from "./0__file_id.js";
3
+ import { deserializeFileId } from "./0__file_id.js";
4
4
  import { replyMarkupToTlObject } from "./3_reply_markup.js";
5
5
  // deno-lint-ignore no-explicit-any
6
6
  export async function inlineQueryResultToTlObject(result_, parseText, usernameResolver) {
@@ -175,16 +175,16 @@ export async function inlineQueryResultToTlObject(result_, parseText, usernameRe
175
175
  });
176
176
  }
177
177
  else if (fileId_ != null) {
178
- const fileId = FileID.decode(fileId_);
178
+ const fileId = deserializeFileId(fileId_);
179
179
  return new types.InputBotInlineResultDocument({
180
180
  id,
181
181
  type: type == "document" ? "file" : type,
182
182
  title,
183
183
  description,
184
184
  document: new types.InputDocument({
185
- id: fileId.params.mediaId,
186
- access_hash: fileId.params.accessHash,
187
- file_reference: fileId.params.fileReference,
185
+ id: "id" in fileId.location ? fileId.location.id : UNREACHABLE(),
186
+ access_hash: fileId.location.accessHash,
187
+ file_reference: fileId.fileReference ?? new Uint8Array(),
188
188
  }),
189
189
  send_message: sendMessage,
190
190
  });
@@ -1,6 +1,7 @@
1
1
  import { cleanObject, fromUnixTimestamp, getLogger, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
2
2
  import { as, types } from "../2_tl.js";
3
- import { FileID, FileType, FileUniqueID, FileUniqueType } from "./0__file_id.js";
3
+ import { FileType, toUniqueFileId } from "./0__file_id.js";
4
+ import { serializeFileId } from "./0__file_id.js";
4
5
  import { constructContact } from "./0_contact.js";
5
6
  import { constructDice } from "./0_dice.js";
6
7
  import { constructLinkPreview } from "./0_link_preview.js";
@@ -118,9 +119,10 @@ async function constructServiceMessage(message_, chat, getEntity, getMessage) {
118
119
  isTopicMessage: false,
119
120
  };
120
121
  Object.assign(message, await getSender(message_, getEntity));
121
- if (message_.action instanceof types.MessageActionChatAddUser) {
122
+ if (message_.action instanceof types.MessageActionChatAddUser || message_.action instanceof types.MessageActionChatJoinedByLink || message_.action instanceof types.MessageActionChatJoinedByRequest) {
122
123
  const newChatMembers = new Array();
123
- for (const user_ of message_.action.users) {
124
+ const users = "users" in message_.action ? message_.action.users : [message_.from_id && "user_id" in message_.from_id ? message_.from_id.user_id : UNREACHABLE()];
125
+ for (const user_ of users) {
124
126
  const entity = await getEntity(new types.PeerUser({ user_id: user_ }));
125
127
  if (entity) {
126
128
  const user = constructUser(entity);
@@ -389,51 +391,54 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
389
391
  else if (message_.media instanceof types.MessageMediaDocument) {
390
392
  const { document } = message_.media;
391
393
  if (document instanceof types.Document) {
392
- const getFileId = (type) => new FileID(null, null, type, document.dc_id, {
393
- mediaId: document.id,
394
- accessHash: document.access_hash,
394
+ const getFileId = (type) => ({
395
+ type,
396
+ dcId: document.dc_id,
395
397
  fileReference: document.file_reference,
396
- }).encode();
397
- const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document.id }).encode();
398
+ location: { type: "common", id: document.id, accessHash: document.access_hash },
399
+ });
398
400
  const animated = document.attributes.find((v) => v instanceof types.DocumentAttributeAnimated);
399
401
  const audio = document.attributes.find((v) => v instanceof types.DocumentAttributeAudio);
400
402
  const fileName = document.attributes.find((v) => v instanceof types.DocumentAttributeFilename);
401
403
  const sticker = document.attributes.find((v) => v instanceof types.DocumentAttributeSticker);
402
404
  const video = document.attributes.find((v) => v instanceof types.DocumentAttributeVideo);
403
405
  if (animated) {
404
- const animation = constructAnimation(document, video, fileName, getFileId(FileType.Animation), fileUniqueId);
406
+ const fileId = getFileId(FileType.Animation);
407
+ const animation = constructAnimation(document, video, fileName, serializeFileId(fileId), toUniqueFileId(fileId));
405
408
  m = { ...messageMedia, animation };
406
409
  }
407
410
  else if (video) {
408
411
  if (video.round_message) {
409
- const videoNote = constructVideoNote(document, video, getFileId(FileType.VideoNote), fileUniqueId);
412
+ const fileId = getFileId(FileType.VideoNote);
413
+ const videoNote = constructVideoNote(document, video, serializeFileId(fileId), toUniqueFileId(fileId));
410
414
  m = { ...message, videoNote };
411
415
  }
412
416
  else {
413
- const video_ = constructVideo(document, video, fileName?.file_name, getFileId(FileType.Video), fileUniqueId);
417
+ const fileId = getFileId(FileType.Video);
418
+ const video_ = constructVideo(document, video, fileName?.file_name, serializeFileId(fileId), toUniqueFileId(fileId));
414
419
  m = { ...messageMedia, video: video_ };
415
420
  }
416
421
  }
417
422
  else if (audio) {
418
423
  if (audio.voice) {
419
- const voice = constructVoice(document, audio, getFileId(FileType.Voice), fileUniqueId);
424
+ const fileId = getFileId(FileType.VoiceNote);
425
+ const voice = constructVoice(document, audio, serializeFileId(fileId), toUniqueFileId(fileId));
420
426
  m = { ...messageMedia, voice };
421
427
  }
422
428
  else {
423
- const audio_ = constructAudio(document, audio, getFileId(FileType.Audio), fileUniqueId);
429
+ const fileId = getFileId(FileType.Audio);
430
+ const audio_ = constructAudio(document, audio, serializeFileId(fileId), toUniqueFileId(fileId));
424
431
  m = { ...messageMedia, audio: audio_ };
425
432
  }
426
433
  }
427
434
  else if (sticker) {
428
- const sticker = await constructSticker(document, getFileId(FileType.Sticker), fileUniqueId, getStickerSetName);
435
+ const fileId = getFileId(FileType.Sticker);
436
+ const sticker = await constructSticker(document, serializeFileId(fileId), toUniqueFileId(fileId), getStickerSetName);
429
437
  m = { ...message, sticker };
430
438
  }
431
- else if (fileName) {
432
- const document_ = constructDocument(document, fileName, getFileId(FileType.Document), fileUniqueId);
433
- m = { ...messageMedia, document: document_ };
434
- }
435
439
  else {
436
- const document_ = constructDocument(document, new types.DocumentAttributeFilename({ file_name: "Unknown" }), getFileId(FileType.Document), fileUniqueId);
440
+ const fileId = getFileId(FileType.Document);
441
+ const document_ = constructDocument(document, fileName ?? new types.DocumentAttributeFilename({ file_name: "Unknown" }), serializeFileId(fileId), toUniqueFileId(fileId));
437
442
  m = { ...messageMedia, document: document_ };
438
443
  }
439
444
  }
@@ -4,12 +4,19 @@ import { User } from "./1_user.js";
4
4
  import { Message, MessageGetter } from "./4_message.js";
5
5
  /** A received callback query. */
6
6
  export interface CallbackQuery {
7
+ /** The identifier of the callback query. */
7
8
  id: string;
9
+ /** The user who made the callback query. */
8
10
  from: User;
11
+ /** The message from which the callback query was made. Unset if made from an inline result message. */
9
12
  message?: Message;
13
+ /** The identifier of the inline result message from which the callback query was made. Unset if made from a message not originating from an inline query result. */
10
14
  inlineMessageId?: string;
15
+ /** A special identifier for the chat in which the callback was made from. Useful for inline result messages. */
11
16
  chatInstance: string;
17
+ /** The data associated with the button that was used to make the callback query. */
12
18
  data?: string;
19
+ /** The short name of the game to be returned. */
13
20
  gameShortName?: string;
14
21
  }
15
22
  export declare function deserializeInlineMessageId(inlineMessageId: string): enums.InputBotInlineMessageID;
@@ -1,2 +1,2 @@
1
1
  export declare function concat(...buffers: [Uint8Array, Uint8Array, ...Uint8Array[]]): Uint8Array;
2
- export declare function bufferFromBigInt(bigIntVar: bigint | number, bytesNumber: number, little?: boolean, signed?: boolean): Uint8Array;
2
+ export declare function bufferFromBigInt(int: bigint | number, byteCount: number, littleEndian?: boolean, signed?: boolean): Uint8Array;
@@ -12,31 +12,33 @@ export function concat(...buffers) {
12
12
  return buffer;
13
13
  }
14
14
  const bufferFromHexString = (hexString) => Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
15
- export function bufferFromBigInt(bigIntVar, bytesNumber, little = true, signed = false) {
16
- bigIntVar = BigInt(typeof bigIntVar === "number" ? Math.ceil(bigIntVar) : bigIntVar);
17
- const bitLength = bigIntVar.toString(2).length;
18
- const bytes = Math.ceil(bitLength / 8);
19
- if (bytesNumber < bytes) {
20
- throw new Error("OverflowError: int too big to convert");
21
- }
22
- if (!signed && bigIntVar < 0n) {
23
- throw new Error("Cannot convert to unsigned");
24
- }
25
- let below = false;
26
- if (bigIntVar < 0n) {
27
- below = true;
28
- bigIntVar = bigIntVar < 0 ? bigIntVar * -1n : bigIntVar;
29
- }
30
- const hex = bigIntVar.toString(16).padStart(bytesNumber * 2, "0");
15
+ export function bufferFromBigInt(int, byteCount, littleEndian = true, signed = false) {
16
+ const actualByteCount = Math.ceil(int.toString(2).length / 8);
17
+ if (byteCount < actualByteCount) {
18
+ throw new Error("Int too big");
19
+ }
20
+ if (byteCount == 4 || byteCount == 2) { // fast path
21
+ const buffer = new Uint8Array(byteCount);
22
+ const dataView = new DataView(buffer.buffer);
23
+ (byteCount == 2 ? signed ? dataView.setInt16 : dataView.setUint16 : signed ? dataView.setInt32 : dataView.setUint32).call(dataView, 0, Number(int), littleEndian);
24
+ return buffer;
25
+ }
26
+ int = BigInt(typeof int === "number" ? Math.ceil(int) : int);
27
+ if (byteCount == 8) { // fast path
28
+ const buffer = new Uint8Array(byteCount);
29
+ const dataView = new DataView(buffer.buffer);
30
+ (signed ? dataView.setBigInt64 : dataView.setBigUint64).call(dataView, 0, int, littleEndian);
31
+ return buffer;
32
+ }
33
+ if (!signed && int < 0n) {
34
+ throw new Error("Got unexpected signed int");
35
+ }
36
+ if (signed && int < 0n) {
37
+ int = 2n ** BigInt(byteCount * 8) + int;
38
+ }
39
+ const hex = int.toString(16).padStart(byteCount * 2, "0");
31
40
  const buffer = bufferFromHexString(hex);
32
- if (signed && below) {
33
- buffer[buffer.length - 1] = 256 -
34
- buffer[buffer.length - 1];
35
- for (let i = 0; i < buffer.length - 1; i++) {
36
- buffer[i] = 255 - buffer[i];
37
- }
38
- }
39
- if (little) {
41
+ if (littleEndian) {
40
42
  buffer.reverse();
41
43
  }
42
44
  return buffer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtkruto/node",
3
- "version": "0.1.157",
3
+ "version": "0.1.161",
4
4
  "description": "MTKruto for Node.js",
5
5
  "author": "Roj <rojvv@icloud.com>",
6
6
  "repository": {
@@ -3,8 +3,8 @@ export declare const ACK_THRESHOLD = 10;
3
3
  export type PublicKeys = readonly [bigint, [bigint, bigint]][];
4
4
  export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const INITIAL_DC: DC;
6
- export declare const LAYER = 174;
7
- export declare const APP_VERSION = "MTKruto 0.1.156";
6
+ export declare const LAYER = 176;
7
+ export declare const APP_VERSION = "MTKruto 0.1.160";
8
8
  export declare const DEVICE_MODEL: string;
9
9
  export declare const LANG_CODE: string;
10
10
  export declare const LANG_PACK = "";