@mtcute/core 0.31.0 → 0.32.0

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 (148) hide show
  1. package/client.cjs +12 -0
  2. package/client.js +12 -0
  3. package/highlevel/client.d.cts +74 -9
  4. package/highlevel/client.d.ts +74 -9
  5. package/highlevel/methods/chats/build-peers-index.cjs +45 -0
  6. package/highlevel/methods/chats/build-peers-index.d.cts +13 -0
  7. package/highlevel/methods/chats/build-peers-index.d.ts +13 -0
  8. package/highlevel/methods/chats/build-peers-index.js +40 -0
  9. package/highlevel/methods/ephemeral/delete-all-welcome-messages.cjs +17 -0
  10. package/highlevel/methods/ephemeral/delete-all-welcome-messages.d.cts +8 -0
  11. package/highlevel/methods/ephemeral/delete-all-welcome-messages.d.ts +8 -0
  12. package/highlevel/methods/ephemeral/delete-all-welcome-messages.js +12 -0
  13. package/highlevel/methods/ephemeral/delete-ephemeral-message.cjs +1 -1
  14. package/highlevel/methods/ephemeral/delete-ephemeral-message.d.cts +2 -2
  15. package/highlevel/methods/ephemeral/delete-ephemeral-message.d.ts +2 -2
  16. package/highlevel/methods/ephemeral/delete-ephemeral-message.js +1 -1
  17. package/highlevel/methods/ephemeral/delete-welcome-message.cjs +18 -0
  18. package/highlevel/methods/ephemeral/delete-welcome-message.d.cts +9 -0
  19. package/highlevel/methods/ephemeral/delete-welcome-message.d.ts +9 -0
  20. package/highlevel/methods/ephemeral/delete-welcome-message.js +13 -0
  21. package/highlevel/methods/ephemeral/edit-ephemeral-message.cjs +11 -3
  22. package/highlevel/methods/ephemeral/edit-ephemeral-message.d.cts +16 -2
  23. package/highlevel/methods/ephemeral/edit-ephemeral-message.d.ts +16 -2
  24. package/highlevel/methods/ephemeral/edit-ephemeral-message.js +11 -3
  25. package/highlevel/methods/ephemeral/get-welcome-messages.cjs +29 -0
  26. package/highlevel/methods/ephemeral/get-welcome-messages.d.cts +8 -0
  27. package/highlevel/methods/ephemeral/get-welcome-messages.d.ts +8 -0
  28. package/highlevel/methods/ephemeral/get-welcome-messages.js +24 -0
  29. package/highlevel/methods/ephemeral/send-ephemeral-message.cjs +13 -3
  30. package/highlevel/methods/ephemeral/send-ephemeral-message.d.cts +20 -2
  31. package/highlevel/methods/ephemeral/send-ephemeral-message.d.ts +20 -2
  32. package/highlevel/methods/ephemeral/send-ephemeral-message.js +13 -3
  33. package/highlevel/methods/files/download-iterable.cjs +3 -0
  34. package/highlevel/methods/files/download-iterable.js +3 -0
  35. package/highlevel/methods/files/normalize-input-media.cjs +25 -4
  36. package/highlevel/methods/files/normalize-input-media.js +25 -4
  37. package/highlevel/methods/forums/edit-forum-topic.cjs +1 -1
  38. package/highlevel/methods/forums/edit-forum-topic.js +1 -1
  39. package/highlevel/methods/forums/toggle-forum-topic-closed.cjs +1 -1
  40. package/highlevel/methods/forums/toggle-forum-topic-closed.js +1 -1
  41. package/highlevel/methods/forums/toggle-general-topic-hidden.cjs +1 -1
  42. package/highlevel/methods/forums/toggle-general-topic-hidden.js +1 -1
  43. package/highlevel/methods/gifts/buy-resale-gift.cjs +5 -2
  44. package/highlevel/methods/gifts/buy-resale-gift.d.cts +11 -1
  45. package/highlevel/methods/gifts/buy-resale-gift.d.ts +11 -1
  46. package/highlevel/methods/gifts/buy-resale-gift.js +5 -2
  47. package/highlevel/methods/messages/forward-messages.cjs +1 -0
  48. package/highlevel/methods/messages/forward-messages.d.cts +2 -0
  49. package/highlevel/methods/messages/forward-messages.d.ts +2 -0
  50. package/highlevel/methods/messages/forward-messages.js +1 -0
  51. package/highlevel/methods/messages/normalize-rich-message.cjs +3 -0
  52. package/highlevel/methods/messages/normalize-rich-message.js +3 -0
  53. package/highlevel/methods/messages/send-text.cjs +2 -33
  54. package/highlevel/methods/messages/send-text.js +2 -33
  55. package/highlevel/methods/messages/send-typing.d.cts +3 -3
  56. package/highlevel/methods/messages/send-typing.d.ts +3 -3
  57. package/highlevel/methods/messages/set-typing.cjs +1 -1
  58. package/highlevel/methods/messages/set-typing.d.cts +2 -2
  59. package/highlevel/methods/messages/set-typing.d.ts +2 -2
  60. package/highlevel/methods/messages/set-typing.js +1 -1
  61. package/highlevel/methods.d.cts +3 -0
  62. package/highlevel/methods.d.ts +3 -0
  63. package/highlevel/types/bots/keyboards/builder.cjs +5 -5
  64. package/highlevel/types/bots/keyboards/builder.d.cts +8 -9
  65. package/highlevel/types/bots/keyboards/builder.d.ts +8 -9
  66. package/highlevel/types/bots/keyboards/builder.js +5 -5
  67. package/highlevel/types/bots/keyboards/factories.cjs +51 -103
  68. package/highlevel/types/bots/keyboards/factories.d.cts +58 -89
  69. package/highlevel/types/bots/keyboards/factories.d.ts +58 -89
  70. package/highlevel/types/bots/keyboards/factories.js +51 -103
  71. package/highlevel/types/bots/keyboards/index.d.cts +3 -3
  72. package/highlevel/types/bots/keyboards/index.d.ts +3 -3
  73. package/highlevel/types/bots/keyboards/normalize.cjs +131 -0
  74. package/highlevel/types/bots/keyboards/normalize.d.cts +10 -0
  75. package/highlevel/types/bots/keyboards/normalize.d.ts +10 -0
  76. package/highlevel/types/bots/keyboards/normalize.js +126 -0
  77. package/highlevel/types/bots/keyboards/types.d.cts +160 -4
  78. package/highlevel/types/bots/keyboards/types.d.ts +160 -4
  79. package/highlevel/types/messages/dialog.cjs +8 -1
  80. package/highlevel/types/messages/dialog.d.cts +3 -0
  81. package/highlevel/types/messages/dialog.d.ts +3 -0
  82. package/highlevel/types/messages/dialog.js +8 -1
  83. package/highlevel/types/messages/dialog.test.d.cts +1 -0
  84. package/highlevel/types/messages/dialog.test.d.ts +1 -0
  85. package/highlevel/types/messages/ephemeral-message.cjs +35 -3
  86. package/highlevel/types/messages/ephemeral-message.d.cts +22 -2
  87. package/highlevel/types/messages/ephemeral-message.d.ts +22 -2
  88. package/highlevel/types/messages/ephemeral-message.js +35 -3
  89. package/highlevel/types/messages/message-action.cjs +8 -1
  90. package/highlevel/types/messages/message-action.d.cts +11 -1
  91. package/highlevel/types/messages/message-action.d.ts +11 -1
  92. package/highlevel/types/messages/message-action.js +8 -1
  93. package/highlevel/types/messages/message.cjs +7 -2
  94. package/highlevel/types/messages/message.d.cts +2 -2
  95. package/highlevel/types/messages/message.d.ts +2 -2
  96. package/highlevel/types/messages/message.js +8 -3
  97. package/highlevel/types/messages/rich/inner.cjs +37 -0
  98. package/highlevel/types/messages/rich/inner.d.cts +19 -0
  99. package/highlevel/types/messages/rich/inner.d.ts +19 -0
  100. package/highlevel/types/messages/rich/inner.js +37 -0
  101. package/highlevel/types/peers/full-chat.cjs +4 -0
  102. package/highlevel/types/peers/full-chat.d.cts +2 -0
  103. package/highlevel/types/peers/full-chat.d.ts +2 -0
  104. package/highlevel/types/peers/full-chat.js +4 -0
  105. package/highlevel/types/peers/typing-status.d.cts +4 -1
  106. package/highlevel/types/peers/typing-status.d.ts +4 -1
  107. package/highlevel/types/updates/ephemeral-callback-query.cjs +10 -2
  108. package/highlevel/types/updates/ephemeral-callback-query.d.cts +8 -2
  109. package/highlevel/types/updates/ephemeral-callback-query.d.ts +8 -2
  110. package/highlevel/types/updates/ephemeral-callback-query.js +10 -2
  111. package/highlevel/types/updates/user-typing-update.cjs +18 -0
  112. package/highlevel/types/updates/user-typing-update.d.cts +9 -0
  113. package/highlevel/types/updates/user-typing-update.d.ts +9 -0
  114. package/highlevel/types/updates/user-typing-update.js +18 -0
  115. package/highlevel/updates/manager.cjs +40 -28
  116. package/highlevel/updates/manager.js +40 -28
  117. package/highlevel/utils/walk-page-blocks.cjs +5 -0
  118. package/highlevel/utils/walk-page-blocks.js +5 -0
  119. package/methods.cjs +6 -0
  120. package/methods.js +6 -0
  121. package/network/mtproto-session.cjs +9 -2
  122. package/network/mtproto-session.d.cts +3 -1
  123. package/network/mtproto-session.d.ts +3 -1
  124. package/network/mtproto-session.js +9 -2
  125. package/network/network-manager.cjs +1 -1
  126. package/network/network-manager.js +1 -1
  127. package/network/session-connection.cjs +12 -6
  128. package/network/session-connection.js +12 -6
  129. package/network/session-connection.test.d.cts +1 -0
  130. package/network/session-connection.test.d.ts +1 -0
  131. package/package.json +3 -3
  132. package/tl/api-schema.json +1 -1
  133. package/tl/binary/reader.cjs +136 -93
  134. package/tl/binary/reader.js +136 -93
  135. package/tl/binary/writer.cjs +318 -207
  136. package/tl/binary/writer.js +318 -207
  137. package/tl/compat/reader.cjs +82 -0
  138. package/tl/compat/reader.js +82 -0
  139. package/tl/index.d.cts +377 -718
  140. package/tl/index.d.ts +377 -718
  141. package/tl/inner-tl.cjs +23 -7
  142. package/tl/inner-tl.js +23 -7
  143. package/tl/rpc-error.test.d.cts +1 -0
  144. package/tl/rpc-error.test.d.ts +1 -0
  145. package/utils/binary/compat.cjs +175 -29
  146. package/utils/binary/compat.js +175 -29
  147. package/utils/links/bots.cjs +9 -4
  148. package/utils/links/bots.js +9 -4
@@ -1,21 +1,24 @@
1
- import { InlineKeyboardMarkup, ReplyKeyboardForceReply, ReplyKeyboardHide, ReplyKeyboardMarkup, ReplyMarkup } from './types.js';
1
+ import { BotKeyboardButtonStyle, CallbackButton, CopyButton, DisabledButton, GameButton, InlineKeyboardMarkup, InputInlineKeyboardButton, InputReplyKeyboardButton, PayButton, ReplyKeyboardForceReply, ReplyKeyboardHide, ReplyKeyboardMarkup, ReplyMarkup, RequestContactButton, RequestGeoButton, RequestPeerButton, RequestPollButton, SwitchInlineButton, TextButton, UrlAuthButton, UrlButton, UserProfileButton, WebViewButton } from './types.js';
2
2
  import { tl } from '../../../../tl/index.js';
3
3
  import { BotKeyboardBuilder } from './builder.js';
4
- /** Create a keyboard builder */
5
- export declare function builder(maxRowWidth?: number | null): BotKeyboardBuilder;
4
+ /** Create a builder for an inline keyboard */
5
+ export declare function builder(maxRowWidth?: number | null): BotKeyboardBuilder<InputInlineKeyboardButton>;
6
+ /** Create a builder for a reply keyboard */
7
+ export declare function replyBuilder(maxRowWidth?: number | null): BotKeyboardBuilder<InputReplyKeyboardButton>;
6
8
  /**
7
9
  * Create an inline keyboard markup
8
10
  *
9
11
  * @param buttons Two-dimensional array of buttons
12
+ * @param params Additional parameters for the keyboard
10
13
  */
11
- export declare function inline(buttons: tl.TypeKeyboardButton[][]): InlineKeyboardMarkup;
14
+ export declare function inline(buttons: InputInlineKeyboardButton[][], params?: Omit<InlineKeyboardMarkup, 'type' | 'buttons'>): InlineKeyboardMarkup;
12
15
  /**
13
16
  * Create a reply keyboard markup
14
17
  *
15
18
  * @param buttons Two-dimensional array of buttons
16
19
  * @param params Additional parameters for the keyboard
17
20
  */
18
- export declare function reply(buttons: tl.TypeKeyboardButton[][], params?: Omit<ReplyKeyboardMarkup, 'type' | 'buttons'>): ReplyKeyboardMarkup;
21
+ export declare function reply(buttons: InputReplyKeyboardButton[][], params?: Omit<ReplyKeyboardMarkup, 'type' | 'buttons'>): ReplyKeyboardMarkup;
19
22
  /**
20
23
  * Hide the previously sent reply keyboard
21
24
  *
@@ -29,6 +32,9 @@ export declare function hideReply(selective?: boolean): ReplyKeyboardHide;
29
32
  * Force the user to send a reply
30
33
  */
31
34
  export declare function forceReply(params?: Omit<ReplyKeyboardForceReply, 'type'>): ReplyKeyboardForceReply;
35
+ interface ButtonOptions {
36
+ style?: BotKeyboardButtonStyle;
37
+ }
32
38
  /**
33
39
  * Create a text-only keyboard button.
34
40
  *
@@ -36,7 +42,7 @@ export declare function forceReply(params?: Omit<ReplyKeyboardForceReply, 'type'
36
42
  *
37
43
  * @param text Button text
38
44
  */
39
- export declare function text(text: string): tl.RawKeyboardButton;
45
+ export declare function text(text: string, options?: ButtonOptions): TextButton;
40
46
  /**
41
47
  * Create a keyboard button requesting for user's contact.
42
48
  * Available only for private chats.
@@ -45,7 +51,7 @@ export declare function text(text: string): tl.RawKeyboardButton;
45
51
  *
46
52
  * @param text Button text
47
53
  */
48
- export declare function requestContact(text: string): tl.RawKeyboardButtonRequestPhone;
54
+ export declare function requestContact(text: string, options?: ButtonOptions): RequestContactButton;
49
55
  /**
50
56
  * Create a keyboard button requesting for user's geo location.
51
57
  * Available only for private chats.
@@ -54,7 +60,7 @@ export declare function requestContact(text: string): tl.RawKeyboardButtonReques
54
60
  *
55
61
  * @param text Button text
56
62
  */
57
- export declare function requestGeo(text: string): tl.RawKeyboardButtonRequestGeoLocation;
63
+ export declare function requestGeo(text: string, options?: ButtonOptions): RequestGeoButton;
58
64
  /**
59
65
  * Create a keyboard button requesting the user to create and send a poll.
60
66
  * Available only for private chats.
@@ -64,7 +70,16 @@ export declare function requestGeo(text: string): tl.RawKeyboardButtonRequestGeo
64
70
  * @param text Button text
65
71
  * @param quiz If set, only quiz polls can be sent
66
72
  */
67
- export declare function requestPoll(text: string, quiz?: boolean): tl.RawKeyboardButtonRequestPoll;
73
+ export declare function requestPoll(text: string, quiz?: boolean, options?: ButtonOptions): RequestPollButton;
74
+ /**
75
+ * Button to request a peer from the user
76
+ *
77
+ * Used for reply keyboards, not inline!
78
+ *
79
+ * @param text Text of the button
80
+ * @param buttonId ID of the button that will later be passed to the service message
81
+ */
82
+ export declare function requestPeer(text: string, buttonId: number, params: ButtonOptions & Omit<RequestPeerButton, 'type' | 'text' | 'buttonId' | 'style'>): RequestPeerButton;
68
83
  /**
69
84
  * Create a keyboard button with a link.
70
85
  *
@@ -73,24 +88,22 @@ export declare function requestPoll(text: string, quiz?: boolean): tl.RawKeyboar
73
88
  * @param text Button text
74
89
  * @param url URL
75
90
  */
76
- export declare function url(text: string, url: string, options?: {
77
- style?: tl.RawKeyboardButtonStyle;
78
- }): tl.RawKeyboardButtonUrl;
91
+ export declare function url(text: string, url: string, options?: ButtonOptions): UrlButton;
79
92
  /**
80
- * Create a keyboard button with a link.
93
+ * Create a keyboard button with callback data.
81
94
  *
82
95
  * Used for inline keyboards, not reply!
83
96
  *
84
97
  * @param text Button text
85
98
  * @param data Callback data (1-64 bytes). String will be converted to `Buffer`
86
- * @param requiresPassword
87
- * Whether the user should verify their identity by entering 2FA password.
88
- * See more: {@link tl.RawKeyboardButtonCallback#requiresPassword}
89
99
  */
90
- export declare function callback(text: string, data: string | Uint8Array, options?: {
100
+ export declare function callback(text: string, data: string | Uint8Array, options?: ButtonOptions & {
101
+ /**
102
+ * Whether the user should verify their identity by entering 2FA password.
103
+ * See more: {@link tl.RawInlineButtonTypeCallback#requiresPassword}
104
+ */
91
105
  requiresPassword?: boolean;
92
- style?: tl.RawKeyboardButtonStyle;
93
- }): tl.RawKeyboardButtonCallback;
106
+ }): CallbackButton;
94
107
  /**
95
108
  * Button to force a user to switch to inline mode.
96
109
  *
@@ -101,20 +114,8 @@ export declare function callback(text: string, data: string | Uint8Array, option
101
114
  * Used for inline keyboards, not reply!
102
115
  *
103
116
  * @param text Button text
104
- * @param query Inline query (can be empty or omitted)
105
117
  */
106
- export declare function switchInline(text: string, options?: {
107
- /**
108
- * Inline query (can be empty or omitted)
109
- */
110
- query?: string;
111
- /**
112
- * If set, pressing the button will insert the bot's username
113
- * and the specified inline query in the current chat's input field
114
- */
115
- currentChat?: boolean;
116
- style?: tl.RawKeyboardButtonStyle;
117
- }): tl.RawKeyboardButtonSwitchInline;
118
+ export declare function switchInline(text: string, options?: ButtonOptions & Omit<SwitchInlineButton, 'type' | 'text' | 'style'>): SwitchInlineButton;
118
119
  /**
119
120
  * Button to start a game
120
121
  *
@@ -125,9 +126,7 @@ export declare function switchInline(text: string, options?: {
125
126
  * game is inferred from {@link InputMedia.game},
126
127
  * thus this button should only be used with it.
127
128
  */
128
- export declare function game(text: string, options?: {
129
- style?: tl.RawKeyboardButtonStyle;
130
- }): tl.RawKeyboardButtonGame;
129
+ export declare function game(text: string, options?: ButtonOptions): GameButton;
131
130
  /**
132
131
  * Button to pay for a product.
133
132
  *
@@ -138,95 +137,65 @@ export declare function game(text: string, options?: {
138
137
  * invoice is inferred from {@link InputMedia.invoice},
139
138
  * thus this button should only be used with it.
140
139
  */
141
- export declare function pay(text: string, options?: {
142
- style?: tl.RawKeyboardButtonStyle;
143
- }): tl.RawKeyboardButtonBuy;
140
+ export declare function pay(text: string, options?: ButtonOptions): PayButton;
144
141
  /**
145
142
  * Button to authorize a user
146
143
  *
147
144
  * Used for inline keyboards, not reply!
148
145
  *
149
146
  * @param text Button label
150
- * @param url Authorization URL (see {@link tl.RawInputKeyboardButtonUrlAuth})
147
+ * @param url Authorization URL (see {@link tl.RawInputInlineButtonTypeUrlAuth})
151
148
  * @param params
152
149
  */
153
- export declare function urlAuth(text: string, url: string, params?: {
154
- /**
155
- * Button label when forwarded
156
- */
157
- fwdText?: string;
158
- /**
159
- * Whether to request the permission for
160
- * your bot to send messages to the user
161
- */
162
- requestWriteAccess?: boolean;
163
- style?: tl.RawKeyboardButtonStyle;
164
- /**
165
- * Bot, which will be used for user authorization.
166
- * `url` domain must be the same as the domain linked
167
- * with the bot.
168
- *
169
- * @default current bot
170
- */
171
- bot?: tl.TypeInputUser;
172
- }): tl.RawInputKeyboardButtonUrlAuth;
150
+ export declare function urlAuth(text: string, url: string, params?: ButtonOptions & Omit<UrlAuthButton, 'type' | 'text' | 'url' | 'style'>): UrlAuthButton;
173
151
  /**
174
152
  * Button to open webview
175
153
  *
176
154
  * Used for both inline keyboards and reply ones
155
+ * (in the latter case it is sent as a simple webview button)
177
156
  *
178
157
  * @param text Button label
179
158
  * @param url WebView URL
180
159
  */
181
- export declare function webView(text: string, url: string, options?: {
182
- style?: tl.RawKeyboardButtonStyle;
183
- }): tl.RawKeyboardButtonWebView;
160
+ export declare function webView(text: string, url: string, options?: ButtonOptions): WebViewButton;
184
161
  /**
185
162
  * Button to open user profile
186
163
  *
164
+ * Used for inline keyboards, not reply!
165
+ *
187
166
  * @param text Text of the button
188
167
  * @param user User to be opened (use {@link TelegramClient.resolvePeer})
189
168
  */
190
- export declare function userProfile(text: string, user: tl.TypeInputPeer, options?: {
191
- style?: tl.RawKeyboardButtonStyle;
192
- }): tl.RawInputKeyboardButtonUserProfile;
169
+ export declare function userProfile(text: string, user: tl.TypeInputPeer, options?: ButtonOptions): UserProfileButton;
193
170
  /**
194
- * Button to request a peer from the user
171
+ * Button to copy text to the user's clipboard
195
172
  *
196
- * @param text Text of the button
197
- * @param buttonId ID of the button that will later be passed to the service message
173
+ * Used for inline keyboards, not reply!
198
174
  */
199
- export declare function requestPeer(text: string, buttonId: number, params: {
200
- /**
201
- * Peer type, along with filters
202
- */
203
- peerType: tl.TypeRequestPeerType;
204
- /**
205
- * Maximum number of peers to be selected
206
- *
207
- * @default 1
208
- */
209
- count?: number;
210
- style?: tl.RawKeyboardButtonStyle;
211
- }): tl.RawKeyboardButtonRequestPeer;
175
+ export declare function copy(params: ButtonOptions & Omit<CopyButton, 'type' | 'style'>): CopyButton;
212
176
  /**
213
- * Button to copy text to the user's clipboard
177
+ * Button that does nothing when pressed
178
+ *
179
+ * Used for inline keyboards, not reply!
214
180
  */
215
- export declare function copy(params: {
216
- text: string;
217
- copyText?: string;
218
- style?: tl.RawKeyboardButtonStyle;
219
- }): tl.RawKeyboardButtonCopy;
181
+ export declare function disabled(text: string, options?: ButtonOptions): DisabledButton;
220
182
  /**
221
183
  * Find a button in the keyboard by its text or by predicate
222
184
  *
223
185
  * @param buttons Two-dimensional array of buttons
224
186
  * @param predicate Button text or predicate function
225
187
  */
226
- export declare function findButton(buttons: tl.TypeKeyboardButton[][], predicate: string | ((btn: tl.TypeKeyboardButton) => boolean)): tl.TypeKeyboardButton | null;
188
+ export declare function findButton<T extends {
189
+ text: string;
190
+ }>(buttons: T[][], predicate: string | ((btn: T) => boolean)): T | null;
227
191
  /** @internal */
228
192
  export declare function _rowsTo2d(rows: tl.RawKeyboardButtonRow[]): tl.TypeKeyboardButton[][];
229
193
  /** @internal */
230
- export declare function _2dToRows(arr: tl.TypeKeyboardButton[][], inline: boolean): tl.RawKeyboardButtonRow[];
194
+ export declare function _inlineRowsTo2d(rows: tl.RawKeyboardInlineButtonRow[]): tl.TypeKeyboardInlineButton[][];
195
+ /** @internal */
196
+ export declare function _2dToRows(arr: InputReplyKeyboardButton[][]): tl.RawKeyboardButtonRow[];
197
+ /** @internal */
198
+ export declare function _2dToInlineRows(arr: InputInlineKeyboardButton[][]): tl.RawKeyboardInlineButtonRow[];
231
199
  /** @internal */
232
200
  export declare function _convertToTl(obj?: ReplyMarkup): tl.TypeReplyMarkup | undefined;
201
+ export {};
@@ -2,15 +2,19 @@ import { utf8 } from "@fuman/utils";
2
2
  import { assertNever } from "../../../../types/utils.js";
3
3
  import { toInputUser } from "../../../utils/peer-utils.js";
4
4
  import { BotKeyboardBuilder } from "./builder.js";
5
+ import { _toReplyButton, _toInlineButton } from "./normalize.js";
5
6
  import { isAnyReplyMarkup } from "../../../../tl/inner-tl.js";
6
7
  function builder(maxRowWidth) {
7
8
  return new BotKeyboardBuilder(maxRowWidth);
8
9
  }
9
- function inline(buttons) {
10
- return {
11
- type: "inline",
12
- buttons
13
- };
10
+ function replyBuilder(maxRowWidth) {
11
+ return new BotKeyboardBuilder(maxRowWidth);
12
+ }
13
+ function inline(buttons, params = {}) {
14
+ const ret = params;
15
+ ret.type = "inline";
16
+ ret.buttons = buttons;
17
+ return ret;
14
18
  }
15
19
  function reply(buttons, params = {}) {
16
20
  const ret = params;
@@ -29,116 +33,61 @@ function forceReply(params = {}) {
29
33
  ret.type = "force_reply";
30
34
  return ret;
31
35
  }
32
- function text(text2) {
33
- return {
34
- _: "keyboardButton",
35
- text: text2
36
- };
36
+ function text(text2, options) {
37
+ return { type: "text", text: text2, style: options?.style };
37
38
  }
38
- function requestContact(text2) {
39
- return {
40
- _: "keyboardButtonRequestPhone",
41
- text: text2
42
- };
39
+ function requestContact(text2, options) {
40
+ return { type: "request_contact", text: text2, style: options?.style };
43
41
  }
44
- function requestGeo(text2) {
45
- return {
46
- _: "keyboardButtonRequestGeoLocation",
47
- text: text2
48
- };
42
+ function requestGeo(text2, options) {
43
+ return { type: "request_geo", text: text2, style: options?.style };
49
44
  }
50
- function requestPoll(text2, quiz) {
51
- return {
52
- _: "keyboardButtonRequestPoll",
53
- text: text2,
54
- quiz
55
- };
45
+ function requestPoll(text2, quiz, options) {
46
+ return { type: "request_poll", text: text2, quiz, style: options?.style };
47
+ }
48
+ function requestPeer(text2, buttonId, params) {
49
+ return { ...params, type: "request_peer", text: text2, buttonId, style: params.style };
56
50
  }
57
51
  function url(text2, url2, options) {
58
- return {
59
- _: "keyboardButtonUrl",
60
- text: text2,
61
- url: url2,
62
- style: options?.style
63
- };
52
+ return { type: "url", text: text2, url: url2, style: options?.style };
64
53
  }
65
54
  function callback(text2, data, options) {
66
55
  return {
67
- _: "keyboardButtonCallback",
56
+ type: "callback",
68
57
  text: text2,
58
+ data: typeof data === "string" ? utf8.encoder.encode(data) : data,
69
59
  requiresPassword: options?.requiresPassword,
70
- style: options?.style,
71
- data: typeof data === "string" ? utf8.encoder.encode(data) : data
60
+ style: options?.style
72
61
  };
73
62
  }
74
63
  function switchInline(text2, options) {
75
- return {
76
- _: "keyboardButtonSwitchInline",
77
- samePeer: options?.currentChat,
78
- style: options?.style,
79
- text: text2,
80
- query: options?.query ?? ""
81
- };
64
+ return { ...options, type: "switch_inline", text: text2, style: options?.style };
82
65
  }
83
66
  function game(text2, options) {
84
- return { _: "keyboardButtonGame", text: text2, style: options?.style };
67
+ return { type: "game", text: text2, style: options?.style };
85
68
  }
86
69
  function pay(text2, options) {
87
- return { _: "keyboardButtonBuy", text: text2, style: options?.style };
70
+ return { type: "pay", text: text2, style: options?.style };
88
71
  }
89
72
  function urlAuth(text2, url2, params = {}) {
90
- return {
91
- _: "inputKeyboardButtonUrlAuth",
92
- text: text2,
93
- url: url2,
94
- bot: params.bot ?? {
95
- _: "inputUserSelf"
96
- },
97
- fwdText: params.fwdText,
98
- requestWriteAccess: params.requestWriteAccess,
99
- style: params.style
100
- };
73
+ return { ...params, type: "url_auth", text: text2, url: url2, style: params.style };
101
74
  }
102
75
  function webView(text2, url2, options) {
103
- return {
104
- _: "keyboardButtonWebView",
105
- text: text2,
106
- url: url2,
107
- style: options?.style
108
- };
76
+ return { type: "webview", text: text2, url: url2, style: options?.style };
109
77
  }
110
78
  function userProfile(text2, user, options) {
111
- return {
112
- _: "inputKeyboardButtonUserProfile",
113
- text: text2,
114
- userId: toInputUser(user),
115
- style: options?.style
116
- };
117
- }
118
- function requestPeer(text2, buttonId, params) {
119
- return {
120
- _: "keyboardButtonRequestPeer",
121
- text: text2,
122
- buttonId,
123
- peerType: params.peerType,
124
- maxQuantity: params.count ?? 1,
125
- style: params.style
126
- };
79
+ return { type: "user_profile", text: text2, user: toInputUser(user), style: options?.style };
127
80
  }
128
81
  function copy(params) {
129
- return {
130
- _: "keyboardButtonCopy",
131
- text: params.text,
132
- copyText: params?.copyText ?? params.text,
133
- style: params.style
134
- };
82
+ return { ...params, type: "copy", style: params.style };
83
+ }
84
+ function disabled(text2, options) {
85
+ return { type: "disabled", text: text2, style: options?.style };
135
86
  }
136
87
  function findButton(buttons, predicate) {
137
88
  if (typeof predicate === "string") {
138
89
  const text2 = predicate;
139
- predicate = (btn) => {
140
- return "text" in btn && btn.text === text2;
141
- };
90
+ predicate = (btn) => btn.text === text2;
142
91
  }
143
92
  for (const row of buttons) {
144
93
  for (const btn of row) {
@@ -152,21 +101,14 @@ function findButton(buttons, predicate) {
152
101
  function _rowsTo2d(rows) {
153
102
  return rows.map((it) => it.buttons);
154
103
  }
155
- function _2dToRows(arr, inline2) {
156
- return arr.map((row) => {
157
- if (!inline2) {
158
- row = row.map(
159
- (btn) => btn._ === "keyboardButtonWebView" ? {
160
- ...btn,
161
- _: "keyboardButtonSimpleWebView"
162
- } : btn
163
- );
164
- }
165
- return {
166
- _: "keyboardButtonRow",
167
- buttons: row
168
- };
169
- });
104
+ function _inlineRowsTo2d(rows) {
105
+ return rows.map((it) => it.buttons);
106
+ }
107
+ function _2dToRows(arr) {
108
+ return arr.map((row) => ({ _: "keyboardButtonRow", buttons: row.map(_toReplyButton) }));
109
+ }
110
+ function _2dToInlineRows(arr) {
111
+ return arr.map((row) => ({ _: "keyboardInlineButtonRow", buttons: row.map(_toInlineButton) }));
170
112
  }
171
113
  function _convertToTl(obj) {
172
114
  if (!obj) return obj;
@@ -179,8 +121,9 @@ function _convertToTl(obj) {
179
121
  singleUse: obj.singleUse,
180
122
  selective: obj.selective,
181
123
  persistent: obj.persistent,
124
+ forceReply: obj.forceReply,
182
125
  placeholder: obj.placeholder,
183
- rows: _2dToRows(obj.buttons, false)
126
+ rows: _2dToRows(obj.buttons)
184
127
  };
185
128
  case "reply_hide":
186
129
  return {
@@ -197,19 +140,23 @@ function _convertToTl(obj) {
197
140
  case "inline":
198
141
  return {
199
142
  _: "replyInlineMarkup",
200
- rows: _2dToRows(obj.buttons, true)
143
+ forceReply: obj.forceReply,
144
+ rows: _2dToInlineRows(obj.buttons)
201
145
  };
202
146
  default:
203
147
  assertNever();
204
148
  }
205
149
  }
206
150
  export {
151
+ _2dToInlineRows,
207
152
  _2dToRows,
208
153
  _convertToTl,
154
+ _inlineRowsTo2d,
209
155
  _rowsTo2d,
210
156
  builder,
211
157
  callback,
212
158
  copy,
159
+ disabled,
213
160
  findButton,
214
161
  forceReply,
215
162
  game,
@@ -217,6 +164,7 @@ export {
217
164
  inline,
218
165
  pay,
219
166
  reply,
167
+ replyBuilder,
220
168
  requestContact,
221
169
  requestGeo,
222
170
  requestPeer,
@@ -8,8 +8,8 @@ export {
8
8
  *
9
9
  * You can also use the type-discriminated objects directly.
10
10
  *
11
- * > **Note**: Button creation functions are intended to be used
12
- * > with inline reply markup, unless stated otherwise
13
- * > in the description.
11
+ * > **Note**: Buttons are split into inline-only and reply-only ones
12
+ * > (see the description of each function), and passing one where the
13
+ * > other is expected is a type error.
14
14
  */
15
15
  BotKeyboard, };
@@ -8,8 +8,8 @@ export {
8
8
  *
9
9
  * You can also use the type-discriminated objects directly.
10
10
  *
11
- * > **Note**: Button creation functions are intended to be used
12
- * > with inline reply markup, unless stated otherwise
13
- * > in the description.
11
+ * > **Note**: Buttons are split into inline-only and reply-only ones
12
+ * > (see the description of each function), and passing one where the
13
+ * > other is expected is a type error.
14
14
  */
15
15
  BotKeyboard, };
@@ -0,0 +1,131 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const errors = require("../../../../types/errors.cjs");
9
+ function toKeyboardStyle(style) {
10
+ if (!style) return void 0;
11
+ return {
12
+ _: "keyboardButtonStyle",
13
+ bgPrimary: style.bgPrimary,
14
+ bgDanger: style.bgDanger,
15
+ bgSuccess: style.bgSuccess,
16
+ icon: style.icon
17
+ };
18
+ }
19
+ function _toRichButtonStyle(style) {
20
+ if (!style) return void 0;
21
+ return {
22
+ _: "richButtonStyle",
23
+ bgPrimary: style.bgPrimary,
24
+ bgDanger: style.bgDanger,
25
+ bgSuccess: style.bgSuccess,
26
+ link: style.link
27
+ };
28
+ }
29
+ function _toInlineButtonType(btn) {
30
+ switch (btn.type) {
31
+ case "url":
32
+ return { _: "inlineButtonTypeUrl", url: btn.url };
33
+ case "webview":
34
+ return { _: "inlineButtonTypeWebView", url: btn.url };
35
+ case "callback":
36
+ return { _: "inlineButtonTypeCallback", data: btn.data, requiresPassword: btn.requiresPassword };
37
+ case "switch_inline":
38
+ return {
39
+ _: "inlineButtonTypeSwitchInline",
40
+ samePeer: btn.currentChat,
41
+ query: btn.query ?? "",
42
+ peerTypes: btn.peerTypes
43
+ };
44
+ case "game":
45
+ return { _: "inlineButtonTypeGame" };
46
+ case "pay":
47
+ return { _: "inlineButtonTypeBuy" };
48
+ case "url_auth":
49
+ return {
50
+ _: "inputInlineButtonTypeUrlAuth",
51
+ url: btn.url,
52
+ fwdText: btn.fwdText,
53
+ requestWriteAccess: btn.requestWriteAccess,
54
+ bot: btn.bot ?? { _: "inputUserSelf" }
55
+ };
56
+ case "user_profile":
57
+ return { _: "inputInlineButtonTypeUserProfile", userId: btn.user };
58
+ case "copy":
59
+ return { _: "inlineButtonTypeCopy", copyText: btn.copyText ?? btn.text };
60
+ case "disabled":
61
+ return { _: "inlineButtonTypeDisabled" };
62
+ default:
63
+ throw new errors.MtArgumentError(`"${btn.type}" buttons can only be used in reply keyboards`);
64
+ }
65
+ }
66
+ function toReplyButtonType(btn) {
67
+ switch (btn.type) {
68
+ case "text":
69
+ return { _: "buttonTypeDefault" };
70
+ case "request_contact":
71
+ return { _: "buttonTypeRequestPhone" };
72
+ case "request_geo":
73
+ return { _: "buttonTypeRequestGeoLocation" };
74
+ case "request_poll":
75
+ return { _: "buttonTypeRequestPoll", quiz: btn.quiz };
76
+ case "webview":
77
+ return { _: "buttonTypeSimpleWebView", url: btn.url };
78
+ case "request_peer":
79
+ if (btn.nameRequested || btn.usernameRequested || btn.photoRequested) {
80
+ return {
81
+ _: "inputButtonTypeRequestPeer",
82
+ nameRequested: btn.nameRequested,
83
+ usernameRequested: btn.usernameRequested,
84
+ photoRequested: btn.photoRequested,
85
+ buttonId: btn.buttonId,
86
+ peerType: btn.peerType,
87
+ maxQuantity: btn.count ?? 1
88
+ };
89
+ }
90
+ return {
91
+ _: "buttonTypeRequestPeer",
92
+ buttonId: btn.buttonId,
93
+ peerType: btn.peerType,
94
+ maxQuantity: btn.count ?? 1
95
+ };
96
+ default:
97
+ throw new errors.MtArgumentError(`"${btn.type}" buttons can only be used in inline keyboards`);
98
+ }
99
+ }
100
+ function _toInlineButton(btn) {
101
+ if ("_" in btn) {
102
+ if (btn._ !== "keyboardInlineButton") {
103
+ throw new errors.MtArgumentError("reply keyboard buttons cannot be used in inline keyboards");
104
+ }
105
+ return btn;
106
+ }
107
+ return {
108
+ _: "keyboardInlineButton",
109
+ text: btn.text,
110
+ type: _toInlineButtonType(btn),
111
+ style: toKeyboardStyle(btn.style)
112
+ };
113
+ }
114
+ function _toReplyButton(btn) {
115
+ if ("_" in btn) {
116
+ if (btn._ !== "keyboardButton") {
117
+ throw new errors.MtArgumentError("inline keyboard buttons cannot be used in reply keyboards");
118
+ }
119
+ return btn;
120
+ }
121
+ return {
122
+ _: "keyboardButton",
123
+ text: btn.text,
124
+ type: toReplyButtonType(btn),
125
+ style: toKeyboardStyle(btn.style)
126
+ };
127
+ }
128
+ exports._toInlineButton = _toInlineButton;
129
+ exports._toInlineButtonType = _toInlineButtonType;
130
+ exports._toReplyButton = _toReplyButton;
131
+ exports._toRichButtonStyle = _toRichButtonStyle;
@@ -0,0 +1,10 @@
1
+ import { tl } from '../../../../tl/index.js';
2
+ import { BotKeyboardButton, BotKeyboardButtonStyle, InputInlineKeyboardButton, InputReplyKeyboardButton } from './types.js';
3
+ /** @internal */
4
+ export declare function _toRichButtonStyle(style?: BotKeyboardButtonStyle): tl.RawRichButtonStyle | undefined;
5
+ /** @internal */
6
+ export declare function _toInlineButtonType(btn: BotKeyboardButton): tl.TypeInlineButtonType;
7
+ /** @internal */
8
+ export declare function _toInlineButton(btn: InputInlineKeyboardButton): tl.TypeKeyboardInlineButton;
9
+ /** @internal */
10
+ export declare function _toReplyButton(btn: InputReplyKeyboardButton): tl.TypeKeyboardButton;