@xtsea/tgcore-ts 0.1.6 → 0.1.7
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.js +9 -7
- package/dist/index.mjs +9 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -48,7 +48,8 @@ var KeyboardBuilder = class _KeyboardBuilder {
|
|
|
48
48
|
return this;
|
|
49
49
|
}
|
|
50
50
|
push(btn) {
|
|
51
|
-
|
|
51
|
+
var _a;
|
|
52
|
+
if (!((_a = btn.text) == null ? void 0 : _a.trim())) throw new Error("Button text is required");
|
|
52
53
|
if (btn.text.length > 64) throw new Error("Button text too long (max 64 chars)");
|
|
53
54
|
const actionKeys = [
|
|
54
55
|
"url",
|
|
@@ -86,7 +87,7 @@ var KeyboardBuilder = class _KeyboardBuilder {
|
|
|
86
87
|
return this.push({ text, web_app: { url } });
|
|
87
88
|
}
|
|
88
89
|
loginUrl(text, url, opts) {
|
|
89
|
-
return this.push({ text, login_url: { url, ...opts
|
|
90
|
+
return this.push({ text, login_url: { url, ...opts != null ? opts : {} } });
|
|
90
91
|
}
|
|
91
92
|
switchInline(text, query) {
|
|
92
93
|
return this.push({ text, switch_inline_query: query });
|
|
@@ -123,7 +124,7 @@ var Http = class {
|
|
|
123
124
|
"content-type": "application/json",
|
|
124
125
|
"x-api-key": this.opts.api_key
|
|
125
126
|
},
|
|
126
|
-
body: JSON.stringify(body
|
|
127
|
+
body: JSON.stringify(body != null ? body : {}),
|
|
127
128
|
signal: controller.signal
|
|
128
129
|
});
|
|
129
130
|
const json = await res.json().catch(() => null);
|
|
@@ -168,7 +169,7 @@ var BaseCallBuilder = class {
|
|
|
168
169
|
}
|
|
169
170
|
async throw() {
|
|
170
171
|
const res = await this.execute();
|
|
171
|
-
if (!res
|
|
172
|
+
if (!(res == null ? void 0 : res.ok)) {
|
|
172
173
|
throw new Error(JSON.stringify(res));
|
|
173
174
|
}
|
|
174
175
|
return res;
|
|
@@ -219,13 +220,14 @@ var CallMethods = class {
|
|
|
219
220
|
// src/client.ts
|
|
220
221
|
var Client = class {
|
|
221
222
|
constructor(opts) {
|
|
222
|
-
|
|
223
|
+
var _a, _b;
|
|
224
|
+
if (!(opts == null ? void 0 : opts.api_key)) {
|
|
223
225
|
throw new Error("tgcore-ts: api_key is required");
|
|
224
226
|
}
|
|
225
227
|
this.http = new Http({
|
|
226
228
|
api_key: opts.api_key,
|
|
227
|
-
base_url: opts.base_url
|
|
228
|
-
timeout_ms: opts.timeout_ms
|
|
229
|
+
base_url: (_a = opts.base_url) != null ? _a : "https://services-pro.ryzenths.dpdns.org",
|
|
230
|
+
timeout_ms: (_b = opts.timeout_ms) != null ? _b : 3e4
|
|
229
231
|
});
|
|
230
232
|
this.calls = new CallMethods(this.http);
|
|
231
233
|
this.raw = new RawMethods(this.http);
|
package/dist/index.mjs
CHANGED
|
@@ -21,7 +21,8 @@ var KeyboardBuilder = class _KeyboardBuilder {
|
|
|
21
21
|
return this;
|
|
22
22
|
}
|
|
23
23
|
push(btn) {
|
|
24
|
-
|
|
24
|
+
var _a;
|
|
25
|
+
if (!((_a = btn.text) == null ? void 0 : _a.trim())) throw new Error("Button text is required");
|
|
25
26
|
if (btn.text.length > 64) throw new Error("Button text too long (max 64 chars)");
|
|
26
27
|
const actionKeys = [
|
|
27
28
|
"url",
|
|
@@ -59,7 +60,7 @@ var KeyboardBuilder = class _KeyboardBuilder {
|
|
|
59
60
|
return this.push({ text, web_app: { url } });
|
|
60
61
|
}
|
|
61
62
|
loginUrl(text, url, opts) {
|
|
62
|
-
return this.push({ text, login_url: { url, ...opts
|
|
63
|
+
return this.push({ text, login_url: { url, ...opts != null ? opts : {} } });
|
|
63
64
|
}
|
|
64
65
|
switchInline(text, query) {
|
|
65
66
|
return this.push({ text, switch_inline_query: query });
|
|
@@ -96,7 +97,7 @@ var Http = class {
|
|
|
96
97
|
"content-type": "application/json",
|
|
97
98
|
"x-api-key": this.opts.api_key
|
|
98
99
|
},
|
|
99
|
-
body: JSON.stringify(body
|
|
100
|
+
body: JSON.stringify(body != null ? body : {}),
|
|
100
101
|
signal: controller.signal
|
|
101
102
|
});
|
|
102
103
|
const json = await res.json().catch(() => null);
|
|
@@ -141,7 +142,7 @@ var BaseCallBuilder = class {
|
|
|
141
142
|
}
|
|
142
143
|
async throw() {
|
|
143
144
|
const res = await this.execute();
|
|
144
|
-
if (!res
|
|
145
|
+
if (!(res == null ? void 0 : res.ok)) {
|
|
145
146
|
throw new Error(JSON.stringify(res));
|
|
146
147
|
}
|
|
147
148
|
return res;
|
|
@@ -192,13 +193,14 @@ var CallMethods = class {
|
|
|
192
193
|
// src/client.ts
|
|
193
194
|
var Client = class {
|
|
194
195
|
constructor(opts) {
|
|
195
|
-
|
|
196
|
+
var _a, _b;
|
|
197
|
+
if (!(opts == null ? void 0 : opts.api_key)) {
|
|
196
198
|
throw new Error("tgcore-ts: api_key is required");
|
|
197
199
|
}
|
|
198
200
|
this.http = new Http({
|
|
199
201
|
api_key: opts.api_key,
|
|
200
|
-
base_url: opts.base_url
|
|
201
|
-
timeout_ms: opts.timeout_ms
|
|
202
|
+
base_url: (_a = opts.base_url) != null ? _a : "https://services-pro.ryzenths.dpdns.org",
|
|
203
|
+
timeout_ms: (_b = opts.timeout_ms) != null ? _b : 3e4
|
|
202
204
|
});
|
|
203
205
|
this.calls = new CallMethods(this.http);
|
|
204
206
|
this.raw = new RawMethods(this.http);
|