@mtkruto/node 0.0.935 → 0.0.937
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/client/3_client.js +5 -5
- package/esm/constants.d.ts +1 -1
- package/esm/constants.js +1 -1
- package/esm/types/0_chat_administrator_rights.d.ts +13 -0
- package/esm/types/0_chat_photo.d.ts +6 -0
- package/esm/types/0_force_reply.d.ts +4 -0
- package/esm/types/0_keyboard_button_poll_type.d.ts +2 -0
- package/esm/types/0_login_url.d.ts +5 -0
- package/esm/types/0_message_entity.d.ts +7 -0
- package/esm/types/0_reply_keyboard_remove.d.ts +3 -0
- package/esm/types/0_thumbnail.d.ts +5 -0
- package/esm/types/0_web_app_info.d.ts +2 -0
- package/esm/types/1_chat.d.ts +32 -0
- package/esm/types/1_inline_keyboard_button.d.ts +9 -0
- package/esm/types/1_keyboard_button.d.ts +21 -0
- package/esm/types/1_photo.d.ts +5 -0
- package/esm/types/1_user.d.ts +15 -0
- package/esm/types/2_inline_keyboard_markup.d.ts +2 -0
- package/esm/types/2_reply_keyboard_markup.d.ts +7 -0
- package/esm/types/3_message.d.ts +36 -4
- package/esm/types/3_message.js +58 -32
- package/package.json +1 -1
- package/script/client/3_client.js +5 -5
- package/script/constants.d.ts +1 -1
- package/script/constants.js +1 -1
- package/script/types/0_chat_administrator_rights.d.ts +13 -0
- package/script/types/0_chat_photo.d.ts +6 -0
- package/script/types/0_force_reply.d.ts +4 -0
- package/script/types/0_keyboard_button_poll_type.d.ts +2 -0
- package/script/types/0_login_url.d.ts +5 -0
- package/script/types/0_message_entity.d.ts +7 -0
- package/script/types/0_reply_keyboard_remove.d.ts +3 -0
- package/script/types/0_thumbnail.d.ts +5 -0
- package/script/types/0_web_app_info.d.ts +2 -0
- package/script/types/1_chat.d.ts +32 -0
- package/script/types/1_inline_keyboard_button.d.ts +9 -0
- package/script/types/1_keyboard_button.d.ts +21 -0
- package/script/types/1_photo.d.ts +5 -0
- package/script/types/1_user.d.ts +15 -0
- package/script/types/2_inline_keyboard_markup.d.ts +2 -0
- package/script/types/2_reply_keyboard_markup.d.ts +7 -0
- package/script/types/3_message.d.ts +36 -4
- package/script/types/3_message.js +58 -32
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import * as types from "../tl/2_types.js";
|
|
2
2
|
import { KeyboardButton } from "./1_keyboard_button.js";
|
|
3
|
+
/** This object represents a [custom keyboard](https://core.telegram.org/bots/features#keyboards) with reply options (see [Introduction to bots](https://core.telegram.org/bots/features#keyboards) for details and examples). */
|
|
3
4
|
export interface ReplyKeyboardMarkup {
|
|
5
|
+
/** Array of button rows, each represented by an Array of `KeyboardButton` objects */
|
|
4
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. */
|
|
5
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. */
|
|
6
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. */
|
|
7
12
|
oneTimeKeyboard?: boolean;
|
|
13
|
+
/** Optional. The placeholder to be shown in the input field when the keyboard is active; 1-64 characters */
|
|
8
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. */
|
|
9
16
|
selective?: boolean;
|
|
10
17
|
}
|
|
11
18
|
export declare function constructReplyKeyboardMarkup(keyboard_: types.ReplyKeyboardMarkup): ReplyKeyboardMarkup;
|
|
@@ -18,34 +18,63 @@ import { Voice } from "./0_voice.js";
|
|
|
18
18
|
import { Dice } from "./0_dice.js";
|
|
19
19
|
import { Contact } from "./0_contact.js";
|
|
20
20
|
import { Game } from "./2_game.js";
|
|
21
|
+
/** This object represents a message. */
|
|
21
22
|
export interface Message {
|
|
23
|
+
/** Unique message identifier inside this chat */
|
|
22
24
|
id: number;
|
|
25
|
+
/** Optional. Unique identifier of a message thread to which the message belongs; for supergroups only */
|
|
23
26
|
threadId?: number;
|
|
27
|
+
/** 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. */
|
|
24
28
|
from?: User;
|
|
29
|
+
/** 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. */
|
|
25
30
|
senderChat?: Chat;
|
|
31
|
+
/** Date the message was sent in Unix time */
|
|
26
32
|
date?: Date;
|
|
33
|
+
/** Conversation the message belongs to */
|
|
27
34
|
chat: Chat;
|
|
35
|
+
/** Optional. For forwarded messages, sender of the original message */
|
|
28
36
|
forwardFrom?: User;
|
|
37
|
+
/** Optional. For messages forwarded from channels or from anonymous administrators, information about the original sender chat */
|
|
29
38
|
forwardFromChat?: Chat;
|
|
39
|
+
/** Optional. For messages forwarded from channels, identifier of the original message in the channel */
|
|
30
40
|
forwardId?: number;
|
|
41
|
+
/** Optional. For forwarded messages that were originally sent in channels or by an anonymous chat administrator, signature of the message sender if present */
|
|
31
42
|
forwardSignature?: string;
|
|
43
|
+
/** Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages */
|
|
32
44
|
forwardSenderName?: string;
|
|
45
|
+
/** Optional. For forwarded messages, date the original message was sent in Unix time */
|
|
33
46
|
forwardDate?: Date;
|
|
47
|
+
/** Optional. True, if the message is sent to a forum topic */
|
|
34
48
|
isTopicMessage: boolean;
|
|
49
|
+
/** Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group */
|
|
35
50
|
isAutomaticForward?: boolean;
|
|
51
|
+
/** 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. */
|
|
36
52
|
replyToMessage?: Omit<Message, "replyToMessage">;
|
|
53
|
+
/** Optional. Bot through which the message was sent */
|
|
37
54
|
viaBot?: User;
|
|
55
|
+
/** Optional. Date the message was last edited in Unix time */
|
|
38
56
|
editDate?: Date;
|
|
39
|
-
|
|
57
|
+
/** Optional. True, if the message can't be forwarded */
|
|
58
|
+
hasProtectedContent?: boolean;
|
|
59
|
+
/** Optional. The unique identifier of a media message group this message belongs to */
|
|
40
60
|
mediaGroupId?: string;
|
|
61
|
+
/** Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator */
|
|
41
62
|
authorSignature?: string;
|
|
63
|
+
/** Optional. For text messages, the actual UTF-8 text of the message */
|
|
42
64
|
text?: string;
|
|
65
|
+
/** Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text */
|
|
43
66
|
entities?: MessageEntity[];
|
|
67
|
+
/** Optional. Caption for the animation, audio, document, photo, video or voice */
|
|
44
68
|
caption?: string;
|
|
69
|
+
/** Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption */
|
|
45
70
|
captionEntities?: MessageEntity[];
|
|
71
|
+
/** Optional. True, if the message media is covered by a spoiler animation */
|
|
46
72
|
hasMediaSpoiler?: boolean;
|
|
73
|
+
/** Optional. View count for channel posts */
|
|
47
74
|
views?: number;
|
|
75
|
+
/** Optional. Inline keyboard attached to the message. `login_url` buttons are represented as ordinary `url` buttons. */
|
|
48
76
|
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
77
|
+
/** Optional. Message is a photo, available sizes of the photo */
|
|
49
78
|
photo?: Photo;
|
|
50
79
|
document?: Document;
|
|
51
80
|
video?: Video;
|
|
@@ -58,10 +87,13 @@ export interface Message {
|
|
|
58
87
|
contact?: Contact;
|
|
59
88
|
game?: Game;
|
|
60
89
|
}
|
|
61
|
-
|
|
90
|
+
interface EntityGetter {
|
|
62
91
|
(peer: types.PeerUser): MaybePromise<types.User | null>;
|
|
63
92
|
(peer: types.PeerChat): MaybePromise<types.Chat | null>;
|
|
64
93
|
(peer: types.PeerChannel): MaybePromise<types.Channel | null>;
|
|
65
|
-
}
|
|
94
|
+
}
|
|
95
|
+
type MessageGetter = {
|
|
66
96
|
(chatId: number, messageId: number): MaybePromise<Omit<Message, "replyToMessage"> | null>;
|
|
67
|
-
} | null
|
|
97
|
+
} | null;
|
|
98
|
+
export declare function constructMessage(message_: types.TypeMessage, getEntity: EntityGetter, getMessage: MessageGetter, getStickerSetName: StickerSetNameGetter): Promise<Message>;
|
|
99
|
+
export {};
|
|
@@ -48,7 +48,59 @@ const _0_file_id_js_1 = require("./!0_file_id.js");
|
|
|
48
48
|
const _0_contact_js_1 = require("./0_contact.js");
|
|
49
49
|
const _2_game_js_1 = require("./2_game.js");
|
|
50
50
|
const d = (0, deps_js_1.debug)("types/Message");
|
|
51
|
+
async function getSender(message_, getEntity) {
|
|
52
|
+
if (message_.fromId instanceof types.PeerUser) {
|
|
53
|
+
const entity = await getEntity(message_.fromId);
|
|
54
|
+
if (entity) {
|
|
55
|
+
return { from: (0, _1_user_js_1.constructUser)(entity) };
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (message_.fromId instanceof types.PeerChannel) {
|
|
62
|
+
const entity = await getEntity(message_.fromId);
|
|
63
|
+
if (entity) {
|
|
64
|
+
return { senderChat: (0, _1_chat_js_1.constructChat)(entity) };
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function getReply(message_, chat, getMessage) {
|
|
72
|
+
if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
|
|
73
|
+
let isTopicMessage = false;
|
|
74
|
+
if (message_.replyTo.forumTopic) {
|
|
75
|
+
isTopicMessage = true;
|
|
76
|
+
}
|
|
77
|
+
const replyToMessage = await getMessage(chat.id, message_.replyTo.replyToMsgId);
|
|
78
|
+
if (replyToMessage) {
|
|
79
|
+
return { replyToMessage, threadId: message_.replyTo.replyToTopId, isTopicMessage };
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
d("couldn't get replied message");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return {};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function constructServiceMessage(message_, chat, getEntity, getMessage) {
|
|
90
|
+
const message = {
|
|
91
|
+
id: message_.id,
|
|
92
|
+
chat: chat,
|
|
93
|
+
date: new Date(message_.date * 1000),
|
|
94
|
+
isTopicMessage: false,
|
|
95
|
+
};
|
|
96
|
+
Object.assign(message, await getReply(message_, chat, getMessage));
|
|
97
|
+
Object.assign(message, await getSender(message_, getEntity));
|
|
98
|
+
return message;
|
|
99
|
+
}
|
|
51
100
|
async function constructMessage(message_, getEntity, getMessage, getStickerSetName) {
|
|
101
|
+
if (!(message_ instanceof types.Message) && !(message_ instanceof types.MessageService)) {
|
|
102
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
103
|
+
}
|
|
52
104
|
let chat_ = null;
|
|
53
105
|
if (message_.peerId instanceof types.PeerUser) {
|
|
54
106
|
const entity = await getEntity(message_.peerId);
|
|
@@ -80,37 +132,25 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
|
|
|
80
132
|
else {
|
|
81
133
|
(0, _0_control_js_1.UNREACHABLE)();
|
|
82
134
|
}
|
|
135
|
+
if (message_ instanceof types.MessageService) {
|
|
136
|
+
return await constructServiceMessage(message_, chat_, getEntity, getMessage);
|
|
137
|
+
}
|
|
83
138
|
const message = {
|
|
84
139
|
id: message_.id,
|
|
85
140
|
chat: chat_,
|
|
141
|
+
date: new Date(message_.date * 1000),
|
|
86
142
|
views: message_.views,
|
|
87
143
|
isTopicMessage: false,
|
|
88
144
|
hasProtectedContent: message_.noforwards || false,
|
|
89
145
|
};
|
|
146
|
+
Object.assign(message, await getReply(message_, chat_, getMessage));
|
|
147
|
+
Object.assign(message, await getSender(message_, getEntity));
|
|
90
148
|
if (message_.media instanceof types.MessageMediaPhoto || message_.media instanceof types.MessageMediaDocument) {
|
|
91
149
|
message.hasMediaSpoiler = message_.media.spoiler || false;
|
|
92
150
|
}
|
|
93
151
|
if (message_.groupedId != undefined) {
|
|
94
152
|
message.mediaGroupId = String(message_.groupedId);
|
|
95
153
|
}
|
|
96
|
-
if (message_.fromId instanceof types.PeerUser) {
|
|
97
|
-
const entity = await getEntity(message_.fromId);
|
|
98
|
-
if (entity) {
|
|
99
|
-
message.from = (0, _1_user_js_1.constructUser)(entity);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
(0, _0_control_js_1.UNREACHABLE)();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else if (message_.fromId instanceof types.PeerChannel) {
|
|
106
|
-
const entity = await getEntity(message_.fromId);
|
|
107
|
-
if (entity) {
|
|
108
|
-
message.senderChat = (0, _1_chat_js_1.constructChat)(entity);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
(0, _0_control_js_1.UNREACHABLE)();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
154
|
if (message_.message) {
|
|
115
155
|
if (message_.media == undefined) {
|
|
116
156
|
message.text = message_.message;
|
|
@@ -127,7 +167,6 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
|
|
|
127
167
|
message.captionEntities = message_.entities.map(_0_message_entity_js_1.constructMessageEntity).filter((v) => v);
|
|
128
168
|
}
|
|
129
169
|
}
|
|
130
|
-
message.date = new Date(message_.date * 1000);
|
|
131
170
|
if (message_.editDate != undefined) {
|
|
132
171
|
message.editDate = new Date(message_.editDate * 1000);
|
|
133
172
|
}
|
|
@@ -148,19 +187,6 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
|
|
|
148
187
|
(0, _0_control_js_1.UNREACHABLE)();
|
|
149
188
|
}
|
|
150
189
|
}
|
|
151
|
-
if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
|
|
152
|
-
if (message_.replyTo.forumTopic) {
|
|
153
|
-
message.isTopicMessage = true;
|
|
154
|
-
}
|
|
155
|
-
const replyToMessage = await getMessage(message.chat.id, message_.replyTo.replyToMsgId);
|
|
156
|
-
if (replyToMessage) {
|
|
157
|
-
message.replyToMessage = replyToMessage;
|
|
158
|
-
message.threadId = message_.replyTo.replyToTopId;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
d("couldn't get replied message");
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
190
|
if (message_.viaBotId != undefined) {
|
|
165
191
|
const viaBot = await getEntity(new types.PeerUser({ userId: message_.viaBotId }));
|
|
166
192
|
if (viaBot) {
|