@mtkruto/node 0.0.834 → 0.0.835
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/client.d.ts +7 -2
- package/esm/client/client.js +42 -5
- package/esm/client/client_abstract.d.ts +1 -1
- package/esm/connection/connection.d.ts +1 -1
- package/esm/storage/storage.d.ts +1 -1
- package/esm/storage/storage_local_storage.d.ts +1 -1
- package/esm/storage/storage_memory.d.ts +1 -1
- package/esm/storage/storage_session_storage.d.ts +1 -1
- package/esm/transport/transport.d.ts +1 -1
- package/esm/types/0_chat_administrator_rights.d.ts +17 -0
- package/esm/types/0_chat_administrator_rights.js +38 -0
- package/esm/types/0_chat_photo.d.ts +24 -0
- package/esm/types/0_chat_photo.js +28 -0
- package/esm/types/0_force_reply.d.ts +8 -0
- package/esm/types/0_force_reply.js +17 -0
- package/esm/types/0_keyboard_button_poll_type.d.ts +3 -0
- package/esm/types/0_login_url.d.ts +6 -0
- package/esm/types/0_login_url.js +1 -0
- package/esm/types/0_message_entity.d.ts +1 -1
- package/esm/types/0_message_entity.js +2 -2
- package/esm/types/0_reply_keyboard_remove.d.ts +7 -0
- package/esm/types/0_reply_keyboard_remove.js +8 -0
- package/esm/types/0_web_app_info.d.ts +4 -0
- package/esm/types/0_web_app_info.js +3 -0
- package/esm/types/1_chat.d.ts +60 -0
- package/esm/types/1_chat.js +70 -0
- package/esm/types/1_inline_keyboard_button.d.ts +33 -0
- package/esm/types/1_inline_keyboard_button.js +63 -0
- package/esm/types/1_keyboard_button.d.ts +43 -0
- package/esm/types/1_keyboard_button.js +133 -0
- package/esm/types/1_user.d.ts +19 -0
- package/esm/types/1_user.js +25 -0
- package/esm/types/2_inline_keyboard_markup.d.ts +7 -0
- package/esm/types/2_inline_keyboard_markup.js +25 -0
- package/esm/types/2_reply_keyboard_markup.d.ts +12 -0
- package/esm/types/2_reply_keyboard_markup.js +37 -0
- package/esm/types/3_message.d.ts +22 -0
- package/esm/types/3_message.js +87 -0
- package/esm/utilities/0_control.d.ts +1 -0
- package/esm/utilities/0_control.js +3 -0
- package/esm/utilities/0_object.d.ts +1 -0
- package/esm/utilities/0_object.js +14 -0
- package/esm/utilities/0_types.js +1 -0
- package/package.json +1 -1
- package/script/client/client.d.ts +7 -2
- package/script/client/client.js +42 -5
- package/script/client/client_abstract.d.ts +1 -1
- package/script/connection/connection.d.ts +1 -1
- package/script/storage/storage.d.ts +1 -1
- package/script/storage/storage_local_storage.d.ts +1 -1
- package/script/storage/storage_memory.d.ts +1 -1
- package/script/storage/storage_session_storage.d.ts +1 -1
- package/script/transport/transport.d.ts +1 -1
- package/script/types/0_chat_administrator_rights.d.ts +17 -0
- package/script/types/0_chat_administrator_rights.js +66 -0
- package/script/types/0_chat_photo.d.ts +24 -0
- package/script/types/0_chat_photo.js +55 -0
- package/script/types/0_force_reply.d.ts +8 -0
- package/script/types/0_force_reply.js +45 -0
- package/script/types/0_keyboard_button_poll_type.d.ts +3 -0
- package/script/types/0_login_url.d.ts +6 -0
- package/script/types/0_login_url.js +2 -0
- package/script/types/0_message_entity.d.ts +1 -1
- package/script/types/0_message_entity.js +2 -2
- package/script/types/0_reply_keyboard_remove.d.ts +7 -0
- package/script/types/0_reply_keyboard_remove.js +36 -0
- package/script/types/0_web_app_info.d.ts +4 -0
- package/script/types/0_web_app_info.js +7 -0
- package/script/types/1_chat.d.ts +60 -0
- package/script/types/1_chat.js +97 -0
- package/script/types/1_inline_keyboard_button.d.ts +33 -0
- package/script/types/1_inline_keyboard_button.js +91 -0
- package/script/types/1_keyboard_button.d.ts +43 -0
- package/script/types/1_keyboard_button.js +161 -0
- package/script/types/1_user.d.ts +19 -0
- package/script/types/1_user.js +52 -0
- package/script/types/2_inline_keyboard_markup.d.ts +7 -0
- package/script/types/2_inline_keyboard_markup.js +53 -0
- package/script/types/2_reply_keyboard_markup.d.ts +12 -0
- package/script/types/2_reply_keyboard_markup.js +65 -0
- package/script/types/3_message.d.ts +22 -0
- package/script/types/3_message.js +114 -0
- package/script/utilities/0_control.d.ts +1 -0
- package/script/utilities/0_control.js +7 -0
- package/script/utilities/0_object.d.ts +1 -0
- package/script/utilities/0_object.js +18 -0
- package/script/utilities/0_types.js +2 -0
- /package/esm/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
- /package/esm/{types.d.ts → utilities/0_types.d.ts} +0 -0
- /package/script/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
- /package/script/{types.d.ts → utilities/0_types.d.ts} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
2
|
+
import { as } from "../tl/1_tl_object.js";
|
|
3
|
+
import * as types from "../tl/2_types.js";
|
|
4
|
+
import { chatAdministratorRightsToTlObject, constructChatAdministratorRights } from "./0_chat_administrator_rights.js";
|
|
5
|
+
export function constructKeyboardButton(button_) {
|
|
6
|
+
if (button_ instanceof types.KeyboardButton) {
|
|
7
|
+
return { text: button_.text };
|
|
8
|
+
}
|
|
9
|
+
else if (button_ instanceof types.KeyboardButtonRequestPeer) {
|
|
10
|
+
if (button_.peerType instanceof types.RequestPeerTypeUser) {
|
|
11
|
+
return {
|
|
12
|
+
text: button_.text,
|
|
13
|
+
requestUser: {
|
|
14
|
+
requestId: button_.buttonId,
|
|
15
|
+
userIsBot: button_.peerType.bot || false,
|
|
16
|
+
userIsPremium: button_.peerType.premium || false,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
else if (button_.peerType instanceof types.RequestPeerTypeChat) {
|
|
21
|
+
const button = {
|
|
22
|
+
text: button_.text,
|
|
23
|
+
requestChat: {
|
|
24
|
+
requestId: button_.buttonId,
|
|
25
|
+
chatIsChannel: false,
|
|
26
|
+
chatIsForum: button_.peerType.forum || false,
|
|
27
|
+
chatHasUsername: button_.peerType.hasUsername || false,
|
|
28
|
+
chatIsCreated: button_.peerType.creator || false,
|
|
29
|
+
botIsMember: button_.peerType.botParticipant || false,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
if (button_.peerType.botAdminRights) {
|
|
33
|
+
button.requestChat.botAdministratorRights = constructChatAdministratorRights(button_.peerType.botAdminRights[as](types.ChatAdminRights));
|
|
34
|
+
}
|
|
35
|
+
if (button_.peerType.userAdminRights) {
|
|
36
|
+
button.requestChat.userAdministratorRights = constructChatAdministratorRights(button_.peerType.userAdminRights[as](types.ChatAdminRights));
|
|
37
|
+
}
|
|
38
|
+
return button;
|
|
39
|
+
}
|
|
40
|
+
else if (button_.peerType instanceof types.RequestPeerTypeBroadcast) {
|
|
41
|
+
const button = {
|
|
42
|
+
text: button_.text,
|
|
43
|
+
requestChat: {
|
|
44
|
+
requestId: button_.buttonId,
|
|
45
|
+
chatIsChannel: true,
|
|
46
|
+
chatIsCreated: button_.peerType.creator || false,
|
|
47
|
+
chatHasUsername: button_.peerType.hasUsername || false,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
if (button_.peerType.botAdminRights) {
|
|
51
|
+
button.requestChat.botAdministratorRights = constructChatAdministratorRights(button_.peerType.botAdminRights[as](types.ChatAdminRights));
|
|
52
|
+
}
|
|
53
|
+
if (button_.peerType.userAdminRights) {
|
|
54
|
+
button.requestChat.userAdministratorRights = constructChatAdministratorRights(button_.peerType.userAdminRights[as](types.ChatAdminRights));
|
|
55
|
+
}
|
|
56
|
+
return button;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
UNREACHABLE();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (button_ instanceof types.KeyboardButtonRequestPhone) {
|
|
63
|
+
return { text: button_.text, requestContact: true };
|
|
64
|
+
}
|
|
65
|
+
else if (button_ instanceof types.KeyboardButtonRequestGeoLocation) {
|
|
66
|
+
return { text: button_.text, requestLocation: true };
|
|
67
|
+
}
|
|
68
|
+
else if (button_ instanceof types.KeyboardButtonRequestPoll) {
|
|
69
|
+
const button = { text: button_.text, requestPoll: {} };
|
|
70
|
+
if (button_.quiz) {
|
|
71
|
+
button.requestPoll.type = "quiz";
|
|
72
|
+
}
|
|
73
|
+
return button;
|
|
74
|
+
}
|
|
75
|
+
else if (button_ instanceof types.KeyboardButtonWebView || button_ instanceof types.KeyboardButtonSimpleWebView) {
|
|
76
|
+
return { text: button_.text, webApp: { url: button_.url } };
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
UNREACHABLE();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function keyboardButtonToTlObject(button) {
|
|
83
|
+
if ("requestUser" in button) {
|
|
84
|
+
return new types.KeyboardButtonRequestPeer({
|
|
85
|
+
text: button.text,
|
|
86
|
+
buttonId: button.requestUser.requestId,
|
|
87
|
+
peerType: new types.RequestPeerTypeUser({ bot: button.requestUser.userIsBot, premium: button.requestUser.userIsPremium }),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else if ("requestChat" in button) {
|
|
91
|
+
if (!button.requestChat.chatIsChannel) { // GUESS
|
|
92
|
+
return new types.KeyboardButtonRequestPeer({
|
|
93
|
+
text: button.text,
|
|
94
|
+
buttonId: button.requestChat.requestId,
|
|
95
|
+
peerType: new types.RequestPeerTypeChat({
|
|
96
|
+
forum: button.requestChat.chatIsForum,
|
|
97
|
+
hasUsername: button.requestChat.chatHasUsername,
|
|
98
|
+
creator: button.requestChat.chatIsCreated || undefined,
|
|
99
|
+
botParticipant: button.requestChat.botIsMember || undefined,
|
|
100
|
+
botAdminRights: button.requestChat.botAdministratorRights ? chatAdministratorRightsToTlObject(button.requestChat.botAdministratorRights) : undefined,
|
|
101
|
+
userAdminRights: button.requestChat.userAdministratorRights ? chatAdministratorRightsToTlObject(button.requestChat.userAdministratorRights) : undefined,
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return new types.KeyboardButtonRequestPeer({
|
|
107
|
+
text: button.text,
|
|
108
|
+
buttonId: button.requestChat.requestId,
|
|
109
|
+
peerType: new types.RequestPeerTypeBroadcast({
|
|
110
|
+
hasUsername: button.requestChat.chatHasUsername,
|
|
111
|
+
creator: button.requestChat.chatIsCreated || undefined,
|
|
112
|
+
botAdminRights: button.requestChat.botAdministratorRights ? chatAdministratorRightsToTlObject(button.requestChat.botAdministratorRights) : undefined,
|
|
113
|
+
userAdminRights: button.requestChat.userAdministratorRights ? chatAdministratorRightsToTlObject(button.requestChat.userAdministratorRights) : undefined,
|
|
114
|
+
}),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if ("requestContact" in button) {
|
|
119
|
+
return new types.KeyboardButtonRequestPhone({ text: button.text });
|
|
120
|
+
}
|
|
121
|
+
else if ("requestLocation" in button) {
|
|
122
|
+
return new types.KeyboardButtonRequestGeoLocation({ text: button.text });
|
|
123
|
+
}
|
|
124
|
+
else if ("requestPoll" in button) {
|
|
125
|
+
return new types.KeyboardButtonRequestPoll({ text: button.text, quiz: button.requestPoll.type == "quiz" });
|
|
126
|
+
}
|
|
127
|
+
else if ("webApp" in button) {
|
|
128
|
+
return new types.KeyboardButtonWebView({ text: button.text, url: button.webApp.url });
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
UNREACHABLE();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
import { ChatPhoto } from "./0_chat_photo.js";
|
|
3
|
+
export interface User {
|
|
4
|
+
id: number;
|
|
5
|
+
isBot: boolean;
|
|
6
|
+
firstName: string;
|
|
7
|
+
lastName?: string;
|
|
8
|
+
username?: string;
|
|
9
|
+
also?: string[];
|
|
10
|
+
photo?: ChatPhoto.User;
|
|
11
|
+
languageCode?: string;
|
|
12
|
+
isScam: boolean;
|
|
13
|
+
isFake: boolean;
|
|
14
|
+
isPremium: boolean;
|
|
15
|
+
isVerified: boolean;
|
|
16
|
+
isSupport: boolean;
|
|
17
|
+
addedToAttachmentMenu: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function constructUser(user_: types.User): User;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { cleanObject } from "../utilities/0_object.js";
|
|
2
|
+
import { as } from "../tl/1_tl_object.js";
|
|
3
|
+
import * as types from "../tl/2_types.js";
|
|
4
|
+
import { constructChatPhoto } from "./0_chat_photo.js";
|
|
5
|
+
export function constructUser(user_) {
|
|
6
|
+
const user = {
|
|
7
|
+
id: Number(user_.id),
|
|
8
|
+
isBot: user_.bot || false,
|
|
9
|
+
firstName: user_.firstName || "",
|
|
10
|
+
lastName: user_.lastName,
|
|
11
|
+
username: user_.username,
|
|
12
|
+
also: user_.usernames?.map((v) => v[as](types.Username)).map((v) => v.username),
|
|
13
|
+
languageCode: user_.langCode,
|
|
14
|
+
isScam: user_.scam || false,
|
|
15
|
+
isFake: user_.fake || false,
|
|
16
|
+
isPremium: user_.premium || false,
|
|
17
|
+
isVerified: user_.verified || false,
|
|
18
|
+
isSupport: user_.support || false,
|
|
19
|
+
addedToAttachmentMenu: user_.attachMenuEnabled || false,
|
|
20
|
+
};
|
|
21
|
+
if (user_.photo instanceof types.UserProfilePhoto) {
|
|
22
|
+
user.photo = constructChatPhoto(user_.photo);
|
|
23
|
+
}
|
|
24
|
+
return cleanObject(user);
|
|
25
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
import { InlineKeyboardButton, inlineKeyboardButtonToTlObject } from "./1_inline_keyboard_button.js";
|
|
3
|
+
export interface InlineKeyboardMarkup {
|
|
4
|
+
inlineKeyboard: InlineKeyboardButton[][];
|
|
5
|
+
}
|
|
6
|
+
export declare function constructInlineKeyboardMarkup(keyboard_: types.ReplyInlineMarkup): InlineKeyboardMarkup;
|
|
7
|
+
export declare function inlineKeyboardMarkupToTlObject(keyboard: InlineKeyboardMarkup, usernameResolver: Parameters<typeof inlineKeyboardButtonToTlObject>[1]): Promise<types.ReplyInlineMarkup>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { as } from "../tl/1_tl_object.js";
|
|
2
|
+
import * as types from "../tl/2_types.js";
|
|
3
|
+
import { constructInlineKeyboardButton, inlineKeyboardButtonToTlObject } from "./1_inline_keyboard_button.js";
|
|
4
|
+
export function constructInlineKeyboardMarkup(keyboard_) {
|
|
5
|
+
const rows = new Array();
|
|
6
|
+
for (const row_ of keyboard_.rows.map((v) => v[as](types.KeyboardButtonRow))) {
|
|
7
|
+
const row = new Array();
|
|
8
|
+
for (const button_ of row_.buttons) {
|
|
9
|
+
row.push(constructInlineKeyboardButton(button_));
|
|
10
|
+
}
|
|
11
|
+
rows.push(row);
|
|
12
|
+
}
|
|
13
|
+
return { inlineKeyboard: rows };
|
|
14
|
+
}
|
|
15
|
+
export async function inlineKeyboardMarkupToTlObject(keyboard, usernameResolver) {
|
|
16
|
+
const rows_ = new Array();
|
|
17
|
+
for (const row of keyboard.inlineKeyboard) {
|
|
18
|
+
const row_ = new Array();
|
|
19
|
+
for (const button of row) {
|
|
20
|
+
row_.push(await inlineKeyboardButtonToTlObject(button, usernameResolver));
|
|
21
|
+
}
|
|
22
|
+
rows_.push(new types.KeyboardButtonRow({ buttons: row_ }));
|
|
23
|
+
}
|
|
24
|
+
return new types.ReplyInlineMarkup({ rows: rows_ });
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
import { KeyboardButton } from "./1_keyboard_button.js";
|
|
3
|
+
export interface ReplyKeyboardMarkup {
|
|
4
|
+
keyboard: KeyboardButton[][];
|
|
5
|
+
isPersistent?: boolean;
|
|
6
|
+
resizeKeyboard?: boolean;
|
|
7
|
+
oneTimeKeyboard?: boolean;
|
|
8
|
+
inputFieldPlaceholder?: string;
|
|
9
|
+
selective?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function constructReplyKeyboardMarkup(keyboard_: types.ReplyKeyboardMarkup): ReplyKeyboardMarkup;
|
|
12
|
+
export declare function replyKeyboardMarkupToTlObject(replyMarkup: ReplyKeyboardMarkup): types.ReplyKeyboardMarkup;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { as } from "../tl/1_tl_object.js";
|
|
2
|
+
import * as types from "../tl/2_types.js";
|
|
3
|
+
import { constructKeyboardButton, keyboardButtonToTlObject } from "./1_keyboard_button.js";
|
|
4
|
+
export function constructReplyKeyboardMarkup(keyboard_) {
|
|
5
|
+
const rows = new Array();
|
|
6
|
+
for (const row_ of keyboard_.rows.map((v) => v[as](types.KeyboardButtonRow))) {
|
|
7
|
+
const row = new Array();
|
|
8
|
+
for (const button_ of row_.buttons) {
|
|
9
|
+
row.push(constructKeyboardButton(button_));
|
|
10
|
+
}
|
|
11
|
+
rows.push(row);
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
resizeKeyboard: keyboard_.resize || false,
|
|
15
|
+
oneTimeKeyboard: keyboard_.singleUse || false,
|
|
16
|
+
selective: keyboard_.selective || false,
|
|
17
|
+
isPersistent: keyboard_.persistent || false,
|
|
18
|
+
keyboard: rows,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function replyKeyboardMarkupToTlObject(replyMarkup) {
|
|
22
|
+
const rows_ = new Array();
|
|
23
|
+
for (const row of replyMarkup.keyboard) {
|
|
24
|
+
const row_ = new Array();
|
|
25
|
+
for (const button of row) {
|
|
26
|
+
row_.push(keyboardButtonToTlObject(button));
|
|
27
|
+
}
|
|
28
|
+
rows_.push(new types.KeyboardButtonRow({ buttons: row_ }));
|
|
29
|
+
}
|
|
30
|
+
return new types.ReplyKeyboardMarkup({
|
|
31
|
+
resize: replyMarkup.resizeKeyboard || undefined,
|
|
32
|
+
singleUse: replyMarkup.oneTimeKeyboard || undefined,
|
|
33
|
+
selective: replyMarkup.selective || undefined,
|
|
34
|
+
persistent: replyMarkup.isPersistent || undefined,
|
|
35
|
+
rows: rows_,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
import { ForceReply } from "./0_force_reply.js";
|
|
3
|
+
import { MessageEntity } from "./0_message_entity.js";
|
|
4
|
+
import { ReplyKeyboardRemove } from "./0_reply_keyboard_remove.js";
|
|
5
|
+
import { Chat } from "./1_chat.js";
|
|
6
|
+
import { User } from "./1_user.js";
|
|
7
|
+
import { InlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
|
|
8
|
+
import { ReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
|
|
9
|
+
export interface Message {
|
|
10
|
+
id: number;
|
|
11
|
+
from?: User;
|
|
12
|
+
chat: Chat;
|
|
13
|
+
text?: string;
|
|
14
|
+
caption?: string;
|
|
15
|
+
entities?: MessageEntity[];
|
|
16
|
+
captionEntities?: MessageEntity[];
|
|
17
|
+
date?: Date;
|
|
18
|
+
editDate?: Date;
|
|
19
|
+
views?: number;
|
|
20
|
+
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
21
|
+
}
|
|
22
|
+
export declare function constructMessage(message_: types.Message, users: types.TypeUser[], chats: types.TypeChat[]): Message;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
2
|
+
import { cleanObject } from "../utilities/0_object.js";
|
|
3
|
+
import * as types from "../tl/2_types.js";
|
|
4
|
+
import { constructForceReply } from "./0_force_reply.js";
|
|
5
|
+
import { constructMessageEntity } from "./0_message_entity.js";
|
|
6
|
+
import { constructReplyKeyboardRemove } from "./0_reply_keyboard_remove.js";
|
|
7
|
+
import { constructChat } from "./1_chat.js";
|
|
8
|
+
import { constructUser } from "./1_user.js";
|
|
9
|
+
import { constructInlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
|
|
10
|
+
import { constructReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
|
|
11
|
+
export function constructMessage(message_, users, chats) {
|
|
12
|
+
let chat_ = null;
|
|
13
|
+
if (message_.peerId instanceof types.PeerUser) {
|
|
14
|
+
for (const user of users) {
|
|
15
|
+
if (user instanceof types.User && user.id == message_.peerId.userId) {
|
|
16
|
+
chat_ = constructChat(user);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (message_.peerId instanceof types.PeerChat) {
|
|
22
|
+
for (const chat of chats) {
|
|
23
|
+
if (chat instanceof types.Chat && chat.id == message_.peerId.chatId) {
|
|
24
|
+
chat_ = constructChat(chat);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (message_.peerId instanceof types.PeerChannel) {
|
|
30
|
+
for (const chat of chats) {
|
|
31
|
+
if (chat instanceof types.Channel && chat.id == message_.peerId.channelId) {
|
|
32
|
+
chat_ = constructChat(chat);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!chat_) {
|
|
38
|
+
UNREACHABLE();
|
|
39
|
+
}
|
|
40
|
+
const message = { id: message_.id, chat: chat_, views: message_.views };
|
|
41
|
+
if (message_.fromId instanceof types.PeerUser) {
|
|
42
|
+
for (const user of users) {
|
|
43
|
+
if (user instanceof types.User && user.id == message_.fromId.userId) {
|
|
44
|
+
message.from = constructUser(user);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (message_.message) {
|
|
50
|
+
if (message_.media == undefined) {
|
|
51
|
+
message.text = message_.message;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
message.caption = message_.message;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (message_.entities != undefined) {
|
|
58
|
+
if (message_.media == undefined) {
|
|
59
|
+
message.entities = message_.entities.map(constructMessageEntity).filter((v) => v);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
message.captionEntities = message_.entities.map(constructMessageEntity).filter((v) => v);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
message.date = new Date(message_.date * 1000);
|
|
66
|
+
if (message_.editDate != undefined) {
|
|
67
|
+
message.editDate = new Date(message_.editDate * 1000);
|
|
68
|
+
}
|
|
69
|
+
if (message_.replyMarkup) {
|
|
70
|
+
if (message_.replyMarkup instanceof types.ReplyKeyboardMarkup) {
|
|
71
|
+
message.replyMarkup = constructReplyKeyboardMarkup(message_.replyMarkup);
|
|
72
|
+
}
|
|
73
|
+
else if (message_.replyMarkup instanceof types.ReplyInlineMarkup) {
|
|
74
|
+
message.replyMarkup = constructInlineKeyboardMarkup(message_.replyMarkup);
|
|
75
|
+
}
|
|
76
|
+
else if (message_.replyMarkup instanceof types.ReplyKeyboardHide) {
|
|
77
|
+
message.replyMarkup = constructReplyKeyboardRemove(message_.replyMarkup);
|
|
78
|
+
}
|
|
79
|
+
else if (message_.replyMarkup instanceof types.ReplyKeyboardForceReply) {
|
|
80
|
+
message.replyMarkup = constructForceReply(message_.replyMarkup);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
UNREACHABLE();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return cleanObject(message);
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function UNREACHABLE(): never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cleanObject<T extends Record<string, any>>(object: T): T;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// deno-lint-ignore no-explicit-any
|
|
2
|
+
export function cleanObject(object) {
|
|
3
|
+
for (const [k, v] of Object.entries(object)) {
|
|
4
|
+
switch (typeof v) {
|
|
5
|
+
case "undefined":
|
|
6
|
+
delete object[k];
|
|
7
|
+
break;
|
|
8
|
+
case "object":
|
|
9
|
+
// @ts-ignore: this works, no idea why it complains
|
|
10
|
+
object[k] = cleanObject(v);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return object;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { MaybePromise } from "../
|
|
1
|
+
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
2
|
import * as types from "../tl/2_types.js";
|
|
3
3
|
import * as functions from "../tl/3_functions.js";
|
|
4
4
|
import { ClientAbstract } from "./client_abstract.js";
|
|
5
5
|
import { Storage } from "../storage/storage.js";
|
|
6
6
|
import { DC, TransportProvider } from "../transport/transport_provider.js";
|
|
7
7
|
import { MessageEntity } from "../types/0_message_entity.js";
|
|
8
|
+
import { ReplyKeyboardRemove } from "../types/0_reply_keyboard_remove.js";
|
|
9
|
+
import { ForceReply } from "../types/0_force_reply.js";
|
|
10
|
+
import { ReplyKeyboardMarkup } from "../types/2_reply_keyboard_markup.js";
|
|
11
|
+
import { InlineKeyboardMarkup } from "../types/2_inline_keyboard_markup.js";
|
|
8
12
|
export declare const restartAuth: unique symbol;
|
|
9
13
|
export declare enum ParseMode {
|
|
10
14
|
None = "none",
|
|
@@ -136,5 +140,6 @@ export declare class Client extends ClientAbstract {
|
|
|
136
140
|
replyToMessageId?: number;
|
|
137
141
|
messageThreadId?: number;
|
|
138
142
|
sendAs?: number | string;
|
|
139
|
-
|
|
143
|
+
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
144
|
+
}): Promise<import("../types/3_message.js").Message>;
|
|
140
145
|
}
|
package/script/client/client.js
CHANGED
|
@@ -27,6 +27,8 @@ exports.Client = exports.ParseMode = exports.restartAuth = void 0;
|
|
|
27
27
|
const deps_js_1 = require("../deps.js");
|
|
28
28
|
const constants_js_1 = require("../constants.js");
|
|
29
29
|
const _0_bigint_js_1 = require("../utilities/0_bigint.js");
|
|
30
|
+
const _0_control_js_1 = require("../utilities/0_control.js");
|
|
31
|
+
const _0_hash_js_1 = require("../utilities/0_hash.js");
|
|
30
32
|
const _0_html_js_1 = require("../utilities/0_html.js");
|
|
31
33
|
const _1_message_js_1 = require("../utilities/1_message.js");
|
|
32
34
|
const _1_password_js_1 = require("../utilities/1_password.js");
|
|
@@ -40,8 +42,12 @@ const _6_message_container_js_1 = require("../tl/6_message_container.js");
|
|
|
40
42
|
const client_abstract_js_1 = require("./client_abstract.js");
|
|
41
43
|
const client_plain_js_1 = require("./client_plain.js");
|
|
42
44
|
const storage_memory_js_1 = require("../storage/storage_memory.js");
|
|
43
|
-
const _0_hash_js_1 = require("../utilities/0_hash.js");
|
|
44
45
|
const _0_message_entity_js_1 = require("../types/0_message_entity.js");
|
|
46
|
+
const _0_reply_keyboard_remove_js_1 = require("../types/0_reply_keyboard_remove.js");
|
|
47
|
+
const _0_force_reply_js_1 = require("../types/0_force_reply.js");
|
|
48
|
+
const _2_reply_keyboard_markup_js_1 = require("../types/2_reply_keyboard_markup.js");
|
|
49
|
+
const _2_inline_keyboard_markup_js_1 = require("../types/2_inline_keyboard_markup.js");
|
|
50
|
+
const _3_message_js_1 = require("../types/3_message.js");
|
|
45
51
|
const d = (0, deps_js_1.debug)("client");
|
|
46
52
|
exports.restartAuth = Symbol();
|
|
47
53
|
var ParseMode;
|
|
@@ -607,7 +613,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
607
613
|
channelId = resolved.peer.channelId;
|
|
608
614
|
}
|
|
609
615
|
else {
|
|
610
|
-
|
|
616
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
611
617
|
}
|
|
612
618
|
}
|
|
613
619
|
if (userId) {
|
|
@@ -619,7 +625,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
619
625
|
return new types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
|
|
620
626
|
}
|
|
621
627
|
else {
|
|
622
|
-
|
|
628
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
623
629
|
}
|
|
624
630
|
}
|
|
625
631
|
}
|
|
@@ -654,6 +660,27 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
654
660
|
}
|
|
655
661
|
}
|
|
656
662
|
}
|
|
663
|
+
let replyMarkup = undefined;
|
|
664
|
+
if (params?.replyMarkup) {
|
|
665
|
+
if ("inlineKeyboard" in params.replyMarkup) {
|
|
666
|
+
replyMarkup = await (0, _2_inline_keyboard_markup_js_1.inlineKeyboardMarkupToTlObject)(params.replyMarkup, async (v) => {
|
|
667
|
+
const inputPeer = await this.getInputPeer(v).then((v) => v[_1_tl_object_js_1.as](types.InputPeerUser));
|
|
668
|
+
return new types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
else if ("keyboard" in params.replyMarkup) {
|
|
672
|
+
replyMarkup = (0, _2_reply_keyboard_markup_js_1.replyKeyboardMarkupToTlObject)(params.replyMarkup);
|
|
673
|
+
}
|
|
674
|
+
else if ("removeKeyboard" in params.replyMarkup) {
|
|
675
|
+
replyMarkup = (0, _0_reply_keyboard_remove_js_1.replyKeyboardRemoveToTlObject)(params.replyMarkup);
|
|
676
|
+
}
|
|
677
|
+
else if ("forceReply" in params.replyMarkup) {
|
|
678
|
+
replyMarkup = (0, _0_force_reply_js_1.forceReplyToTlObject)(params.replyMarkup);
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
throw new Error("The replyMarkup parameter has an unexpected type");
|
|
682
|
+
}
|
|
683
|
+
}
|
|
657
684
|
const peer = await this.getInputPeer(chatId);
|
|
658
685
|
const randomId = (0, _0_bigint_js_1.getRandomId)();
|
|
659
686
|
const message = text;
|
|
@@ -664,7 +691,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
664
691
|
const topMsgId = params?.messageThreadId;
|
|
665
692
|
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined;
|
|
666
693
|
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _0_message_entity_js_1.messageEntityToTlObject)(v)) : undefined;
|
|
667
|
-
|
|
694
|
+
const updates = await this.invoke(new functions.MessagesSendMessage({
|
|
668
695
|
peer,
|
|
669
696
|
randomId,
|
|
670
697
|
message,
|
|
@@ -675,7 +702,17 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
675
702
|
topMsgId,
|
|
676
703
|
sendAs,
|
|
677
704
|
entities,
|
|
678
|
-
|
|
705
|
+
replyMarkup,
|
|
706
|
+
})).then((v) => v[_1_tl_object_js_1.as](types.Updates));
|
|
707
|
+
for (const update of updates.updates) {
|
|
708
|
+
if (update instanceof types.UpdateNewMessage) {
|
|
709
|
+
return (0, _3_message_js_1.constructMessage)(update.message[_1_tl_object_js_1.as](types.Message), updates.users, updates.chats);
|
|
710
|
+
}
|
|
711
|
+
else if (update instanceof types.UpdateNewChannelMessage) {
|
|
712
|
+
return (0, _3_message_js_1.constructMessage)(update.message[_1_tl_object_js_1.as](types.Message), updates.users, updates.chats);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
679
716
|
}
|
|
680
717
|
}
|
|
681
718
|
exports.Client = Client;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { MaybePromise } from "../utilities/0_types.js";
|
|
1
2
|
import { Connection } from "../connection/connection.js";
|
|
2
3
|
import { Transport } from "../transport/transport.js";
|
|
3
4
|
import { DC } from "../transport/transport_provider.js";
|
|
4
|
-
import { MaybePromise } from "../types.js";
|
|
5
5
|
export declare abstract class ClientAbstract {
|
|
6
6
|
protected transportProvider: import("../transport/transport_provider.js").TransportProvider;
|
|
7
7
|
protected connection: Connection;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
export interface ChatAdministratorRights {
|
|
3
|
+
isAnonymous: boolean;
|
|
4
|
+
canManageChat: boolean;
|
|
5
|
+
canDeleteMessages: boolean;
|
|
6
|
+
canManageVideoChats: boolean;
|
|
7
|
+
canRestrictMembers: boolean;
|
|
8
|
+
canPromoteMembers: boolean;
|
|
9
|
+
canChangeInfo: boolean;
|
|
10
|
+
canInviteUsers: boolean;
|
|
11
|
+
canPostMessages?: boolean;
|
|
12
|
+
canEditMessages?: boolean;
|
|
13
|
+
canPinMessages?: boolean;
|
|
14
|
+
canManageTopics?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function constructChatAdministratorRights(rights_: types.ChatAdminRights): ChatAdministratorRights;
|
|
17
|
+
export declare function chatAdministratorRightsToTlObject(rights: ChatAdministratorRights): types.ChatAdminRights;
|