@effect-ak/tg-bot-client 0.0.2
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/cjs/client/const.js +19 -0
- package/dist/cjs/client/factory.js +29 -0
- package/dist/cjs/client/request.js +32 -0
- package/dist/cjs/client/response.js +10 -0
- package/dist/cjs/index.js +49 -0
- package/dist/cjs/specification/api.js +5 -0
- package/dist/cjs/specification/types.js +5 -0
- package/dist/dts/client/const.d.ts +11 -0
- package/dist/dts/client/factory.d.ts +9 -0
- package/dist/dts/client/request.d.ts +2 -0
- package/dist/dts/client/response.d.ts +7 -0
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/specification/api.d.ts +3021 -0
- package/dist/dts/specification/types.d.ts +3823 -0
- package/dist/esm/client/const.js +12 -0
- package/dist/esm/client/factory.js +23 -0
- package/dist/esm/client/request.js +33 -0
- package/dist/esm/client/response.js +6 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/specification/api.js +1 -0
- package/dist/esm/specification/types.js +1 -0
- package/package.json +46 -0
- package/readme.md +74 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.messageEffectIdCodes = exports.isMessageEffect = exports.MESSAGE_EFFECTS = void 0;
|
|
7
|
+
const MESSAGE_EFFECTS = exports.MESSAGE_EFFECTS = {
|
|
8
|
+
"🔥": "5104841245755180586",
|
|
9
|
+
"👍": "5107584321108051014",
|
|
10
|
+
"👎": "5104858069142078462",
|
|
11
|
+
"❤️": "5159385139981059251",
|
|
12
|
+
"🎉": "5046509860389126442",
|
|
13
|
+
"💩": "5046589136895476101"
|
|
14
|
+
};
|
|
15
|
+
const messageEffectIdCodes = exports.messageEffectIdCodes = Object.keys(MESSAGE_EFFECTS);
|
|
16
|
+
const isMessageEffect = input => {
|
|
17
|
+
return typeof input === "string" && input in MESSAGE_EFFECTS;
|
|
18
|
+
};
|
|
19
|
+
exports.isMessageEffect = isMessageEffect;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.makeTgBotClient = void 0;
|
|
7
|
+
var _request = require("./request.js");
|
|
8
|
+
var _response = require("./response.js");
|
|
9
|
+
const defaultBaseUrl = "https://api.telegram.org";
|
|
10
|
+
const makeTgBotClient = options => {
|
|
11
|
+
const baseUrl = options.baseUrl ?? defaultBaseUrl;
|
|
12
|
+
const execute = async (method, input) => {
|
|
13
|
+
const httpResponse = await fetch(`${baseUrl}/bot${options.token}/${(0, _request.methodPath)(method)}`, {
|
|
14
|
+
body: (0, _request.makePayload)(input) ?? null,
|
|
15
|
+
method: "POST"
|
|
16
|
+
}).then(_ => _.json());
|
|
17
|
+
if (!(0, _response.isTgBotApiResponse)(httpResponse)) throw new Error("Not valid response", {
|
|
18
|
+
cause: httpResponse
|
|
19
|
+
});
|
|
20
|
+
if (httpResponse.ok == false) {
|
|
21
|
+
console.warn(httpResponse);
|
|
22
|
+
}
|
|
23
|
+
return httpResponse;
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
execute
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.makeTgBotClient = makeTgBotClient;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.methodPath = exports.makePayload = void 0;
|
|
7
|
+
const methodPath = methodName => methodName.split("_").reduce((result, word, step) => {
|
|
8
|
+
if (step == 0) {
|
|
9
|
+
return word;
|
|
10
|
+
} else {
|
|
11
|
+
return result + word.at(0)?.toUpperCase() + word.slice(1);
|
|
12
|
+
}
|
|
13
|
+
}, "");
|
|
14
|
+
exports.methodPath = methodPath;
|
|
15
|
+
const hasFileContent = input => typeof input == "object" && input != null && "file_content" in input && input.file_content instanceof Uint8Array && "file_name" in input && typeof input.file_name === "string" && input.file_name.length > 0;
|
|
16
|
+
const makePayload = body => {
|
|
17
|
+
const entries = Object.entries(body);
|
|
18
|
+
if (entries.length == 0) return undefined;
|
|
19
|
+
const result = new FormData();
|
|
20
|
+
for (const [key, value] of entries) {
|
|
21
|
+
if (!value) continue;
|
|
22
|
+
if (typeof value != "object") {
|
|
23
|
+
result.append(key, `${value}`);
|
|
24
|
+
} else if (hasFileContent(value)) {
|
|
25
|
+
result.append(key, new Blob([value.file_content]), value.file_name);
|
|
26
|
+
} else {
|
|
27
|
+
result.append(key, JSON.stringify(value));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
exports.makePayload = makePayload;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isTgBotApiResponse = void 0;
|
|
7
|
+
const isTgBotApiResponse = input => {
|
|
8
|
+
return "ok" in input && typeof input.ok == "boolean" && (typeof input.error_code === 'undefined' || typeof input.error_code === 'number') && (typeof input.description === 'undefined' || typeof input.description === 'string') && (typeof input.result === 'undefined' || typeof input.result === 'object');
|
|
9
|
+
};
|
|
10
|
+
exports.isTgBotApiResponse = isTgBotApiResponse;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _const = require("./client/const.js");
|
|
7
|
+
Object.keys(_const).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _const[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _const[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _factory = require("./client/factory.js");
|
|
18
|
+
Object.keys(_factory).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _factory[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _factory[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _api = require("./specification/api.js");
|
|
29
|
+
Object.keys(_api).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _api[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _api[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _types = require("./specification/types.js");
|
|
40
|
+
Object.keys(_types).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _types[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const MESSAGE_EFFECTS: {
|
|
2
|
+
readonly "\uD83D\uDD25": "5104841245755180586";
|
|
3
|
+
readonly "\uD83D\uDC4D": "5107584321108051014";
|
|
4
|
+
readonly "\uD83D\uDC4E": "5104858069142078462";
|
|
5
|
+
readonly "\u2764\uFE0F": "5159385139981059251";
|
|
6
|
+
readonly "\uD83C\uDF89": "5046509860389126442";
|
|
7
|
+
readonly "\uD83D\uDCA9": "5046589136895476101";
|
|
8
|
+
};
|
|
9
|
+
export type MessageEffect = keyof typeof MESSAGE_EFFECTS;
|
|
10
|
+
export declare const messageEffectIdCodes: MessageEffect[];
|
|
11
|
+
export declare const isMessageEffect: (input: unknown) => input is MessageEffect;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Api } from "../specification/api.js";
|
|
2
|
+
import { TgBotApiResponse } from "./response.js";
|
|
3
|
+
export type TgBotClient = ReturnType<typeof makeTgBotClient>;
|
|
4
|
+
export declare const makeTgBotClient: (options: {
|
|
5
|
+
token: string;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
}) => {
|
|
8
|
+
readonly execute: <M extends keyof Api>(method: M, input: Parameters<Api[M]>[0]) => Promise<TgBotApiResponse<ReturnType<Api[M]>>>;
|
|
9
|
+
};
|