@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.
Files changed (91) hide show
  1. package/esm/client/client.d.ts +7 -2
  2. package/esm/client/client.js +42 -5
  3. package/esm/client/client_abstract.d.ts +1 -1
  4. package/esm/connection/connection.d.ts +1 -1
  5. package/esm/storage/storage.d.ts +1 -1
  6. package/esm/storage/storage_local_storage.d.ts +1 -1
  7. package/esm/storage/storage_memory.d.ts +1 -1
  8. package/esm/storage/storage_session_storage.d.ts +1 -1
  9. package/esm/transport/transport.d.ts +1 -1
  10. package/esm/types/0_chat_administrator_rights.d.ts +17 -0
  11. package/esm/types/0_chat_administrator_rights.js +38 -0
  12. package/esm/types/0_chat_photo.d.ts +24 -0
  13. package/esm/types/0_chat_photo.js +28 -0
  14. package/esm/types/0_force_reply.d.ts +8 -0
  15. package/esm/types/0_force_reply.js +17 -0
  16. package/esm/types/0_keyboard_button_poll_type.d.ts +3 -0
  17. package/esm/types/0_login_url.d.ts +6 -0
  18. package/esm/types/0_login_url.js +1 -0
  19. package/esm/types/0_message_entity.d.ts +1 -1
  20. package/esm/types/0_message_entity.js +2 -2
  21. package/esm/types/0_reply_keyboard_remove.d.ts +7 -0
  22. package/esm/types/0_reply_keyboard_remove.js +8 -0
  23. package/esm/types/0_web_app_info.d.ts +4 -0
  24. package/esm/types/0_web_app_info.js +3 -0
  25. package/esm/types/1_chat.d.ts +60 -0
  26. package/esm/types/1_chat.js +70 -0
  27. package/esm/types/1_inline_keyboard_button.d.ts +33 -0
  28. package/esm/types/1_inline_keyboard_button.js +63 -0
  29. package/esm/types/1_keyboard_button.d.ts +43 -0
  30. package/esm/types/1_keyboard_button.js +133 -0
  31. package/esm/types/1_user.d.ts +19 -0
  32. package/esm/types/1_user.js +25 -0
  33. package/esm/types/2_inline_keyboard_markup.d.ts +7 -0
  34. package/esm/types/2_inline_keyboard_markup.js +25 -0
  35. package/esm/types/2_reply_keyboard_markup.d.ts +12 -0
  36. package/esm/types/2_reply_keyboard_markup.js +37 -0
  37. package/esm/types/3_message.d.ts +22 -0
  38. package/esm/types/3_message.js +87 -0
  39. package/esm/utilities/0_control.d.ts +1 -0
  40. package/esm/utilities/0_control.js +3 -0
  41. package/esm/utilities/0_object.d.ts +1 -0
  42. package/esm/utilities/0_object.js +14 -0
  43. package/esm/utilities/0_types.js +1 -0
  44. package/package.json +1 -1
  45. package/script/client/client.d.ts +7 -2
  46. package/script/client/client.js +42 -5
  47. package/script/client/client_abstract.d.ts +1 -1
  48. package/script/connection/connection.d.ts +1 -1
  49. package/script/storage/storage.d.ts +1 -1
  50. package/script/storage/storage_local_storage.d.ts +1 -1
  51. package/script/storage/storage_memory.d.ts +1 -1
  52. package/script/storage/storage_session_storage.d.ts +1 -1
  53. package/script/transport/transport.d.ts +1 -1
  54. package/script/types/0_chat_administrator_rights.d.ts +17 -0
  55. package/script/types/0_chat_administrator_rights.js +66 -0
  56. package/script/types/0_chat_photo.d.ts +24 -0
  57. package/script/types/0_chat_photo.js +55 -0
  58. package/script/types/0_force_reply.d.ts +8 -0
  59. package/script/types/0_force_reply.js +45 -0
  60. package/script/types/0_keyboard_button_poll_type.d.ts +3 -0
  61. package/script/types/0_login_url.d.ts +6 -0
  62. package/script/types/0_login_url.js +2 -0
  63. package/script/types/0_message_entity.d.ts +1 -1
  64. package/script/types/0_message_entity.js +2 -2
  65. package/script/types/0_reply_keyboard_remove.d.ts +7 -0
  66. package/script/types/0_reply_keyboard_remove.js +36 -0
  67. package/script/types/0_web_app_info.d.ts +4 -0
  68. package/script/types/0_web_app_info.js +7 -0
  69. package/script/types/1_chat.d.ts +60 -0
  70. package/script/types/1_chat.js +97 -0
  71. package/script/types/1_inline_keyboard_button.d.ts +33 -0
  72. package/script/types/1_inline_keyboard_button.js +91 -0
  73. package/script/types/1_keyboard_button.d.ts +43 -0
  74. package/script/types/1_keyboard_button.js +161 -0
  75. package/script/types/1_user.d.ts +19 -0
  76. package/script/types/1_user.js +52 -0
  77. package/script/types/2_inline_keyboard_markup.d.ts +7 -0
  78. package/script/types/2_inline_keyboard_markup.js +53 -0
  79. package/script/types/2_reply_keyboard_markup.d.ts +12 -0
  80. package/script/types/2_reply_keyboard_markup.js +65 -0
  81. package/script/types/3_message.d.ts +22 -0
  82. package/script/types/3_message.js +114 -0
  83. package/script/utilities/0_control.d.ts +1 -0
  84. package/script/utilities/0_control.js +7 -0
  85. package/script/utilities/0_object.d.ts +1 -0
  86. package/script/utilities/0_object.js +18 -0
  87. package/script/utilities/0_types.js +2 -0
  88. /package/esm/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
  89. /package/esm/{types.d.ts → utilities/0_types.d.ts} +0 -0
  90. /package/script/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
  91. /package/script/{types.d.ts → utilities/0_types.d.ts} +0 -0
@@ -1,10 +1,14 @@
1
- import { MaybePromise } from "../types.js";
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
- }): Promise<types.TypeUpdates>;
143
+ replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
144
+ }): Promise<import("../types/3_message.js").Message>;
140
145
  }
@@ -1,6 +1,8 @@
1
1
  import { debug, gunzip } from "../deps.js";
2
2
  import { ackThreshold, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_INITIAL_DC, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, USERNAME_TTL, ZERO_CHANNEL_ID } from "../constants.js";
3
3
  import { bigIntFromBuffer, getRandomBigInt, getRandomId } from "../utilities/0_bigint.js";
4
+ import { UNREACHABLE } from "../utilities/0_control.js";
5
+ import { sha1 } from "../utilities/0_hash.js";
4
6
  import { parseHtml } from "../utilities/0_html.js";
5
7
  import { decryptMessage, encryptMessage, getMessageId } from "../utilities/1_message.js";
6
8
  import { checkPassword } from "../utilities/1_password.js";
@@ -14,8 +16,12 @@ import { MessageContainer } from "../tl/6_message_container.js";
14
16
  import { ClientAbstract } from "./client_abstract.js";
15
17
  import { ClientPlain } from "./client_plain.js";
16
18
  import { StorageMemory } from "../storage/storage_memory.js";
17
- import { sha1 } from "../utilities/0_hash.js";
18
19
  import { messageEntityToTlObject } from "../types/0_message_entity.js";
20
+ import { replyKeyboardRemoveToTlObject } from "../types/0_reply_keyboard_remove.js";
21
+ import { forceReplyToTlObject } from "../types/0_force_reply.js";
22
+ import { replyKeyboardMarkupToTlObject } from "../types/2_reply_keyboard_markup.js";
23
+ import { inlineKeyboardMarkupToTlObject } from "../types/2_inline_keyboard_markup.js";
24
+ import { constructMessage } from "../types/3_message.js";
19
25
  const d = debug("client");
20
26
  export const restartAuth = Symbol();
21
27
  export var ParseMode;
@@ -581,7 +587,7 @@ export class Client extends ClientAbstract {
581
587
  channelId = resolved.peer.channelId;
582
588
  }
583
589
  else {
584
- throw new Error("Unreachable");
590
+ UNREACHABLE();
585
591
  }
586
592
  }
587
593
  if (userId) {
@@ -593,7 +599,7 @@ export class Client extends ClientAbstract {
593
599
  return new types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
594
600
  }
595
601
  else {
596
- throw new Error("Unreachable");
602
+ UNREACHABLE();
597
603
  }
598
604
  }
599
605
  }
@@ -628,6 +634,27 @@ export class Client extends ClientAbstract {
628
634
  }
629
635
  }
630
636
  }
637
+ let replyMarkup = undefined;
638
+ if (params?.replyMarkup) {
639
+ if ("inlineKeyboard" in params.replyMarkup) {
640
+ replyMarkup = await inlineKeyboardMarkupToTlObject(params.replyMarkup, async (v) => {
641
+ const inputPeer = await this.getInputPeer(v).then((v) => v[as](types.InputPeerUser));
642
+ return new types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
643
+ });
644
+ }
645
+ else if ("keyboard" in params.replyMarkup) {
646
+ replyMarkup = replyKeyboardMarkupToTlObject(params.replyMarkup);
647
+ }
648
+ else if ("removeKeyboard" in params.replyMarkup) {
649
+ replyMarkup = replyKeyboardRemoveToTlObject(params.replyMarkup);
650
+ }
651
+ else if ("forceReply" in params.replyMarkup) {
652
+ replyMarkup = forceReplyToTlObject(params.replyMarkup);
653
+ }
654
+ else {
655
+ throw new Error("The replyMarkup parameter has an unexpected type");
656
+ }
657
+ }
631
658
  const peer = await this.getInputPeer(chatId);
632
659
  const randomId = getRandomId();
633
660
  const message = text;
@@ -638,7 +665,7 @@ export class Client extends ClientAbstract {
638
665
  const topMsgId = params?.messageThreadId;
639
666
  const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined;
640
667
  const entities = entities_?.length > 0 ? entities_.map((v) => messageEntityToTlObject(v)) : undefined;
641
- return await this.invoke(new functions.MessagesSendMessage({
668
+ const updates = await this.invoke(new functions.MessagesSendMessage({
642
669
  peer,
643
670
  randomId,
644
671
  message,
@@ -649,6 +676,16 @@ export class Client extends ClientAbstract {
649
676
  topMsgId,
650
677
  sendAs,
651
678
  entities,
652
- }));
679
+ replyMarkup,
680
+ })).then((v) => v[as](types.Updates));
681
+ for (const update of updates.updates) {
682
+ if (update instanceof types.UpdateNewMessage) {
683
+ return constructMessage(update.message[as](types.Message), updates.users, updates.chats);
684
+ }
685
+ else if (update instanceof types.UpdateNewChannelMessage) {
686
+ return constructMessage(update.message[as](types.Message), updates.users, updates.chats);
687
+ }
688
+ }
689
+ UNREACHABLE();
653
690
  }
654
691
  }
@@ -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;
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_types.js";
2
2
  export declare abstract class Connection {
3
3
  abstract get connected(): boolean;
4
4
  abstract open(): MaybePromise<void>;
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_types.js";
2
2
  import { DC } from "../transport/transport_provider.js";
3
3
  export declare abstract class Storage {
4
4
  private _authKeyId;
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_types.js";
2
2
  import { Storage } from "./storage.js";
3
3
  export declare class StorageLocalStorage extends Storage implements Storage {
4
4
  private readonly prefix;
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_types.js";
2
2
  import { Storage } from "./storage.js";
3
3
  export declare class StorageMemory extends Storage implements Storage {
4
4
  protected map: Map<string, string>;
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_types.js";
2
2
  import { Storage } from "./storage.js";
3
3
  export declare class StorageSessionStorage extends Storage implements Storage {
4
4
  private readonly prefix;
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_types.js";
2
2
  import { CTR } from "../utilities/0_crypto.js";
3
3
  export declare abstract class Transport {
4
4
  protected initialized: boolean;
@@ -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;
@@ -0,0 +1,38 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export function constructChatAdministratorRights(rights_) {
3
+ const rights = {
4
+ isAnonymous: rights_.anonymous || false,
5
+ canManageChat: rights_.other || false,
6
+ canDeleteMessages: rights_.deleteMessages || false,
7
+ canManageVideoChats: rights_.manageCall || false,
8
+ canRestrictMembers: rights_.banUsers || false,
9
+ canPromoteMembers: rights_.addAdmins || false,
10
+ canChangeInfo: rights_.changeInfo || false,
11
+ canInviteUsers: rights_.inviteUsers || false,
12
+ };
13
+ if (rights_.postMessages) {
14
+ rights.canPostMessages = rights_.postMessages;
15
+ }
16
+ if (rights_.editMessages) {
17
+ rights.canEditMessages = rights_.editMessages;
18
+ }
19
+ if (rights_.pinMessages) {
20
+ rights.canPinMessages = rights_.pinMessages;
21
+ }
22
+ if (rights_.manageTopics) {
23
+ rights.canManageTopics = rights_.manageTopics;
24
+ }
25
+ return rights;
26
+ }
27
+ export function chatAdministratorRightsToTlObject(rights) {
28
+ return new types.ChatAdminRights({
29
+ anonymous: rights.isAnonymous || undefined,
30
+ other: rights.canManageChat || undefined,
31
+ deleteMessages: rights.canDeleteMessages || undefined,
32
+ manageCall: rights.canManageChat || undefined,
33
+ banUsers: rights.canRestrictMembers || undefined,
34
+ addAdmins: rights.canPromoteMembers || undefined,
35
+ changeInfo: rights.canChangeInfo || undefined,
36
+ inviteUsers: rights.canInviteUsers || undefined,
37
+ });
38
+ }
@@ -0,0 +1,24 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export declare enum ChatPhotoType {
3
+ Chat = "chat",
4
+ User = "user"
5
+ }
6
+ export declare namespace ChatPhoto {
7
+ interface Base {
8
+ type: ChatPhotoType;
9
+ hasVideo: boolean;
10
+ photoId: bigint;
11
+ strippedThumb?: Uint8Array;
12
+ dcId: number;
13
+ }
14
+ interface User extends Base {
15
+ type: ChatPhotoType;
16
+ personal: boolean;
17
+ }
18
+ interface Chat extends Base {
19
+ type: ChatPhotoType;
20
+ }
21
+ }
22
+ export type ChatPhoto = ChatPhoto.User | ChatPhoto.Chat;
23
+ export declare function constructChatPhoto(photo: types.ChatPhoto): ChatPhoto.Chat;
24
+ export declare function constructChatPhoto(photo: types.UserProfilePhoto): ChatPhoto.User;
@@ -0,0 +1,28 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export var ChatPhotoType;
3
+ (function (ChatPhotoType) {
4
+ ChatPhotoType["Chat"] = "chat";
5
+ ChatPhotoType["User"] = "user";
6
+ })(ChatPhotoType || (ChatPhotoType = {}));
7
+ export function constructChatPhoto(photo) {
8
+ const { hasVideo = false, photoId, strippedThumb, dcId } = photo;
9
+ if (photo instanceof types.ChatPhoto) {
10
+ return {
11
+ type: ChatPhotoType.Chat,
12
+ hasVideo,
13
+ photoId,
14
+ strippedThumb,
15
+ dcId,
16
+ };
17
+ }
18
+ else {
19
+ return {
20
+ type: ChatPhotoType.User,
21
+ personal: photo.personal || false,
22
+ hasVideo,
23
+ photoId,
24
+ strippedThumb,
25
+ dcId,
26
+ };
27
+ }
28
+ }
@@ -0,0 +1,8 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export interface ForceReply {
3
+ forceReply: true;
4
+ inputFieldPlaceholder?: string;
5
+ selective?: boolean;
6
+ }
7
+ export declare function constructForceReply(replyMarkup_: types.ReplyKeyboardForceReply): ForceReply;
8
+ export declare function forceReplyToTlObject(replyMarkup: ForceReply): types.ReplyKeyboardForceReply;
@@ -0,0 +1,17 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export function constructForceReply(replyMarkup_) {
3
+ const replyMarkup = { forceReply: true };
4
+ if (replyMarkup_.placeholder) {
5
+ replyMarkup.inputFieldPlaceholder = replyMarkup_.placeholder;
6
+ }
7
+ if (replyMarkup_.selective) {
8
+ replyMarkup.selective = true;
9
+ }
10
+ return replyMarkup;
11
+ }
12
+ export function forceReplyToTlObject(replyMarkup) {
13
+ return new types.ReplyKeyboardForceReply({
14
+ selective: replyMarkup.selective || undefined,
15
+ placeholder: replyMarkup.inputFieldPlaceholder,
16
+ });
17
+ }
@@ -0,0 +1,3 @@
1
+ export interface KeyboardButtonPollType {
2
+ type?: string;
3
+ }
@@ -0,0 +1,6 @@
1
+ export interface LoginUrl {
2
+ url: string;
3
+ forwardText?: string;
4
+ botUsername?: string;
5
+ requestWriteAccess?: boolean;
6
+ }
@@ -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
- documentId: bigint;
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, documentId: obj.documentId };
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.documentId });
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,4 @@
1
+ export interface WebAppInfo {
2
+ url: string;
3
+ }
4
+ export declare function constructWebAppInfo(url: string): WebAppInfo;
@@ -0,0 +1,3 @@
1
+ export function constructWebAppInfo(url) {
2
+ return { url };
3
+ }
@@ -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;