@xtsea/tgcore-ts 0.1.8 → 0.1.9
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/dist/{index.mjs → index.cjs} +110 -82
- package/dist/index.d.ts +50 -50
- package/dist/index.js +85 -113
- package/package.json +13 -4
- package/dist/{index.d.mts → index.d.cts} +50 -50
|
@@ -1,85 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
currentRow() {
|
|
16
|
-
return this.keyboard[this.keyboard.length - 1];
|
|
17
|
-
}
|
|
18
|
-
row() {
|
|
19
|
-
if (this.currentRow().length === 0) return this;
|
|
20
|
-
this.keyboard.push([]);
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
push(btn) {
|
|
24
|
-
if (!btn.text?.trim()) throw new Error("Button text is required");
|
|
25
|
-
if (btn.text.length > 64) throw new Error("Button text too long (max 64 chars)");
|
|
26
|
-
const actionKeys = [
|
|
27
|
-
"url",
|
|
28
|
-
"callback_data",
|
|
29
|
-
"web_app",
|
|
30
|
-
"login_url",
|
|
31
|
-
"switch_inline_query",
|
|
32
|
-
"switch_inline_query_current_chat",
|
|
33
|
-
"switch_inline_query_chosen_chat",
|
|
34
|
-
"copy_text"
|
|
35
|
-
];
|
|
36
|
-
const used = actionKeys.filter((k) => btn[k] != null);
|
|
37
|
-
if (used.length !== 1) {
|
|
38
|
-
throw new Error(`InlineKeyboardButton must have exactly 1 action field, got: ${used.join(", ") || "none"}`);
|
|
39
|
-
}
|
|
40
|
-
if (btn.callback_data && btn.callback_data.length > 64) {
|
|
41
|
-
throw new Error("callback_data too long (max 64 chars)");
|
|
42
|
-
}
|
|
43
|
-
if (this._maxPerRow && this.currentRow().length >= this._maxPerRow) {
|
|
44
|
-
this.row();
|
|
45
|
-
}
|
|
46
|
-
this.currentRow().push(btn);
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
url(text, url) {
|
|
50
|
-
return this.push({ text, url });
|
|
51
|
-
}
|
|
52
|
-
style(text, style, url) {
|
|
53
|
-
return this.push({ text, style, url });
|
|
54
|
-
}
|
|
55
|
-
callback(text, data) {
|
|
56
|
-
return this.push({ text, callback_data: data });
|
|
57
|
-
}
|
|
58
|
-
webApp(text, url) {
|
|
59
|
-
return this.push({ text, web_app: { url } });
|
|
60
|
-
}
|
|
61
|
-
loginUrl(text, url, opts) {
|
|
62
|
-
return this.push({ text, login_url: { url, ...opts ?? {} } });
|
|
63
|
-
}
|
|
64
|
-
switchInline(text, query) {
|
|
65
|
-
return this.push({ text, switch_inline_query: query });
|
|
66
|
-
}
|
|
67
|
-
switchInlineCurrentChat(text, query) {
|
|
68
|
-
return this.push({ text, switch_inline_query_current_chat: query });
|
|
69
|
-
}
|
|
70
|
-
switchInlineChosenChat(text, opts) {
|
|
71
|
-
if (!opts) throw new Error("switch_inline_query_chosen_chat options required");
|
|
72
|
-
return this.push({ text, switch_inline_query_chosen_chat: opts });
|
|
73
|
-
}
|
|
74
|
-
copyText(text, copy) {
|
|
75
|
-
return this.push({ text, copy_text: { text: copy } });
|
|
76
|
-
}
|
|
77
|
-
build() {
|
|
78
|
-
const cleaned = this.keyboard.filter((r) => r.length > 0);
|
|
79
|
-
if (cleaned.length === 0) throw new Error("Keyboard is empty");
|
|
80
|
-
return { inline_keyboard: cleaned };
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
81
15
|
}
|
|
16
|
+
return to;
|
|
82
17
|
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Client: () => Client,
|
|
24
|
+
KeyboardBuilder: () => KeyboardBuilder
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
83
27
|
|
|
84
28
|
// src/http.ts
|
|
85
29
|
var Http = class {
|
|
@@ -204,7 +148,91 @@ var Client = class {
|
|
|
204
148
|
this.raw = new RawMethods(this.http);
|
|
205
149
|
}
|
|
206
150
|
};
|
|
207
|
-
|
|
151
|
+
|
|
152
|
+
// src/builders/keyboard.ts
|
|
153
|
+
var KeyboardBuilder = class _KeyboardBuilder {
|
|
154
|
+
constructor() {
|
|
155
|
+
this.keyboard = [[]];
|
|
156
|
+
this._maxPerRow = null;
|
|
157
|
+
}
|
|
158
|
+
static inline() {
|
|
159
|
+
return new _KeyboardBuilder();
|
|
160
|
+
}
|
|
161
|
+
maxPerRow(n) {
|
|
162
|
+
if (!Number.isInteger(n) || n <= 0) throw new Error("maxPerRow must be a positive integer");
|
|
163
|
+
this._maxPerRow = n;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
currentRow() {
|
|
167
|
+
return this.keyboard[this.keyboard.length - 1];
|
|
168
|
+
}
|
|
169
|
+
row() {
|
|
170
|
+
if (this.currentRow().length === 0) return this;
|
|
171
|
+
this.keyboard.push([]);
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
push(btn) {
|
|
175
|
+
if (!btn.text?.trim()) throw new Error("Button text is required");
|
|
176
|
+
if (btn.text.length > 64) throw new Error("Button text too long (max 64 chars)");
|
|
177
|
+
const actionKeys = [
|
|
178
|
+
"url",
|
|
179
|
+
"callback_data",
|
|
180
|
+
"web_app",
|
|
181
|
+
"login_url",
|
|
182
|
+
"switch_inline_query",
|
|
183
|
+
"switch_inline_query_current_chat",
|
|
184
|
+
"switch_inline_query_chosen_chat",
|
|
185
|
+
"copy_text"
|
|
186
|
+
];
|
|
187
|
+
const used = actionKeys.filter((k) => btn[k] != null);
|
|
188
|
+
if (used.length !== 1) {
|
|
189
|
+
throw new Error(`InlineKeyboardButton must have exactly 1 action field, got: ${used.join(", ") || "none"}`);
|
|
190
|
+
}
|
|
191
|
+
if (btn.callback_data && btn.callback_data.length > 64) {
|
|
192
|
+
throw new Error("callback_data too long (max 64 chars)");
|
|
193
|
+
}
|
|
194
|
+
if (this._maxPerRow && this.currentRow().length >= this._maxPerRow) {
|
|
195
|
+
this.row();
|
|
196
|
+
}
|
|
197
|
+
this.currentRow().push(btn);
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
url(text, url) {
|
|
201
|
+
return this.push({ text, url });
|
|
202
|
+
}
|
|
203
|
+
style(text, style, url) {
|
|
204
|
+
return this.push({ text, style, url });
|
|
205
|
+
}
|
|
206
|
+
callback(text, data) {
|
|
207
|
+
return this.push({ text, callback_data: data });
|
|
208
|
+
}
|
|
209
|
+
webApp(text, url) {
|
|
210
|
+
return this.push({ text, web_app: { url } });
|
|
211
|
+
}
|
|
212
|
+
loginUrl(text, url, opts) {
|
|
213
|
+
return this.push({ text, login_url: { url, ...opts ?? {} } });
|
|
214
|
+
}
|
|
215
|
+
switchInline(text, query) {
|
|
216
|
+
return this.push({ text, switch_inline_query: query });
|
|
217
|
+
}
|
|
218
|
+
switchInlineCurrentChat(text, query) {
|
|
219
|
+
return this.push({ text, switch_inline_query_current_chat: query });
|
|
220
|
+
}
|
|
221
|
+
switchInlineChosenChat(text, opts) {
|
|
222
|
+
if (!opts) throw new Error("switch_inline_query_chosen_chat options required");
|
|
223
|
+
return this.push({ text, switch_inline_query_chosen_chat: opts });
|
|
224
|
+
}
|
|
225
|
+
copyText(text, copy) {
|
|
226
|
+
return this.push({ text, copy_text: { text: copy } });
|
|
227
|
+
}
|
|
228
|
+
build() {
|
|
229
|
+
const cleaned = this.keyboard.filter((r) => r.length > 0);
|
|
230
|
+
if (cleaned.length === 0) throw new Error("Keyboard is empty");
|
|
231
|
+
return { inline_keyboard: cleaned };
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
235
|
+
0 && (module.exports = {
|
|
208
236
|
Client,
|
|
209
237
|
KeyboardBuilder
|
|
210
|
-
};
|
|
238
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,53 +1,3 @@
|
|
|
1
|
-
type InlineKeyboardButton = {
|
|
2
|
-
text: string;
|
|
3
|
-
url?: string;
|
|
4
|
-
style?: string;
|
|
5
|
-
callback_data?: string;
|
|
6
|
-
web_app?: {
|
|
7
|
-
url: string;
|
|
8
|
-
};
|
|
9
|
-
login_url?: {
|
|
10
|
-
url: string;
|
|
11
|
-
forward_text?: string;
|
|
12
|
-
bot_username?: string;
|
|
13
|
-
request_write_access?: boolean;
|
|
14
|
-
};
|
|
15
|
-
switch_inline_query?: string;
|
|
16
|
-
switch_inline_query_current_chat?: string;
|
|
17
|
-
switch_inline_query_chosen_chat?: {
|
|
18
|
-
query?: string;
|
|
19
|
-
allow_user_chats?: boolean;
|
|
20
|
-
allow_bot_chats?: boolean;
|
|
21
|
-
allow_group_chats?: boolean;
|
|
22
|
-
allow_channel_chats?: boolean;
|
|
23
|
-
};
|
|
24
|
-
copy_text?: {
|
|
25
|
-
text: string;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
type InlineKeyboardMarkup = {
|
|
29
|
-
inline_keyboard: InlineKeyboardButton[][];
|
|
30
|
-
};
|
|
31
|
-
declare class KeyboardBuilder {
|
|
32
|
-
private keyboard;
|
|
33
|
-
private _maxPerRow;
|
|
34
|
-
static inline(): KeyboardBuilder;
|
|
35
|
-
maxPerRow(n: number): this;
|
|
36
|
-
private currentRow;
|
|
37
|
-
row(): this;
|
|
38
|
-
private push;
|
|
39
|
-
url(text: string, url: string): this;
|
|
40
|
-
style(text: string, style: string, url: string): this;
|
|
41
|
-
callback(text: string, data: string): this;
|
|
42
|
-
webApp(text: string, url: string): this;
|
|
43
|
-
loginUrl(text: string, url: string, opts?: Omit<NonNullable<InlineKeyboardButton["login_url"]>, "url">): this;
|
|
44
|
-
switchInline(text: string, query: string): this;
|
|
45
|
-
switchInlineCurrentChat(text: string, query: string): this;
|
|
46
|
-
switchInlineChosenChat(text: string, opts: InlineKeyboardButton["switch_inline_query_chosen_chat"]): this;
|
|
47
|
-
copyText(text: string, copy: string): this;
|
|
48
|
-
build(): InlineKeyboardMarkup;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
1
|
type HttpOptions = {
|
|
52
2
|
api_key: string;
|
|
53
3
|
base_url: string;
|
|
@@ -110,4 +60,54 @@ declare class Client {
|
|
|
110
60
|
constructor(opts: ClientOptions);
|
|
111
61
|
}
|
|
112
62
|
|
|
63
|
+
type InlineKeyboardButton = {
|
|
64
|
+
text: string;
|
|
65
|
+
url?: string;
|
|
66
|
+
style?: string;
|
|
67
|
+
callback_data?: string;
|
|
68
|
+
web_app?: {
|
|
69
|
+
url: string;
|
|
70
|
+
};
|
|
71
|
+
login_url?: {
|
|
72
|
+
url: string;
|
|
73
|
+
forward_text?: string;
|
|
74
|
+
bot_username?: string;
|
|
75
|
+
request_write_access?: boolean;
|
|
76
|
+
};
|
|
77
|
+
switch_inline_query?: string;
|
|
78
|
+
switch_inline_query_current_chat?: string;
|
|
79
|
+
switch_inline_query_chosen_chat?: {
|
|
80
|
+
query?: string;
|
|
81
|
+
allow_user_chats?: boolean;
|
|
82
|
+
allow_bot_chats?: boolean;
|
|
83
|
+
allow_group_chats?: boolean;
|
|
84
|
+
allow_channel_chats?: boolean;
|
|
85
|
+
};
|
|
86
|
+
copy_text?: {
|
|
87
|
+
text: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
type InlineKeyboardMarkup = {
|
|
91
|
+
inline_keyboard: InlineKeyboardButton[][];
|
|
92
|
+
};
|
|
93
|
+
declare class KeyboardBuilder {
|
|
94
|
+
private keyboard;
|
|
95
|
+
private _maxPerRow;
|
|
96
|
+
static inline(): KeyboardBuilder;
|
|
97
|
+
maxPerRow(n: number): this;
|
|
98
|
+
private currentRow;
|
|
99
|
+
row(): this;
|
|
100
|
+
private push;
|
|
101
|
+
url(text: string, url: string): this;
|
|
102
|
+
style(text: string, style: string, url: string): this;
|
|
103
|
+
callback(text: string, data: string): this;
|
|
104
|
+
webApp(text: string, url: string): this;
|
|
105
|
+
loginUrl(text: string, url: string, opts?: Omit<NonNullable<InlineKeyboardButton["login_url"]>, "url">): this;
|
|
106
|
+
switchInline(text: string, query: string): this;
|
|
107
|
+
switchInlineCurrentChat(text: string, query: string): this;
|
|
108
|
+
switchInlineChosenChat(text: string, opts: InlineKeyboardButton["switch_inline_query_chosen_chat"]): this;
|
|
109
|
+
copyText(text: string, copy: string): this;
|
|
110
|
+
build(): InlineKeyboardMarkup;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
113
|
export { Client, type ClientOptions, type InlineKeyboardButton, type InlineKeyboardMarkup, KeyboardBuilder };
|
package/dist/index.js
CHANGED
|
@@ -1,113 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
Client: () => Client,
|
|
24
|
-
KeyboardBuilder: () => KeyboardBuilder
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
|
-
// src/builders/keyboard.ts
|
|
29
|
-
var KeyboardBuilder = class _KeyboardBuilder {
|
|
30
|
-
constructor() {
|
|
31
|
-
this.keyboard = [[]];
|
|
32
|
-
this._maxPerRow = null;
|
|
33
|
-
}
|
|
34
|
-
static inline() {
|
|
35
|
-
return new _KeyboardBuilder();
|
|
36
|
-
}
|
|
37
|
-
maxPerRow(n) {
|
|
38
|
-
if (!Number.isInteger(n) || n <= 0) throw new Error("maxPerRow must be a positive integer");
|
|
39
|
-
this._maxPerRow = n;
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
currentRow() {
|
|
43
|
-
return this.keyboard[this.keyboard.length - 1];
|
|
44
|
-
}
|
|
45
|
-
row() {
|
|
46
|
-
if (this.currentRow().length === 0) return this;
|
|
47
|
-
this.keyboard.push([]);
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
push(btn) {
|
|
51
|
-
if (!btn.text?.trim()) throw new Error("Button text is required");
|
|
52
|
-
if (btn.text.length > 64) throw new Error("Button text too long (max 64 chars)");
|
|
53
|
-
const actionKeys = [
|
|
54
|
-
"url",
|
|
55
|
-
"callback_data",
|
|
56
|
-
"web_app",
|
|
57
|
-
"login_url",
|
|
58
|
-
"switch_inline_query",
|
|
59
|
-
"switch_inline_query_current_chat",
|
|
60
|
-
"switch_inline_query_chosen_chat",
|
|
61
|
-
"copy_text"
|
|
62
|
-
];
|
|
63
|
-
const used = actionKeys.filter((k) => btn[k] != null);
|
|
64
|
-
if (used.length !== 1) {
|
|
65
|
-
throw new Error(`InlineKeyboardButton must have exactly 1 action field, got: ${used.join(", ") || "none"}`);
|
|
66
|
-
}
|
|
67
|
-
if (btn.callback_data && btn.callback_data.length > 64) {
|
|
68
|
-
throw new Error("callback_data too long (max 64 chars)");
|
|
69
|
-
}
|
|
70
|
-
if (this._maxPerRow && this.currentRow().length >= this._maxPerRow) {
|
|
71
|
-
this.row();
|
|
72
|
-
}
|
|
73
|
-
this.currentRow().push(btn);
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
url(text, url) {
|
|
77
|
-
return this.push({ text, url });
|
|
78
|
-
}
|
|
79
|
-
style(text, style, url) {
|
|
80
|
-
return this.push({ text, style, url });
|
|
81
|
-
}
|
|
82
|
-
callback(text, data) {
|
|
83
|
-
return this.push({ text, callback_data: data });
|
|
84
|
-
}
|
|
85
|
-
webApp(text, url) {
|
|
86
|
-
return this.push({ text, web_app: { url } });
|
|
87
|
-
}
|
|
88
|
-
loginUrl(text, url, opts) {
|
|
89
|
-
return this.push({ text, login_url: { url, ...opts ?? {} } });
|
|
90
|
-
}
|
|
91
|
-
switchInline(text, query) {
|
|
92
|
-
return this.push({ text, switch_inline_query: query });
|
|
93
|
-
}
|
|
94
|
-
switchInlineCurrentChat(text, query) {
|
|
95
|
-
return this.push({ text, switch_inline_query_current_chat: query });
|
|
96
|
-
}
|
|
97
|
-
switchInlineChosenChat(text, opts) {
|
|
98
|
-
if (!opts) throw new Error("switch_inline_query_chosen_chat options required");
|
|
99
|
-
return this.push({ text, switch_inline_query_chosen_chat: opts });
|
|
100
|
-
}
|
|
101
|
-
copyText(text, copy) {
|
|
102
|
-
return this.push({ text, copy_text: { text: copy } });
|
|
103
|
-
}
|
|
104
|
-
build() {
|
|
105
|
-
const cleaned = this.keyboard.filter((r) => r.length > 0);
|
|
106
|
-
if (cleaned.length === 0) throw new Error("Keyboard is empty");
|
|
107
|
-
return { inline_keyboard: cleaned };
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
1
|
// src/http.ts
|
|
112
2
|
var Http = class {
|
|
113
3
|
constructor(opts) {
|
|
@@ -231,8 +121,90 @@ var Client = class {
|
|
|
231
121
|
this.raw = new RawMethods(this.http);
|
|
232
122
|
}
|
|
233
123
|
};
|
|
234
|
-
|
|
235
|
-
|
|
124
|
+
|
|
125
|
+
// src/builders/keyboard.ts
|
|
126
|
+
var KeyboardBuilder = class _KeyboardBuilder {
|
|
127
|
+
constructor() {
|
|
128
|
+
this.keyboard = [[]];
|
|
129
|
+
this._maxPerRow = null;
|
|
130
|
+
}
|
|
131
|
+
static inline() {
|
|
132
|
+
return new _KeyboardBuilder();
|
|
133
|
+
}
|
|
134
|
+
maxPerRow(n) {
|
|
135
|
+
if (!Number.isInteger(n) || n <= 0) throw new Error("maxPerRow must be a positive integer");
|
|
136
|
+
this._maxPerRow = n;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
currentRow() {
|
|
140
|
+
return this.keyboard[this.keyboard.length - 1];
|
|
141
|
+
}
|
|
142
|
+
row() {
|
|
143
|
+
if (this.currentRow().length === 0) return this;
|
|
144
|
+
this.keyboard.push([]);
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
push(btn) {
|
|
148
|
+
if (!btn.text?.trim()) throw new Error("Button text is required");
|
|
149
|
+
if (btn.text.length > 64) throw new Error("Button text too long (max 64 chars)");
|
|
150
|
+
const actionKeys = [
|
|
151
|
+
"url",
|
|
152
|
+
"callback_data",
|
|
153
|
+
"web_app",
|
|
154
|
+
"login_url",
|
|
155
|
+
"switch_inline_query",
|
|
156
|
+
"switch_inline_query_current_chat",
|
|
157
|
+
"switch_inline_query_chosen_chat",
|
|
158
|
+
"copy_text"
|
|
159
|
+
];
|
|
160
|
+
const used = actionKeys.filter((k) => btn[k] != null);
|
|
161
|
+
if (used.length !== 1) {
|
|
162
|
+
throw new Error(`InlineKeyboardButton must have exactly 1 action field, got: ${used.join(", ") || "none"}`);
|
|
163
|
+
}
|
|
164
|
+
if (btn.callback_data && btn.callback_data.length > 64) {
|
|
165
|
+
throw new Error("callback_data too long (max 64 chars)");
|
|
166
|
+
}
|
|
167
|
+
if (this._maxPerRow && this.currentRow().length >= this._maxPerRow) {
|
|
168
|
+
this.row();
|
|
169
|
+
}
|
|
170
|
+
this.currentRow().push(btn);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
url(text, url) {
|
|
174
|
+
return this.push({ text, url });
|
|
175
|
+
}
|
|
176
|
+
style(text, style, url) {
|
|
177
|
+
return this.push({ text, style, url });
|
|
178
|
+
}
|
|
179
|
+
callback(text, data) {
|
|
180
|
+
return this.push({ text, callback_data: data });
|
|
181
|
+
}
|
|
182
|
+
webApp(text, url) {
|
|
183
|
+
return this.push({ text, web_app: { url } });
|
|
184
|
+
}
|
|
185
|
+
loginUrl(text, url, opts) {
|
|
186
|
+
return this.push({ text, login_url: { url, ...opts ?? {} } });
|
|
187
|
+
}
|
|
188
|
+
switchInline(text, query) {
|
|
189
|
+
return this.push({ text, switch_inline_query: query });
|
|
190
|
+
}
|
|
191
|
+
switchInlineCurrentChat(text, query) {
|
|
192
|
+
return this.push({ text, switch_inline_query_current_chat: query });
|
|
193
|
+
}
|
|
194
|
+
switchInlineChosenChat(text, opts) {
|
|
195
|
+
if (!opts) throw new Error("switch_inline_query_chosen_chat options required");
|
|
196
|
+
return this.push({ text, switch_inline_query_chosen_chat: opts });
|
|
197
|
+
}
|
|
198
|
+
copyText(text, copy) {
|
|
199
|
+
return this.push({ text, copy_text: { text: copy } });
|
|
200
|
+
}
|
|
201
|
+
build() {
|
|
202
|
+
const cleaned = this.keyboard.filter((r) => r.length > 0);
|
|
203
|
+
if (cleaned.length === 0) throw new Error("Keyboard is empty");
|
|
204
|
+
return { inline_keyboard: cleaned };
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
export {
|
|
236
208
|
Client,
|
|
237
209
|
KeyboardBuilder
|
|
238
|
-
}
|
|
210
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xtsea/tgcore-ts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "tgcore TypeScript SDK • Telegram Engine Client",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
8
17
|
"license": "Apache-2.0",
|
|
9
18
|
"author": "XTSEA",
|
|
10
19
|
"repository": {
|
|
@@ -1,53 +1,3 @@
|
|
|
1
|
-
type InlineKeyboardButton = {
|
|
2
|
-
text: string;
|
|
3
|
-
url?: string;
|
|
4
|
-
style?: string;
|
|
5
|
-
callback_data?: string;
|
|
6
|
-
web_app?: {
|
|
7
|
-
url: string;
|
|
8
|
-
};
|
|
9
|
-
login_url?: {
|
|
10
|
-
url: string;
|
|
11
|
-
forward_text?: string;
|
|
12
|
-
bot_username?: string;
|
|
13
|
-
request_write_access?: boolean;
|
|
14
|
-
};
|
|
15
|
-
switch_inline_query?: string;
|
|
16
|
-
switch_inline_query_current_chat?: string;
|
|
17
|
-
switch_inline_query_chosen_chat?: {
|
|
18
|
-
query?: string;
|
|
19
|
-
allow_user_chats?: boolean;
|
|
20
|
-
allow_bot_chats?: boolean;
|
|
21
|
-
allow_group_chats?: boolean;
|
|
22
|
-
allow_channel_chats?: boolean;
|
|
23
|
-
};
|
|
24
|
-
copy_text?: {
|
|
25
|
-
text: string;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
type InlineKeyboardMarkup = {
|
|
29
|
-
inline_keyboard: InlineKeyboardButton[][];
|
|
30
|
-
};
|
|
31
|
-
declare class KeyboardBuilder {
|
|
32
|
-
private keyboard;
|
|
33
|
-
private _maxPerRow;
|
|
34
|
-
static inline(): KeyboardBuilder;
|
|
35
|
-
maxPerRow(n: number): this;
|
|
36
|
-
private currentRow;
|
|
37
|
-
row(): this;
|
|
38
|
-
private push;
|
|
39
|
-
url(text: string, url: string): this;
|
|
40
|
-
style(text: string, style: string, url: string): this;
|
|
41
|
-
callback(text: string, data: string): this;
|
|
42
|
-
webApp(text: string, url: string): this;
|
|
43
|
-
loginUrl(text: string, url: string, opts?: Omit<NonNullable<InlineKeyboardButton["login_url"]>, "url">): this;
|
|
44
|
-
switchInline(text: string, query: string): this;
|
|
45
|
-
switchInlineCurrentChat(text: string, query: string): this;
|
|
46
|
-
switchInlineChosenChat(text: string, opts: InlineKeyboardButton["switch_inline_query_chosen_chat"]): this;
|
|
47
|
-
copyText(text: string, copy: string): this;
|
|
48
|
-
build(): InlineKeyboardMarkup;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
1
|
type HttpOptions = {
|
|
52
2
|
api_key: string;
|
|
53
3
|
base_url: string;
|
|
@@ -110,4 +60,54 @@ declare class Client {
|
|
|
110
60
|
constructor(opts: ClientOptions);
|
|
111
61
|
}
|
|
112
62
|
|
|
63
|
+
type InlineKeyboardButton = {
|
|
64
|
+
text: string;
|
|
65
|
+
url?: string;
|
|
66
|
+
style?: string;
|
|
67
|
+
callback_data?: string;
|
|
68
|
+
web_app?: {
|
|
69
|
+
url: string;
|
|
70
|
+
};
|
|
71
|
+
login_url?: {
|
|
72
|
+
url: string;
|
|
73
|
+
forward_text?: string;
|
|
74
|
+
bot_username?: string;
|
|
75
|
+
request_write_access?: boolean;
|
|
76
|
+
};
|
|
77
|
+
switch_inline_query?: string;
|
|
78
|
+
switch_inline_query_current_chat?: string;
|
|
79
|
+
switch_inline_query_chosen_chat?: {
|
|
80
|
+
query?: string;
|
|
81
|
+
allow_user_chats?: boolean;
|
|
82
|
+
allow_bot_chats?: boolean;
|
|
83
|
+
allow_group_chats?: boolean;
|
|
84
|
+
allow_channel_chats?: boolean;
|
|
85
|
+
};
|
|
86
|
+
copy_text?: {
|
|
87
|
+
text: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
type InlineKeyboardMarkup = {
|
|
91
|
+
inline_keyboard: InlineKeyboardButton[][];
|
|
92
|
+
};
|
|
93
|
+
declare class KeyboardBuilder {
|
|
94
|
+
private keyboard;
|
|
95
|
+
private _maxPerRow;
|
|
96
|
+
static inline(): KeyboardBuilder;
|
|
97
|
+
maxPerRow(n: number): this;
|
|
98
|
+
private currentRow;
|
|
99
|
+
row(): this;
|
|
100
|
+
private push;
|
|
101
|
+
url(text: string, url: string): this;
|
|
102
|
+
style(text: string, style: string, url: string): this;
|
|
103
|
+
callback(text: string, data: string): this;
|
|
104
|
+
webApp(text: string, url: string): this;
|
|
105
|
+
loginUrl(text: string, url: string, opts?: Omit<NonNullable<InlineKeyboardButton["login_url"]>, "url">): this;
|
|
106
|
+
switchInline(text: string, query: string): this;
|
|
107
|
+
switchInlineCurrentChat(text: string, query: string): this;
|
|
108
|
+
switchInlineChosenChat(text: string, opts: InlineKeyboardButton["switch_inline_query_chosen_chat"]): this;
|
|
109
|
+
copyText(text: string, copy: string): this;
|
|
110
|
+
build(): InlineKeyboardMarkup;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
113
|
export { Client, type ClientOptions, type InlineKeyboardButton, type InlineKeyboardMarkup, KeyboardBuilder };
|