@mtkruto/node 0.0.832 → 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 +66 -13
- package/esm/client/client_abstract.d.ts +2 -2
- package/esm/client/client_abstract.js +3 -8
- package/esm/client/client_plain.js +8 -7
- package/esm/connection/connection.d.ts +2 -1
- package/esm/connection/connection_web_socket.d.ts +1 -0
- package/esm/connection/connection_web_socket.js +3 -0
- package/esm/deps/deno.land/std@0.69.0/fmt/colors.d.ts +77 -0
- package/esm/deps/deno.land/std@0.69.0/fmt/colors.js +224 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.d.ts +3 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.js +71 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.d.ts +22 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.js +112 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.d.ts +2 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.js +2 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/format.d.ts +1 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/format.js +39 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.d.ts +1 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js +1 -0
- package/esm/deps.d.ts +2 -0
- package/esm/deps.js +2 -0
- 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 +8 -6
- package/script/client/client.d.ts +7 -2
- package/script/client/client.js +65 -12
- package/script/client/client_abstract.d.ts +2 -2
- package/script/client/client_abstract.js +3 -8
- package/script/client/client_plain.js +7 -6
- package/script/connection/connection.d.ts +2 -1
- package/script/connection/connection_web_socket.d.ts +1 -0
- package/script/connection/connection_web_socket.js +3 -0
- package/script/deps/deno.land/std@0.69.0/fmt/colors.d.ts +77 -0
- package/script/deps/deno.land/std@0.69.0/fmt/colors.js +298 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.d.ts +3 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.js +98 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.d.ts +22 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.js +141 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.d.ts +2 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.js +32 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/format.d.ts +1 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/format.js +43 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.d.ts +1 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js +17 -0
- package/script/deps.d.ts +2 -0
- package/script/deps.js +4 -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -84,7 +84,7 @@ export declare namespace MessageEntity {
|
|
|
84
84
|
}
|
|
85
85
|
interface CustomEmoji extends Base {
|
|
86
86
|
type: MessageEntityType.CustomEmoji;
|
|
87
|
-
|
|
87
|
+
customEmojiId: string;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
export type MessageEntity = MessageEntity.Mention | MessageEntity.Hashtag | MessageEntity.BotCommand | MessageEntity.URL | MessageEntity.EmailAddress | MessageEntity.Bold | MessageEntity.Italic | MessageEntity.Code | MessageEntity.Pre | MessageEntity.TextURL | MessageEntity.MentionName | MessageEntity.Cashtag | MessageEntity.Phone | MessageEntity.Underline | MessageEntity.Strike | MessageEntity.Blockquote | MessageEntity.BankCard | MessageEntity.Spoiler | MessageEntity.CustomEmoji;
|
|
@@ -77,7 +77,7 @@ export function constructMessageEntity(obj) {
|
|
|
77
77
|
return { type: MessageEntityType.Spoiler, offset: obj.offset, length: obj.length };
|
|
78
78
|
}
|
|
79
79
|
else if (obj instanceof types.MessageEntityCustomEmoji) {
|
|
80
|
-
return { type: MessageEntityType.CustomEmoji, offset: obj.offset, length: obj.length,
|
|
80
|
+
return { type: MessageEntityType.CustomEmoji, offset: obj.offset, length: obj.length, customEmojiId: String(obj.documentId) };
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
83
|
return null;
|
|
@@ -123,6 +123,6 @@ export function messageEntityToTlObject(entity) {
|
|
|
123
123
|
case MessageEntityType.Spoiler:
|
|
124
124
|
return new types.MessageEntitySpoiler({ offset, length });
|
|
125
125
|
case MessageEntityType.CustomEmoji:
|
|
126
|
-
return new types.MessageEntityCustomEmoji({ offset, length, documentId: entity.
|
|
126
|
+
return new types.MessageEntityCustomEmoji({ offset, length, documentId: BigInt(entity.customEmojiId) });
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
export interface ReplyKeyboardRemove {
|
|
3
|
+
removeKeyboard: true;
|
|
4
|
+
selective?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function constructReplyKeyboardRemove(replyMarkup_: types.ReplyKeyboardHide): ReplyKeyboardRemove;
|
|
7
|
+
export declare function replyKeyboardRemoveToTlObject(replyMarkup: ReplyKeyboardRemove): types.ReplyKeyboardHide;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { cleanObject } from "../utilities/0_object.js";
|
|
2
|
+
import * as types from "../tl/2_types.js";
|
|
3
|
+
export function constructReplyKeyboardRemove(replyMarkup_) {
|
|
4
|
+
return cleanObject({ removeKeyboard: true, selective: replyMarkup_.selective });
|
|
5
|
+
}
|
|
6
|
+
export function replyKeyboardRemoveToTlObject(replyMarkup) {
|
|
7
|
+
return new types.ReplyKeyboardHide({ selective: replyMarkup.selective || undefined });
|
|
8
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
import { ChatPhoto } from "./0_chat_photo.js";
|
|
3
|
+
export declare enum ChatType {
|
|
4
|
+
Private = "private",
|
|
5
|
+
Group = "group",
|
|
6
|
+
Supergroup = "supergroup",
|
|
7
|
+
Channel = "channel"
|
|
8
|
+
}
|
|
9
|
+
export declare namespace Chat {
|
|
10
|
+
interface Base {
|
|
11
|
+
type: ChatType;
|
|
12
|
+
id: number;
|
|
13
|
+
photo?: ChatPhoto;
|
|
14
|
+
}
|
|
15
|
+
interface Private extends Base {
|
|
16
|
+
type: ChatType.Private;
|
|
17
|
+
isBot?: boolean;
|
|
18
|
+
firstName: string;
|
|
19
|
+
lastName?: string;
|
|
20
|
+
username?: string;
|
|
21
|
+
also?: string[];
|
|
22
|
+
photo?: ChatPhoto.User;
|
|
23
|
+
isScam: boolean;
|
|
24
|
+
isFake: boolean;
|
|
25
|
+
isSupport: boolean;
|
|
26
|
+
isVerified: boolean;
|
|
27
|
+
isRestricted?: boolean;
|
|
28
|
+
restrictionReason?: types.RestrictionReason[];
|
|
29
|
+
}
|
|
30
|
+
interface Group extends Base {
|
|
31
|
+
type: ChatType.Group;
|
|
32
|
+
title: string;
|
|
33
|
+
photo?: ChatPhoto.Chat;
|
|
34
|
+
isCreator: boolean;
|
|
35
|
+
}
|
|
36
|
+
interface ChannelBase extends Base {
|
|
37
|
+
title: string;
|
|
38
|
+
username?: string;
|
|
39
|
+
also?: string[];
|
|
40
|
+
photo?: ChatPhoto.Chat;
|
|
41
|
+
isScam: boolean;
|
|
42
|
+
isFake: boolean;
|
|
43
|
+
isVerified: boolean;
|
|
44
|
+
isRestricted: boolean;
|
|
45
|
+
restrictionReason?: types.RestrictionReason[];
|
|
46
|
+
}
|
|
47
|
+
interface Channel extends ChannelBase {
|
|
48
|
+
type: ChatType.Channel;
|
|
49
|
+
title: string;
|
|
50
|
+
username?: string;
|
|
51
|
+
also?: string[];
|
|
52
|
+
}
|
|
53
|
+
interface Supergroup extends ChannelBase {
|
|
54
|
+
type: ChatType.Supergroup;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export type Chat = Chat.Private | Chat.Group | Chat.Supergroup | Chat.Channel;
|
|
58
|
+
export declare function constructChat(chat: types.User): Chat.Private;
|
|
59
|
+
export declare function constructChat(chat: types.Chat): Chat.Group;
|
|
60
|
+
export declare function constructChat(chat: types.Channel): Chat.Supergroup | Chat.Channel;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ZERO_CHANNEL_ID } from "../constants.js";
|
|
2
|
+
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
3
|
+
import { cleanObject } from "../utilities/0_object.js";
|
|
4
|
+
import { as } from "../tl/1_tl_object.js";
|
|
5
|
+
import * as types from "../tl/2_types.js";
|
|
6
|
+
import { constructChatPhoto } from "./0_chat_photo.js";
|
|
7
|
+
export var ChatType;
|
|
8
|
+
(function (ChatType) {
|
|
9
|
+
ChatType["Private"] = "private";
|
|
10
|
+
ChatType["Group"] = "group";
|
|
11
|
+
ChatType["Supergroup"] = "supergroup";
|
|
12
|
+
ChatType["Channel"] = "channel";
|
|
13
|
+
})(ChatType || (ChatType = {}));
|
|
14
|
+
export function constructChat(chat) {
|
|
15
|
+
if (chat instanceof types.User) {
|
|
16
|
+
const chat_ = {
|
|
17
|
+
type: ChatType.Private,
|
|
18
|
+
isBot: chat.bot || false,
|
|
19
|
+
id: Number(chat.id),
|
|
20
|
+
firstName: chat.firstName || "",
|
|
21
|
+
lastName: chat.lastName,
|
|
22
|
+
isScam: chat.scam || false,
|
|
23
|
+
isFake: chat.fake || false,
|
|
24
|
+
isSupport: chat.support || false,
|
|
25
|
+
isVerified: chat.verified || false,
|
|
26
|
+
};
|
|
27
|
+
if (chat_.isBot) {
|
|
28
|
+
chat_.isRestricted = chat.restricted || false;
|
|
29
|
+
chat_.restrictionReason = chat.restrictionReason?.map((v) => v[as](types.RestrictionReason));
|
|
30
|
+
}
|
|
31
|
+
if (chat.photo instanceof types.UserProfilePhoto) {
|
|
32
|
+
chat_.photo = constructChatPhoto(chat.photo);
|
|
33
|
+
}
|
|
34
|
+
return cleanObject(chat_);
|
|
35
|
+
}
|
|
36
|
+
else if (chat instanceof types.Chat) {
|
|
37
|
+
const chat_ = {
|
|
38
|
+
type: ChatType.Group,
|
|
39
|
+
id: Number(-chat.id),
|
|
40
|
+
title: chat.title,
|
|
41
|
+
isCreator: chat.creator || false,
|
|
42
|
+
};
|
|
43
|
+
if (chat.photo instanceof types.ChatPhoto) {
|
|
44
|
+
chat_.photo = constructChatPhoto(chat.photo);
|
|
45
|
+
}
|
|
46
|
+
return cleanObject(chat_);
|
|
47
|
+
}
|
|
48
|
+
else if (chat instanceof types.Channel) {
|
|
49
|
+
let chat_;
|
|
50
|
+
const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
|
|
51
|
+
if (chat.megagroup) {
|
|
52
|
+
chat_ = { id: ZERO_CHANNEL_ID + -Number(chat.id), type: ChatType.Supergroup, title, isScam, isFake, isVerified, isRestricted };
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
chat_ = { id: ZERO_CHANNEL_ID + -Number(chat.id), type: ChatType.Channel, title, isScam, isFake, isVerified, isRestricted };
|
|
56
|
+
}
|
|
57
|
+
chat_.username = chat.username;
|
|
58
|
+
chat_.also = chat.usernames?.map((v) => v[as](types.Username)).map((v) => v.username);
|
|
59
|
+
if (chat_.isRestricted) {
|
|
60
|
+
chat_.restrictionReason = chat.restrictionReason?.map((v) => v[as](types.RestrictionReason));
|
|
61
|
+
}
|
|
62
|
+
if (chat.photo instanceof types.ChatPhoto) {
|
|
63
|
+
chat_.photo = constructChatPhoto(chat.photo);
|
|
64
|
+
}
|
|
65
|
+
return cleanObject(chat_);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
UNREACHABLE();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
|
+
import * as types from "../tl/2_types.js";
|
|
3
|
+
import { WebAppInfo } from "./0_web_app_info.js";
|
|
4
|
+
import { LoginUrl } from "./0_login_url.js";
|
|
5
|
+
export declare namespace InlineKeyboardButton {
|
|
6
|
+
interface Base {
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
interface URL extends Base {
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
interface Callback extends Base {
|
|
13
|
+
callbackData: string;
|
|
14
|
+
}
|
|
15
|
+
interface WebApp extends Base {
|
|
16
|
+
webApp: WebAppInfo;
|
|
17
|
+
}
|
|
18
|
+
interface Login extends Base {
|
|
19
|
+
loginUrl: LoginUrl;
|
|
20
|
+
}
|
|
21
|
+
interface SwitchInline extends Base {
|
|
22
|
+
switchInlineQuery: string;
|
|
23
|
+
}
|
|
24
|
+
interface SwitchInlineCurrent extends Base {
|
|
25
|
+
switchInlineQueryCurrentChat: string;
|
|
26
|
+
}
|
|
27
|
+
interface Pay extends Base {
|
|
28
|
+
pay: boolean;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export type InlineKeyboardButton = InlineKeyboardButton.URL | InlineKeyboardButton.Callback | InlineKeyboardButton.WebApp | InlineKeyboardButton.Login | InlineKeyboardButton.SwitchInline | InlineKeyboardButton.SwitchInlineCurrent | InlineKeyboardButton.Pay;
|
|
32
|
+
export declare function constructInlineKeyboardButton(button_: types.TypeKeyboardButton): InlineKeyboardButton;
|
|
33
|
+
export declare function inlineKeyboardButtonToTlObject(button: InlineKeyboardButton, usernameResolver: (username: string) => MaybePromise<types.InputUser>): Promise<types.KeyboardButtonURL | types.KeyboardButtonCallback | types.KeyboardButtonSwitchInline | types.KeyboardButtonBuy | types.InputKeyboardButtonURLAuth | types.KeyboardButtonWebView>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
2
|
+
import * as types from "../tl/2_types.js";
|
|
3
|
+
import { constructWebAppInfo } from "./0_web_app_info.js";
|
|
4
|
+
export function constructInlineKeyboardButton(button_) {
|
|
5
|
+
if (button_ instanceof types.KeyboardButtonURL) {
|
|
6
|
+
return { text: button_.text, url: button_.url };
|
|
7
|
+
}
|
|
8
|
+
else if (button_ instanceof types.KeyboardButtonCallback) {
|
|
9
|
+
return { text: button_.text, callbackData: new TextDecoder().decode(button_.data) };
|
|
10
|
+
}
|
|
11
|
+
else if (button_ instanceof types.KeyboardButtonWebView || button_ instanceof types.KeyboardButtonSimpleWebView) {
|
|
12
|
+
return { text: button_.text, webApp: constructWebAppInfo(button_.url) };
|
|
13
|
+
}
|
|
14
|
+
else if (button_ instanceof types.KeyboardButtonURLAuth) {
|
|
15
|
+
return { text: button_.text, loginUrl: { url: button_.url, forwardText: button_.fwdText } };
|
|
16
|
+
}
|
|
17
|
+
else if (button_ instanceof types.KeyboardButtonSwitchInline) {
|
|
18
|
+
if (button_.samePeer) {
|
|
19
|
+
return { text: button_.text, switchInlineQueryCurrentChat: button_.query };
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return { text: button_.text, switchInlineQuery: button_.query };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (button_ instanceof types.KeyboardButtonBuy) {
|
|
26
|
+
return { text: button_.text, pay: true };
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
UNREACHABLE();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export async function inlineKeyboardButtonToTlObject(button, usernameResolver) {
|
|
33
|
+
if ("url" in button) {
|
|
34
|
+
return new types.KeyboardButtonURL({ text: button.text, url: button.url });
|
|
35
|
+
}
|
|
36
|
+
else if ("callbackData" in button) {
|
|
37
|
+
return new types.KeyboardButtonCallback({ text: button.text, data: new TextEncoder().encode(button.callbackData) });
|
|
38
|
+
}
|
|
39
|
+
else if ("webApp" in button) {
|
|
40
|
+
return new types.KeyboardButtonWebView({ text: button.text, url: button.webApp.url });
|
|
41
|
+
}
|
|
42
|
+
else if ("loginUrl" in button) {
|
|
43
|
+
return new types.InputKeyboardButtonURLAuth({
|
|
44
|
+
text: button.text,
|
|
45
|
+
url: button.loginUrl.url,
|
|
46
|
+
fwdText: button.loginUrl.forwardText,
|
|
47
|
+
bot: button.loginUrl.botUsername ? await usernameResolver(button.loginUrl.botUsername) : new types.InputUserSelf(),
|
|
48
|
+
requestWriteAccess: button.loginUrl.requestWriteAccess || undefined,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else if ("switchInlineQuery" in button) {
|
|
52
|
+
return new types.KeyboardButtonSwitchInline({ text: button.text, query: button.switchInlineQuery });
|
|
53
|
+
}
|
|
54
|
+
else if ("switchInlineQueryCurrentChat" in button) {
|
|
55
|
+
return new types.KeyboardButtonSwitchInline({ text: button.text, query: button.switchInlineQueryCurrentChat, samePeer: true });
|
|
56
|
+
}
|
|
57
|
+
else if ("pay" in button) {
|
|
58
|
+
return new types.KeyboardButtonBuy({ text: button.text });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
UNREACHABLE();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as types from "../tl/2_types.js";
|
|
2
|
+
import { ChatAdministratorRights } from "./0_chat_administrator_rights.js";
|
|
3
|
+
import { KeyboardButtonPollType } from "./0_keyboard_button_poll_type.js";
|
|
4
|
+
import { WebAppInfo } from "./0_web_app_info.js";
|
|
5
|
+
export declare namespace KeyboardButton {
|
|
6
|
+
interface Text {
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
interface RequestUser extends Text {
|
|
10
|
+
requestUser: {
|
|
11
|
+
requestId: number;
|
|
12
|
+
userIsBot?: boolean;
|
|
13
|
+
userIsPremium?: boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface RequestChat extends Text {
|
|
17
|
+
requestChat: {
|
|
18
|
+
requestId: number;
|
|
19
|
+
chatIsChannel: boolean;
|
|
20
|
+
chatIsForum?: boolean;
|
|
21
|
+
chatHasUsername?: boolean;
|
|
22
|
+
chatIsCreated?: boolean;
|
|
23
|
+
userAdministratorRights?: ChatAdministratorRights;
|
|
24
|
+
botAdministratorRights?: ChatAdministratorRights;
|
|
25
|
+
botIsMember?: boolean;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface RequestContact extends Text {
|
|
29
|
+
requestContact: true;
|
|
30
|
+
}
|
|
31
|
+
interface RequestLocation extends Text {
|
|
32
|
+
requestLocation: true;
|
|
33
|
+
}
|
|
34
|
+
interface RequestPoll extends Text {
|
|
35
|
+
requestPoll: KeyboardButtonPollType;
|
|
36
|
+
}
|
|
37
|
+
interface WebApp extends Text {
|
|
38
|
+
webApp: WebAppInfo;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export type KeyboardButton = KeyboardButton.Text | KeyboardButton.RequestUser | KeyboardButton.RequestChat | KeyboardButton.RequestContact | KeyboardButton.RequestLocation | KeyboardButton.RequestPoll | KeyboardButton.WebApp;
|
|
42
|
+
export declare function constructKeyboardButton(button_: types.TypeKeyboardButton): KeyboardButton;
|
|
43
|
+
export declare function keyboardButtonToTlObject(button: KeyboardButton): types.KeyboardButtonRequestPhone | types.KeyboardButtonRequestGeoLocation | types.KeyboardButtonRequestPoll | types.KeyboardButtonWebView | types.KeyboardButtonRequestPeer;
|
|
@@ -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;
|