@xtsea/tgcore-ts 0.1.5 → 0.1.6
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.d.mts +51 -1
- package/dist/index.d.ts +51 -1
- package/dist/index.js +87 -2
- package/dist/index.mjs +85 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
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
|
+
|
|
1
51
|
type HttpOptions = {
|
|
2
52
|
api_key: string;
|
|
3
53
|
base_url: string;
|
|
@@ -60,4 +110,4 @@ declare class Client {
|
|
|
60
110
|
constructor(opts: ClientOptions);
|
|
61
111
|
}
|
|
62
112
|
|
|
63
|
-
export { Client, type ClientOptions };
|
|
113
|
+
export { Client, type ClientOptions, type InlineKeyboardButton, type InlineKeyboardMarkup, KeyboardBuilder };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
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
|
+
|
|
1
51
|
type HttpOptions = {
|
|
2
52
|
api_key: string;
|
|
3
53
|
base_url: string;
|
|
@@ -60,4 +110,4 @@ declare class Client {
|
|
|
60
110
|
constructor(opts: ClientOptions);
|
|
61
111
|
}
|
|
62
112
|
|
|
63
|
-
export { Client, type ClientOptions };
|
|
113
|
+
export { Client, type ClientOptions, type InlineKeyboardButton, type InlineKeyboardMarkup, KeyboardBuilder };
|
package/dist/index.js
CHANGED
|
@@ -20,10 +20,94 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
Client: () => Client
|
|
23
|
+
Client: () => Client,
|
|
24
|
+
KeyboardBuilder: () => KeyboardBuilder
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(index_exports);
|
|
26
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
|
+
|
|
27
111
|
// src/http.ts
|
|
28
112
|
var Http = class {
|
|
29
113
|
constructor(opts) {
|
|
@@ -149,5 +233,6 @@ var Client = class {
|
|
|
149
233
|
};
|
|
150
234
|
// Annotate the CommonJS export names for ESM import in node:
|
|
151
235
|
0 && (module.exports = {
|
|
152
|
-
Client
|
|
236
|
+
Client,
|
|
237
|
+
KeyboardBuilder
|
|
153
238
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
+
// src/builders/keyboard.ts
|
|
2
|
+
var KeyboardBuilder = class _KeyboardBuilder {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.keyboard = [[]];
|
|
5
|
+
this._maxPerRow = null;
|
|
6
|
+
}
|
|
7
|
+
static inline() {
|
|
8
|
+
return new _KeyboardBuilder();
|
|
9
|
+
}
|
|
10
|
+
maxPerRow(n) {
|
|
11
|
+
if (!Number.isInteger(n) || n <= 0) throw new Error("maxPerRow must be a positive integer");
|
|
12
|
+
this._maxPerRow = n;
|
|
13
|
+
return this;
|
|
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 };
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
1
84
|
// src/http.ts
|
|
2
85
|
var Http = class {
|
|
3
86
|
constructor(opts) {
|
|
@@ -122,5 +205,6 @@ var Client = class {
|
|
|
122
205
|
}
|
|
123
206
|
};
|
|
124
207
|
export {
|
|
125
|
-
Client
|
|
208
|
+
Client,
|
|
209
|
+
KeyboardBuilder
|
|
126
210
|
};
|