@mtkruto/node 0.0.957 → 0.0.960

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 (93) hide show
  1. package/esm/client/0_utilities.d.ts +3 -0
  2. package/esm/client/0_utilities.js +20 -0
  3. package/esm/client/3_client.d.ts +2 -2
  4. package/esm/client/3_client.js +57 -16
  5. package/esm/constants.d.ts +1 -1
  6. package/esm/constants.js +1 -1
  7. package/esm/storage/0_storage.d.ts +16 -17
  8. package/esm/storage/0_storage.js +65 -131
  9. package/esm/storage/0_utilities.d.ts +13 -0
  10. package/esm/storage/0_utilities.js +62 -0
  11. package/esm/storage/1_storage_indexed_db.d.ts +3 -3
  12. package/esm/storage/1_storage_indexed_db.js +4 -3
  13. package/esm/storage/1_storage_local_storage.d.ts +3 -3
  14. package/esm/storage/1_storage_local_storage.js +13 -6
  15. package/esm/storage/1_storage_memory.d.ts +4 -4
  16. package/esm/storage/1_storage_memory.js +4 -2
  17. package/esm/storage/1_storage_session_storage.d.ts +3 -3
  18. package/esm/storage/1_storage_session_storage.js +13 -6
  19. package/esm/types/0_audio.d.ts +9 -0
  20. package/esm/types/0_chat_administrator_rights.d.ts +4 -4
  21. package/esm/types/0_contact.d.ts +6 -0
  22. package/esm/types/0_dice.d.ts +3 -0
  23. package/esm/types/0_force_reply.d.ts +1 -1
  24. package/esm/types/0_keyboard_button_poll_type.d.ts +1 -1
  25. package/esm/types/0_location.d.ts +7 -0
  26. package/esm/types/0_login_url.d.ts +3 -3
  27. package/esm/types/0_mask_position.d.ts +5 -0
  28. package/esm/types/0_message_entity.d.ts +4 -4
  29. package/esm/types/0_reply_keyboard_remove.d.ts +1 -1
  30. package/esm/types/0_thumbnail.d.ts +2 -1
  31. package/esm/types/0_venue.d.ts +6 -0
  32. package/esm/types/0_voice.d.ts +6 -0
  33. package/esm/types/1_animation.d.ts +10 -0
  34. package/esm/types/1_chat.d.ts +18 -18
  35. package/esm/types/1_document.d.ts +7 -0
  36. package/esm/types/1_inline_keyboard_button.d.ts +7 -7
  37. package/esm/types/1_keyboard_button.d.ts +14 -14
  38. package/esm/types/1_photo.d.ts +2 -1
  39. package/esm/types/1_sticker.d.ts +16 -0
  40. package/esm/types/1_user.d.ts +7 -7
  41. package/esm/types/1_video.d.ts +10 -0
  42. package/esm/types/1_video_note.d.ts +8 -0
  43. package/esm/types/2_game.d.ts +7 -0
  44. package/esm/types/2_reply_keyboard_markup.d.ts +5 -5
  45. package/esm/types/3_message.d.ts +57 -25
  46. package/esm/types/3_message.js +0 -1
  47. package/package.json +1 -1
  48. package/script/client/0_utilities.d.ts +3 -0
  49. package/script/client/0_utilities.js +48 -0
  50. package/script/client/3_client.d.ts +2 -2
  51. package/script/client/3_client.js +57 -16
  52. package/script/constants.d.ts +1 -1
  53. package/script/constants.js +1 -1
  54. package/script/storage/0_storage.d.ts +16 -17
  55. package/script/storage/0_storage.js +65 -131
  56. package/script/storage/0_utilities.d.ts +13 -0
  57. package/script/storage/0_utilities.js +68 -0
  58. package/script/storage/1_storage_indexed_db.d.ts +3 -3
  59. package/script/storage/1_storage_indexed_db.js +4 -3
  60. package/script/storage/1_storage_local_storage.d.ts +3 -3
  61. package/script/storage/1_storage_local_storage.js +13 -6
  62. package/script/storage/1_storage_memory.d.ts +4 -4
  63. package/script/storage/1_storage_memory.js +4 -2
  64. package/script/storage/1_storage_session_storage.d.ts +3 -3
  65. package/script/storage/1_storage_session_storage.js +13 -6
  66. package/script/types/0_audio.d.ts +9 -0
  67. package/script/types/0_chat_administrator_rights.d.ts +4 -4
  68. package/script/types/0_contact.d.ts +6 -0
  69. package/script/types/0_dice.d.ts +3 -0
  70. package/script/types/0_force_reply.d.ts +1 -1
  71. package/script/types/0_keyboard_button_poll_type.d.ts +1 -1
  72. package/script/types/0_location.d.ts +7 -0
  73. package/script/types/0_login_url.d.ts +3 -3
  74. package/script/types/0_mask_position.d.ts +5 -0
  75. package/script/types/0_message_entity.d.ts +4 -4
  76. package/script/types/0_reply_keyboard_remove.d.ts +1 -1
  77. package/script/types/0_thumbnail.d.ts +2 -1
  78. package/script/types/0_venue.d.ts +6 -0
  79. package/script/types/0_voice.d.ts +6 -0
  80. package/script/types/1_animation.d.ts +10 -0
  81. package/script/types/1_chat.d.ts +18 -18
  82. package/script/types/1_document.d.ts +7 -0
  83. package/script/types/1_inline_keyboard_button.d.ts +7 -7
  84. package/script/types/1_keyboard_button.d.ts +14 -14
  85. package/script/types/1_photo.d.ts +2 -1
  86. package/script/types/1_sticker.d.ts +16 -0
  87. package/script/types/1_user.d.ts +7 -7
  88. package/script/types/1_video.d.ts +10 -0
  89. package/script/types/1_video_note.d.ts +8 -0
  90. package/script/types/2_game.d.ts +7 -0
  91. package/script/types/2_reply_keyboard_markup.d.ts +5 -5
  92. package/script/types/3_message.d.ts +57 -25
  93. package/script/types/3_message.js +0 -1
@@ -2,21 +2,37 @@ import * as types from "../tl/2_types.js";
2
2
  import { MaybePromise } from "../utilities/0_types.js";
3
3
  import { Thumbnail } from "./0_thumbnail.js";
4
4
  import { MaskPosition } from "./0_mask_position.js";
5
+ /** This object represents a sticker. */
5
6
  export interface Sticker {
7
+ /** Identifier for this file, which can be used to download or reuse the file */
6
8
  fileId: string;
9
+ /** 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
10
  fileUniqueId: string;
11
+ /** Type of the sticker, currently one of "regular", "mask", "custom_emoji". The type of the sticker is independent from its format, which is determined by the fields is_animated and is_video. */
8
12
  type: "regular" | "mask" | "custom_emoji";
13
+ /** Sticker width */
9
14
  width: number;
15
+ /** Sticker height */
10
16
  height: number;
17
+ /** True, if the sticker is [animated](https://telegram.org/blog/animated-stickers) */
11
18
  isAnimated: boolean;
19
+ /** True, if the sticker is a [video sticker](https://telegram.org/blog/video-stickers-better-reactions) */
12
20
  isVideo: boolean;
21
+ /** Sticker thumbnail in the .WEBP or .JPG format */
13
22
  thumbnails: Thumbnail[];
23
+ /** Emoji associated with the sticker */
14
24
  emoji?: string;
25
+ /** Name of the sticker set to which the sticker belongs */
15
26
  setName?: string;
27
+ /** For premium regular stickers, premium animation for the sticker */
16
28
  premiumAnimation?: File;
29
+ /** For mask stickers, the position where the mask should be placed */
17
30
  maskPosition?: MaskPosition;
31
+ /** For custom emoji stickers, unique identifier of the custom emoji */
18
32
  customEmojiId?: string;
33
+ /** True, if the sticker must be repainted to a text color in messages, the color of the Telegram Premium badge in emoji status, white color on chat photos, or another appropriate color in other places */
19
34
  needsRepainting?: boolean;
35
+ /** File size in bytes */
20
36
  fileSize?: number;
21
37
  }
22
38
  export type StickerSetNameGetter = (inputStickerSet: types.InputStickerSetID) => MaybePromise<string>;
@@ -9,27 +9,27 @@ export interface User {
9
9
  isBot: boolean;
10
10
  /** User's or bot's first name */
11
11
  firstName: string;
12
- /** Optional. User's or bot's last name */
12
+ /** User's or bot's last name */
13
13
  lastName?: string;
14
- /** Optional. User's or bot's username */
14
+ /** User's or bot's username */
15
15
  username?: string;
16
- /** Optional. Additional usernames */
16
+ /** Additional usernames */
17
17
  also?: string[];
18
- /** Optional. Chat photo */
18
+ /** Chat photo */
19
19
  photo?: ChatPhoto.User;
20
- /** Optional. [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) of the user's language */
20
+ /** [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) of the user's language */
21
21
  languageCode?: string;
22
22
  /** True, if the user is a scam user */
23
23
  isScam: boolean;
24
24
  /** True, if this user was reported by many users as a fake or scam user: be careful when interacting with them. */
25
25
  isFake: boolean;
26
- /** Optional. True, if this user is a Telegram Premium user */
26
+ /** True, if this user is a Telegram Premium user */
27
27
  isPremium: boolean;
28
28
  /** True, if the user is verified */
29
29
  isVerified: boolean;
30
30
  /** True, if the user is an official support user */
31
31
  isSupport: boolean;
32
- /** Optional. True, if this user added the bot to the attachment menu */
32
+ /** True, if this user added the bot to the attachment menu */
33
33
  addedToAttachmentMenu: boolean;
34
34
  }
35
35
  export declare function constructUser(user_: types.User): User;
@@ -1,14 +1,24 @@
1
1
  import * as types from "../tl/2_types.js";
2
2
  import { Thumbnail } from "./0_thumbnail.js";
3
+ /** This object represents a video file. */
3
4
  export interface Video {
5
+ /** Identifier for this file, which can be used to download or reuse the file */
4
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. */
5
8
  fileUniqueId: string;
9
+ /** Video width as defined by sender */
6
10
  width: number;
11
+ /** Video height as defined by sender */
7
12
  height: number;
13
+ /** Duration of the video in seconds as defined by sender */
8
14
  duration: number;
15
+ /** Video thumbnail */
9
16
  thumbnails: Thumbnail[];
17
+ /** Original filename as defined by sender */
10
18
  fileName?: string;
19
+ /** MIME type of the file as defined by sender */
11
20
  mimeType: string;
21
+ /** 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. */
12
22
  fileSize: number;
13
23
  }
14
24
  export declare function constructVideo(document: types.Document, videoAttribute: types.DocumentAttributeVideo, fileName: string | undefined, fileId: string, fileUniqueId: string): Video;
@@ -1,12 +1,20 @@
1
1
  import * as types from "../tl/2_types.js";
2
2
  import { Thumbnail } from "./0_thumbnail.js";
3
+ /** This object represents a video message (available in Telegram apps as of v.4.0). */
3
4
  export interface VideoNote {
5
+ /** Identifier for this file, which can be used to download or reuse the file */
4
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. */
5
8
  fileUniqueId: string;
9
+ /** Video width and height (diameter of the video message) as defined by sender */
6
10
  length: number;
11
+ /** Duration of the video in seconds as defined by sender */
7
12
  duration: number;
13
+ /** Video thumbnail */
8
14
  thumbnails: Thumbnail[];
15
+ /** Original filename as defined by sender */
9
16
  fileName?: string;
17
+ /** File size in bytes */
10
18
  fileSize: number;
11
19
  }
12
20
  export declare function constructVideoNote(document: types.Document, videoAttribute: types.DocumentAttributeVideo, fileId: string, fileUniqueId: string): VideoNote;
@@ -2,12 +2,19 @@ import * as types from "../tl/2_types.js";
2
2
  import { MessageEntity } from "./0_message_entity.js";
3
3
  import { Animation } from "./1_animation.js";
4
4
  import { Photo } from "./1_photo.js";
5
+ /** This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers. */
5
6
  export interface Game {
7
+ /** Title of the game */
6
8
  title: string;
9
+ /** Description of the game */
7
10
  description: string;
11
+ /** Photo that will be displayed in the game message in chats. */
8
12
  photo: Photo;
13
+ /** Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls [setGameScore](https://corefork.telegram.org/bots/api#setgamescore), or manually edited using [editMessageText](https://corefork.telegram.org/bots/api#editmessagetext). 0-4096 characters. */
9
14
  text?: string;
15
+ /** Special entities that appear in text, such as usernames, URLs, bot commands, etc. */
10
16
  textEntities?: MessageEntity[];
17
+ /** Animation that will be displayed in the game message in chats. Upload via [BotFather](https://t.me/botfather) */
11
18
  animation?: Animation;
12
19
  }
13
20
  export declare function constructGame(media_: types.MessageMediaGame): Game;
@@ -4,15 +4,15 @@ import { KeyboardButton } from "./1_keyboard_button.js";
4
4
  export interface ReplyKeyboardMarkup {
5
5
  /** Array of button rows, each represented by an Array of `KeyboardButton` objects */
6
6
  keyboard: KeyboardButton[][];
7
- /** Optional. Requests clients to always show the keyboard when the regular keyboard is hidden. Defaults to false, in which case the custom keyboard can be hidden and opened with a keyboard icon. */
7
+ /** Requests clients to always show the keyboard when the regular keyboard is hidden. Defaults to false, in which case the custom keyboard can be hidden and opened with a keyboard icon. */
8
8
  isPersistent?: boolean;
9
- /** Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. */
9
+ /** Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. */
10
10
  resizeKeyboard?: boolean;
11
- /** Optional. Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - the user can press a special button in the input field to see the custom keyboard again. Defaults to false. */
11
+ /** Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - the user can press a special button in the input field to see the custom keyboard again. Defaults to false. */
12
12
  oneTimeKeyboard?: boolean;
13
- /** Optional. The placeholder to be shown in the input field when the keyboard is active; 1-64 characters */
13
+ /** The placeholder to be shown in the input field when the keyboard is active; 1-64 characters */
14
14
  inputFieldPlaceholder?: string;
15
- /** Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the `Message` object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. */
15
+ /** Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the `Message` object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. */
16
16
  selective?: boolean;
17
17
  }
18
18
  export declare function constructReplyKeyboardMarkup(keyboard_: types.ReplyKeyboardMarkup): ReplyKeyboardMarkup;
@@ -24,105 +24,137 @@ import { Location } from "./0_location.js";
24
24
  export interface Message {
25
25
  /** Unique message identifier inside this chat */
26
26
  id: number;
27
- /** Optional. Unique identifier of a message thread to which the message belongs; for supergroups only */
27
+ /** Unique identifier of a message thread to which the message belongs; for supergroups only */
28
28
  threadId?: number;
29
- /** Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. */
29
+ /** Sender of the message; empty for messages sent to channels. For backward compatibility, the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. */
30
30
  from?: User;
31
- /** Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts, the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group. For backward compatibility, the field from contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. */
31
+ /** Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts, the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group. For backward compatibility, the field from contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat. */
32
32
  senderChat?: Chat;
33
33
  /** Date the message was sent in Unix time */
34
34
  date?: Date;
35
35
  /** Conversation the message belongs to */
36
36
  chat: Chat;
37
- /** Optional. For forwarded messages, sender of the original message */
37
+ /** For forwarded messages, sender of the original message */
38
38
  forwardFrom?: User;
39
- /** Optional. For messages forwarded from channels or from anonymous administrators, information about the original sender chat */
39
+ /** For messages forwarded from channels or from anonymous administrators, information about the original sender chat */
40
40
  forwardFromChat?: Chat;
41
- /** Optional. For messages forwarded from channels, identifier of the original message in the channel */
41
+ /** For messages forwarded from channels, identifier of the original message in the channel */
42
42
  forwardId?: number;
43
- /** Optional. For forwarded messages that were originally sent in channels or by an anonymous chat administrator, signature of the message sender if present */
43
+ /** For forwarded messages that were originally sent in channels or by an anonymous chat administrator, signature of the message sender if present */
44
44
  forwardSignature?: string;
45
- /** Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages */
45
+ /** Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages */
46
46
  forwardSenderName?: string;
47
- /** Optional. For forwarded messages, date the original message was sent in Unix time */
47
+ /** For forwarded messages, date the original message was sent in Unix time */
48
48
  forwardDate?: Date;
49
- /** Optional. True, if the message is sent to a forum topic */
49
+ /** True, if the message is sent to a forum topic */
50
50
  isTopicMessage: boolean;
51
- /** Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group */
51
+ /** True, if the message is a channel post that was automatically forwarded to the connected discussion group */
52
52
  isAutomaticForward?: boolean;
53
- /** Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. */
53
+ /** For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. */
54
54
  replyToMessage?: Omit<Message, "replyToMessage">;
55
- /** Optional. Bot through which the message was sent */
55
+ /** Bot through which the message was sent */
56
56
  viaBot?: User;
57
- /** Optional. Date the message was last edited in Unix time */
57
+ /** Date the message was last edited in Unix time */
58
58
  editDate?: Date;
59
- /** Optional. True, if the message can't be forwarded */
59
+ /** True, if the message can't be forwarded */
60
60
  hasProtectedContent?: boolean;
61
- /** Optional. The unique identifier of a media message group this message belongs to */
61
+ /** The unique identifier of a media message group this message belongs to */
62
62
  mediaGroupId?: string;
63
- /** Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator */
63
+ /** Signature of the post author for messages in channels, or the custom title of an anonymous group administrator */
64
64
  authorSignature?: string;
65
- /** Optional. For text messages, the actual UTF-8 text of the message */
65
+ /** For text messages, the actual UTF-8 text of the message */
66
66
  text?: string;
67
- /** Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text */
67
+ /** For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text */
68
68
  entities?: MessageEntity[];
69
- /** Optional. Caption for the animation, audio, document, photo, video or voice */
69
+ /** Caption for the animation, audio, document, photo, video or voice */
70
70
  caption?: string;
71
- /** Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption */
71
+ /** For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption */
72
72
  captionEntities?: MessageEntity[];
73
- /** Optional. True, if the message media is covered by a spoiler animation */
73
+ /** True, if the message media is covered by a spoiler animation */
74
74
  hasMediaSpoiler?: boolean;
75
- /** Optional. View count for channel posts */
75
+ /** View count for channel posts */
76
76
  views?: number;
77
- /** Optional. Inline keyboard attached to the message. `login_url` buttons are represented as ordinary `url` buttons. */
77
+ /** Inline keyboard attached to the message. `login_url` buttons are represented as ordinary `url` buttons. */
78
78
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
79
- /** Optional. Message is a photo, available sizes of the photo */
79
+ /** Message is a photo, available sizes of the photo */
80
80
  photo?: Photo;
81
+ /** Message is a general file, information about the file */
81
82
  document?: Document;
83
+ /** Message is a video, information about the video */
82
84
  video?: Video;
85
+ /** Message is a sticker, information about the sticker */
83
86
  sticker?: Sticker;
87
+ /** Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set */
84
88
  animation?: Animation;
89
+ /** Message is a voice message, information about the file */
85
90
  voice?: Voice;
91
+ /** Message is an audio file, information about the file */
86
92
  audio?: Audio;
93
+ /** Message is a dice with random value */
87
94
  dice?: Dice;
95
+ /** Message is a [video note](https://telegram.org/blog/video-messages-and-telescope), information about the video message */
88
96
  videoNote?: VideoNote;
97
+ /** Message is a shared contact, information about the contact */
89
98
  contact?: Contact;
99
+ /** Message is a game, information about the game. */
90
100
  game?: Game;
101
+ /** Message is a venue, information about the venue. For backward compatibility, when this field is set, the location field will also be set */
91
102
  venue?: Venue;
103
+ /** Message is a shared location, information about the location */
92
104
  location?: Location;
105
+ /** New members that were added to the group or supergroup and information about them (the bot itself may be one of these members) */
93
106
  newChatMembers?: User[];
107
+ /** A member was removed from the group, information about them (this member may be the bot itself) */
94
108
  leftChatMember?: User;
109
+ /** A chat title was changed to this value */
95
110
  newChatTitle?: string;
111
+ /** A chat photo was change to this value */
96
112
  newChatPhoto?: Photo;
113
+ /** Service message: the chat photo was deleted */
97
114
  deletedChatPhoto?: true;
115
+ /** Service message: the group has been created */
98
116
  groupCreated?: true;
117
+ /** Service message: the supergroup has been created. This field can't be received in a message coming through updates, because bot can't be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup. */
99
118
  supergroupCreated?: true;
119
+ /** Service message: the channel has been created. This field can't be received in a message coming through updates, because bot can't be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel. */
100
120
  channelCreated?: true;
121
+ /** The group has been migrated to a supergroup with the specified identifier. 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 signed 64-bit integer or double-precision float type are safe for storing this identifier. */
101
122
  chatMigratedTo?: number;
123
+ /** The supergroup has been migrated from a group with the specified identifier. 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 signed 64-bit integer or double-precision float type are safe for storing this identifier. */
102
124
  chatMigratedFrom?: number;
125
+ /** Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply. */
103
126
  pinnedMessage?: Message;
127
+ /** Service message: a user was shared with the bot */
104
128
  userShared?: {
105
129
  requestId: number;
106
130
  userId: number;
107
131
  };
132
+ /** Service message: the user allowed the bot added to the attachment menu to write messages */
108
133
  writeAccessAllowed?: {
109
134
  webAppName?: string;
110
135
  };
136
+ /** Service message: forum topic created */
111
137
  forumTopicCreated?: {
112
138
  name: string;
113
139
  iconColor: string;
114
140
  iconCutsomEmojiId?: string;
115
141
  };
142
+ /** Service message: forum topic edited */
116
143
  forumTopicEdited?: {
117
144
  name?: string;
118
145
  iconCutsomEmojiId?: string;
119
146
  };
147
+ /** Service message: forum topic closed */
120
148
  forumTopicClosed?: Record<never, never>;
149
+ /** Service message: forum topic reopened */
121
150
  forumTopicReopened?: Record<never, never>;
151
+ /** Service message: video chat scheduled */
122
152
  videoChatScheduled?: {
123
153
  startDate: Date;
124
154
  };
155
+ /** Service message: video chat started */
125
156
  videoChatStarted?: Record<never, never>;
157
+ /** Service message: video chat ended */
126
158
  videoChatEnded?: {
127
159
  duration: number;
128
160
  };
@@ -381,7 +381,6 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
381
381
  message.location = constructLocation(message_.media);
382
382
  }
383
383
  else {
384
- console.log(message_.media);
385
384
  // not implemented
386
385
  UNREACHABLE();
387
386
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.957",
5
+ "version": "0.0.960",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -0,0 +1,3 @@
1
+ import * as types from "../tl/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,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.peerToChatId = exports.getChannelChatId = void 0;
27
+ const constants_js_1 = require("../constants.js");
28
+ const types = __importStar(require("../tl/2_types.js"));
29
+ const _0_control_js_1 = require("../utilities/0_control.js");
30
+ function getChannelChatId(channelId) {
31
+ return constants_js_1.ZERO_CHANNEL_ID + -Number(channelId);
32
+ }
33
+ exports.getChannelChatId = getChannelChatId;
34
+ function peerToChatId(peer) {
35
+ if (peer instanceof types.PeerUser || peer instanceof types.InputPeerUser) {
36
+ return Number(peer.userId);
37
+ }
38
+ else if (peer instanceof types.PeerChat || peer instanceof types.InputPeerChat) {
39
+ return -Number(peer.chatId);
40
+ }
41
+ else if (peer instanceof types.PeerChannel || peer instanceof types.InputPeerChannel) {
42
+ return getChannelChatId(peer.channelId);
43
+ }
44
+ else {
45
+ (0, _0_control_js_1.UNREACHABLE)();
46
+ }
47
+ }
48
+ exports.peerToChatId = peerToChatId;
@@ -172,11 +172,11 @@ export declare class Client extends ClientAbstract {
172
172
  sendAs?: number | string;
173
173
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
174
174
  }): Promise<Message>;
175
- getMessages(chatId: number | string, messageIds: number[]): Promise<Omit<Message, "replyToMessage">[]>;
175
+ getMessages(chatId_: number | string, messageIds: number[]): Promise<Omit<Message, "replyToMessage">[]>;
176
176
  getMessage(chatId: number | string, messageId: number): Promise<Omit<Message, "replyToMessage"> | null>;
177
177
  private downloadInner;
178
178
  download(fileId_: string): Promise<AsyncGenerator<Uint8Array, void, unknown>>;
179
179
  [getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
180
180
  forwardMessages(from: number | string, to: number | string, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
181
- forwardMessage(from: number | string, to: number | string, messageId: number, params?: ForwardMessagesParams): Promise<Message[]>;
181
+ forwardMessage(from: number | string, to: number | string, messageId: number, params?: ForwardMessagesParams): Promise<Message>;
182
182
  }
@@ -49,6 +49,7 @@ const _0_html_js_1 = require("./0_html.js");
49
49
  const _0_password_js_1 = require("./0_password.js");
50
50
  const _1_client_abstract_js_1 = require("./1_client_abstract.js");
51
51
  const _2_client_plain_js_1 = require("./2_client_plain.js");
52
+ const _0_utilities_js_1 = require("./0_utilities.js");
52
53
  const d = (0, deps_js_1.debug)("Client");
53
54
  const dGap = (0, deps_js_1.debug)("Client/recoverUpdateGap");
54
55
  const dGapC = (0, deps_js_1.debug)("Client/recoverChannelUpdateGap");
@@ -533,7 +534,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
533
534
  this.promises.delete(messageId);
534
535
  }
535
536
  };
536
- if (result instanceof types.Updates || result instanceof types.TypeUpdate) {
537
+ if (result instanceof types.TypeUpdates || result instanceof types.TypeUpdate) {
537
538
  this.processUpdates(result).then(resolvePromise);
538
539
  }
539
540
  else {
@@ -689,6 +690,24 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
689
690
  d("applied update with pts %d", update.pts);
690
691
  await this.storage.setChannelPts(channelId, update.pts);
691
692
  }
693
+ if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateNewChannelMessage) {
694
+ if (update.message instanceof types.Message || update.message instanceof types.MessageService) {
695
+ await this.storage.setMessage((0, _0_utilities_js_1.peerToChatId)(update.message.peerId), update.message.id, update.message);
696
+ }
697
+ }
698
+ else if (update instanceof types.UpdateDeleteChannelMessages) {
699
+ for (const message of update.messages) {
700
+ await this.storage.setMessage((0, _0_utilities_js_1.getChannelChatId)(update.channelId), message, null);
701
+ }
702
+ }
703
+ else if (update instanceof types.UpdateDeleteMessages) {
704
+ for (const message of update.messages) {
705
+ const chatId = await this.storage.getMessageChat(message);
706
+ if (chatId) {
707
+ await this.storage.setMessage(chatId, message, null);
708
+ }
709
+ }
710
+ }
692
711
  // apply update (call listeners)
693
712
  this.updateHandler?.(this, update);
694
713
  }
@@ -1066,6 +1085,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1066
1085
  await this.processChats(result.chats);
1067
1086
  await this.processUsers(result.users);
1068
1087
  }
1088
+ if (result instanceof types.MessagesMessages) {
1089
+ for (const message of result.messages) {
1090
+ if (message instanceof types.Message || message instanceof types.MessageService) {
1091
+ await this.storage.setMessage((0, _0_utilities_js_1.peerToChatId)(message.peerId), message.id, message);
1092
+ }
1093
+ }
1094
+ }
1069
1095
  }
1070
1096
  async updatesToMessages(chatId, updates) {
1071
1097
  const messages = new Array();
@@ -1147,22 +1173,37 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1147
1173
  }));
1148
1174
  return await this.updatesToMessages(chatId, result).then((v) => v[0]);
1149
1175
  }
1150
- async getMessages(chatId, messageIds) {
1151
- const peer = await this.getInputPeer(chatId);
1152
- let messages_;
1153
- if (peer instanceof types.InputPeerChannel) {
1154
- messages_ = await this.invoke(new functions.ChannelsGetMessages({
1155
- channel: new types.InputChannel({ channelId: peer.channelId, accessHash: peer.accessHash }),
1156
- id: messageIds.map((v) => new types.InputMessageID({ id: v })),
1157
- })).then((v) => v[_1_tl_object_js_1.as](types.MessagesChannelMessages));
1176
+ async getMessages(chatId_, messageIds) {
1177
+ const peer = await this.getInputPeer(chatId_);
1178
+ let messages_ = new Array();
1179
+ const chatId = (0, _0_utilities_js_1.peerToChatId)(peer);
1180
+ let shouldFetch = false;
1181
+ for (const messageId of messageIds) {
1182
+ const message = await this.storage.getMessage(chatId, messageId);
1183
+ if (message == null) {
1184
+ messages_ = [];
1185
+ shouldFetch = true;
1186
+ break;
1187
+ }
1188
+ else {
1189
+ messages_.push(message);
1190
+ }
1158
1191
  }
1159
- else {
1160
- messages_ = await this.invoke(new functions.MessagesGetMessages({
1161
- id: messageIds.map((v) => new types.InputMessageID({ id: v })),
1162
- })).then((v) => v[_1_tl_object_js_1.as](types.MessagesMessages));
1192
+ if (shouldFetch) {
1193
+ if (peer instanceof types.InputPeerChannel) {
1194
+ messages_ = await this.invoke(new functions.ChannelsGetMessages({
1195
+ channel: new types.InputChannel({ channelId: peer.channelId, accessHash: peer.accessHash }),
1196
+ id: messageIds.map((v) => new types.InputMessageID({ id: v })),
1197
+ })).then((v) => v[_1_tl_object_js_1.as](types.MessagesChannelMessages).messages);
1198
+ }
1199
+ else {
1200
+ messages_ = await this.invoke(new functions.MessagesGetMessages({
1201
+ id: messageIds.map((v) => new types.InputMessageID({ id: v })),
1202
+ })).then((v) => v[_1_tl_object_js_1.as](types.MessagesMessages).messages);
1203
+ }
1163
1204
  }
1164
1205
  const messages = new Array();
1165
- for (const message_ of messages_.messages) {
1206
+ for (const message_ of messages_) {
1166
1207
  messages.push(await (0, _3_message_js_1.constructMessage)(message_, this[exports.getEntity].bind(this), null, this[exports.getStickerSetName].bind(this)));
1167
1208
  }
1168
1209
  return messages;
@@ -1262,8 +1303,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1262
1303
  }));
1263
1304
  return await this.updatesToMessages(to, result);
1264
1305
  }
1265
- forwardMessage(from, to, messageId, params) {
1266
- return this.forwardMessages(from, to, [messageId], params);
1306
+ async forwardMessage(from, to, messageId, params) {
1307
+ return await this.forwardMessages(from, to, [messageId], params).then((v) => v[0]);
1267
1308
  }
1268
1309
  }
1269
1310
  exports.Client = Client;
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.957";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.960";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
88
88
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
89
89
  exports.DEFAULT_INITIAL_DC = "2-test";
90
90
  exports.LAYER = 158;
91
- exports.DEFAULT_APP_VERSION = "MTKruto 0.0.957";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.960";
92
92
  // @ts-ignore: lib
93
93
  exports.DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
94
94
  exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -1,33 +1,34 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
2
  import { DC } from "../transport/2_transport_provider.js";
3
+ import { TLObject } from "../tl/1_tl_object.js";
3
4
  import * as types from "../tl/2_types.js";
5
+ export type StorageKeyPart = string | number | bigint | Uint8Array;
4
6
  export declare abstract class Storage {
5
7
  private _authKeyId;
6
8
  abstract init(): MaybePromise<void>;
7
- abstract set(key: string, value: string | null): MaybePromise<void>;
8
- abstract get(key: string): MaybePromise<string | null>;
9
+ abstract set(key: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
10
+ abstract get<T>(key: readonly StorageKeyPart[]): MaybePromise<T | null>;
9
11
  setDc(dc: DC | null): MaybePromise<void>;
10
- getDc(): Promise<DC | null>;
12
+ getDc(): MaybePromise<DC | null>;
11
13
  private resetAuthKeyId;
12
14
  getAuthKey(): Promise<Uint8Array | null>;
13
15
  setAuthKey(authKey: Uint8Array | null): Promise<void>;
14
16
  get authKeyId(): bigint | null;
15
- private readonly channelAccessHash__;
16
17
  setChannelAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
17
- getChannelAccessHash(id: bigint): Promise<bigint | null>;
18
- private readonly userAccessHash__;
18
+ getChannelAccessHash(id: bigint): MaybePromise<bigint | null>;
19
19
  setUserAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
20
- getUserAccessHash(id: bigint): Promise<bigint | null>;
21
- private readonly username__;
20
+ getUserAccessHash(id: bigint): MaybePromise<bigint | null>;
22
21
  updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
23
- getUsername(username: string): Promise<readonly ["channel" | "user", bigint, Date] | null>;
24
- private readonly state__;
22
+ getUsername(username: string): MaybePromise<["channel" | "user", bigint, Date] | null>;
23
+ setTlObject(key: readonly StorageKeyPart[], value: TLObject | null): Promise<void>;
24
+ getTLObject(key: readonly StorageKeyPart[]): Promise<import("../tl/3_tl_reader.js").ReadObject | null>;
25
25
  setState(state: types.UpdatesState): Promise<void>;
26
26
  getState(): Promise<types.UpdatesState | null>;
27
- private readonly channelPts__;
27
+ setMessage(chatId: number, messageId: number, message: types.TypeMessage | null): Promise<void>;
28
+ getMessageChat(messageId: number): MaybePromise<number | null>;
29
+ getMessage(chatId: number, messageId: number): Promise<types.TypeMessage | null>;
28
30
  setChannelPts(channelId: bigint, pts: number): Promise<void>;
29
- getChannelPts(channelId: bigint): Promise<number | null>;
30
- private readonly peer__;
31
+ getChannelPts(channelId: bigint): MaybePromise<number | null>;
31
32
  setEntity(peer: types.Channel): Promise<void>;
32
33
  setEntity(peer: types.Chat): Promise<void>;
33
34
  setEntity(peer: types.User): Promise<void>;
@@ -35,10 +36,8 @@ export declare abstract class Storage {
35
36
  getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
36
37
  getEntity(type: "user", id: bigint): Promise<types.User | null>;
37
38
  getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
38
- private readonly accountType__;
39
39
  setAccountType(type: "user" | "bot"): Promise<void>;
40
- getAccountType(): Promise<"bot" | "user">;
41
- private readonly stickerSetName__;
40
+ getAccountType(): MaybePromise<"bot" | "user" | null>;
42
41
  updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
43
- getStickerSetName(id: bigint, accessHash: bigint): Promise<[string, Date] | null>;
42
+ getStickerSetName(id: bigint, accessHash: bigint): MaybePromise<[string, Date] | null>;
44
43
  }