@effect-ak/tg-bot-client 0.2.1 → 0.2.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/index.d.ts +2821 -0
- package/dist/index.js +462 -0
- package/dist/index.mjs +418 -0
- package/package.json +15 -15
- package/readme.md +1 -1
- package/dist/cjs/bot/factory/_service.js +0 -59
- package/dist/cjs/bot/factory/client-config.js +0 -68
- package/dist/cjs/bot/factory/make-bot.js +0 -59
- package/dist/cjs/bot/message-handler/_service.js +0 -51
- package/dist/cjs/bot/message-handler/types.js +0 -5
- package/dist/cjs/bot/message-handler/utils.js +0 -19
- package/dist/cjs/bot/run.js +0 -10
- package/dist/cjs/bot/update-poller/_service.js +0 -78
- package/dist/cjs/bot/update-poller/errors.js +0 -5
- package/dist/cjs/bot/update-poller/fetch-updates.js +0 -109
- package/dist/cjs/bot/update-poller/poll-and-handle.js +0 -89
- package/dist/cjs/bot/update-poller/settings.js +0 -23
- package/dist/cjs/client/_client.js +0 -64
- package/dist/cjs/client/config.js +0 -56
- package/dist/cjs/client/errors.js +0 -57
- package/dist/cjs/client/execute-request/_service.js +0 -59
- package/dist/cjs/client/execute-request/execute.js +0 -98
- package/dist/cjs/client/execute-request/payload.js +0 -24
- package/dist/cjs/client/file/_service.js +0 -61
- package/dist/cjs/client/file/get-file.js +0 -77
- package/dist/cjs/client/guards.js +0 -12
- package/dist/cjs/const.js +0 -20
- package/dist/cjs/index.js +0 -29
- package/dist/cjs/specification/api.js +0 -5
- package/dist/cjs/specification/types.js +0 -5
- package/dist/dts/bot/factory/_service.d.ts +0 -37
- package/dist/dts/bot/factory/client-config.d.ts +0 -3
- package/dist/dts/bot/factory/make-bot.d.ts +0 -7
- package/dist/dts/bot/message-handler/_service.d.ts +0 -6
- package/dist/dts/bot/message-handler/types.d.ts +0 -16
- package/dist/dts/bot/message-handler/utils.d.ts +0 -6
- package/dist/dts/bot/run.d.ts +0 -7
- package/dist/dts/bot/update-poller/_service.d.ts +0 -21
- package/dist/dts/bot/update-poller/errors.d.ts +0 -1
- package/dist/dts/bot/update-poller/fetch-updates.d.ts +0 -17
- package/dist/dts/bot/update-poller/poll-and-handle.d.ts +0 -16
- package/dist/dts/bot/update-poller/settings.d.ts +0 -6
- package/dist/dts/client/_client.d.ts +0 -8
- package/dist/dts/client/config.d.ts +0 -8
- package/dist/dts/client/errors.d.ts +0 -23
- package/dist/dts/client/execute-request/_service.d.ts +0 -15
- package/dist/dts/client/execute-request/execute.d.ts +0 -5
- package/dist/dts/client/execute-request/payload.d.ts +0 -1
- package/dist/dts/client/file/_service.d.ts +0 -16
- package/dist/dts/client/file/get-file.d.ts +0 -5
- package/dist/dts/client/guards.d.ts +0 -17
- package/dist/dts/const.d.ts +0 -12
- package/dist/dts/index.d.ts +0 -5
- package/dist/dts/specification/api.d.ts +0 -1030
- package/dist/dts/specification/types.d.ts +0 -1663
- package/dist/esm/bot/factory/_service.js +0 -49
- package/dist/esm/bot/factory/client-config.js +0 -57
- package/dist/esm/bot/factory/make-bot.js +0 -46
- package/dist/esm/bot/message-handler/_service.js +0 -41
- package/dist/esm/bot/message-handler/types.js +0 -2
- package/dist/esm/bot/message-handler/utils.js +0 -16
- package/dist/esm/bot/run.js +0 -10
- package/dist/esm/bot/update-poller/_service.js +0 -68
- package/dist/esm/bot/update-poller/errors.js +0 -2
- package/dist/esm/bot/update-poller/fetch-updates.js +0 -86
- package/dist/esm/bot/update-poller/poll-and-handle.js +0 -74
- package/dist/esm/bot/update-poller/settings.js +0 -19
- package/dist/esm/client/_client.js +0 -53
- package/dist/esm/client/config.js +0 -46
- package/dist/esm/client/errors.js +0 -46
- package/dist/esm/client/execute-request/_service.js +0 -49
- package/dist/esm/client/execute-request/execute.js +0 -74
- package/dist/esm/client/execute-request/payload.js +0 -25
- package/dist/esm/client/file/_service.js +0 -51
- package/dist/esm/client/file/get-file.js +0 -61
- package/dist/esm/client/guards.js +0 -13
- package/dist/esm/const.js +0 -17
- package/dist/esm/index.js +0 -21
- package/dist/esm/specification/api.js +0 -2
- package/dist/esm/specification/types.js +0 -2
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return m[k];
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
} : function (o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
});
|
|
19
|
-
var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
value: v
|
|
23
|
-
});
|
|
24
|
-
} : function (o, v) {
|
|
25
|
-
o["default"] = v;
|
|
26
|
-
});
|
|
27
|
-
var __importStar = void 0 && (void 0).__importStar || function () {
|
|
28
|
-
var ownKeys = function (o) {
|
|
29
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
-
var ar = [];
|
|
31
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
-
return ar;
|
|
33
|
-
};
|
|
34
|
-
return ownKeys(o);
|
|
35
|
-
};
|
|
36
|
-
return function (mod) {
|
|
37
|
-
if (mod && mod.__esModule) return mod;
|
|
38
|
-
var result = {};
|
|
39
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
-
__setModuleDefault(result, mod);
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
}();
|
|
44
|
-
Object.defineProperty(exports, "__esModule", {
|
|
45
|
-
value: true
|
|
46
|
-
});
|
|
47
|
-
exports.execute = void 0;
|
|
48
|
-
const Micro = __importStar(require("effect/Micro"));
|
|
49
|
-
const String = __importStar(require("effect/String"));
|
|
50
|
-
const errors_js_1 = require("../errors.js");
|
|
51
|
-
const payload_js_1 = require("./payload.js");
|
|
52
|
-
const guards_js_1 = require("../guards.js");
|
|
53
|
-
const execute = (config, method, input) => Micro.gen(function* () {
|
|
54
|
-
const httpResponse = yield* Micro.tryPromise({
|
|
55
|
-
try: () => fetch(`${config["base-url"]}/bot${config["bot-token"]}/${String.snakeToCamel(method)}`, {
|
|
56
|
-
body: (0, payload_js_1.makePayload)(input) ?? null,
|
|
57
|
-
method: "POST"
|
|
58
|
-
}),
|
|
59
|
-
catch: cause => new errors_js_1.TgBotClientError({
|
|
60
|
-
reason: {
|
|
61
|
-
type: "ClientInternalError",
|
|
62
|
-
cause
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
});
|
|
66
|
-
const response = yield* Micro.tryPromise({
|
|
67
|
-
try: () => httpResponse.json(),
|
|
68
|
-
catch: () => new errors_js_1.TgBotClientError({
|
|
69
|
-
reason: {
|
|
70
|
-
type: "UnexpectedResponse",
|
|
71
|
-
response: httpResponse
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
});
|
|
75
|
-
if (!(0, guards_js_1.isTgBotApiResponse)(response)) {
|
|
76
|
-
return yield* Micro.fail(new errors_js_1.TgBotClientError({
|
|
77
|
-
reason: {
|
|
78
|
-
type: "UnexpectedResponse",
|
|
79
|
-
response
|
|
80
|
-
}
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
if (!httpResponse.ok) {
|
|
84
|
-
return yield* Micro.fail(new errors_js_1.TgBotClientError({
|
|
85
|
-
reason: {
|
|
86
|
-
type: "NotOkResponse",
|
|
87
|
-
...(response.error_code ? {
|
|
88
|
-
errorCode: response.error_code
|
|
89
|
-
} : undefined),
|
|
90
|
-
...(response.description ? {
|
|
91
|
-
details: response.description
|
|
92
|
-
} : undefined)
|
|
93
|
-
}
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
return response.result;
|
|
97
|
-
});
|
|
98
|
-
exports.execute = execute;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.makePayload = void 0;
|
|
7
|
-
const guards_js_1 = require("../guards.js");
|
|
8
|
-
const makePayload = body => {
|
|
9
|
-
const entries = Object.entries(body);
|
|
10
|
-
if (entries.length == 0) return undefined;
|
|
11
|
-
const result = new FormData();
|
|
12
|
-
for (const [key, value] of entries) {
|
|
13
|
-
if (!value) continue;
|
|
14
|
-
if (typeof value != "object") {
|
|
15
|
-
result.append(key, `${value}`);
|
|
16
|
-
} else if ((0, guards_js_1.isFileContent)(value)) {
|
|
17
|
-
result.append(key, new Blob([value.file_content]), value.file_name);
|
|
18
|
-
} else {
|
|
19
|
-
result.append(key, JSON.stringify(value));
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
exports.makePayload = makePayload;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return m[k];
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
} : function (o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
});
|
|
19
|
-
var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
value: v
|
|
23
|
-
});
|
|
24
|
-
} : function (o, v) {
|
|
25
|
-
o["default"] = v;
|
|
26
|
-
});
|
|
27
|
-
var __importStar = void 0 && (void 0).__importStar || function () {
|
|
28
|
-
var ownKeys = function (o) {
|
|
29
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
-
var ar = [];
|
|
31
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
-
return ar;
|
|
33
|
-
};
|
|
34
|
-
return ownKeys(o);
|
|
35
|
-
};
|
|
36
|
-
return function (mod) {
|
|
37
|
-
if (mod && mod.__esModule) return mod;
|
|
38
|
-
var result = {};
|
|
39
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
-
__setModuleDefault(result, mod);
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
}();
|
|
44
|
-
Object.defineProperty(exports, "__esModule", {
|
|
45
|
-
value: true
|
|
46
|
-
});
|
|
47
|
-
exports.ClientFileServiceDefault = exports.ClientFileService = void 0;
|
|
48
|
-
const Micro = __importStar(require("effect/Micro"));
|
|
49
|
-
const Context = __importStar(require("effect/Context"));
|
|
50
|
-
const config_js_1 = require("../config.js");
|
|
51
|
-
const _service_js_1 = require("../execute-request/_service.js");
|
|
52
|
-
const get_file_js_1 = require("./get-file.js");
|
|
53
|
-
class ClientFileService extends Context.Tag("ClientFileService")() {}
|
|
54
|
-
exports.ClientFileService = ClientFileService;
|
|
55
|
-
exports.ClientFileServiceDefault = Micro.gen(function* () {
|
|
56
|
-
const config = yield* Micro.service(config_js_1.TgBotClientConfig);
|
|
57
|
-
const execute = yield* Micro.service(_service_js_1.ClientExecuteRequestService);
|
|
58
|
-
return {
|
|
59
|
-
getFile: input => (0, get_file_js_1.getFile)(input.file_id, config, execute)
|
|
60
|
-
};
|
|
61
|
-
}).pipe(Micro.provideServiceEffect(_service_js_1.ClientExecuteRequestService, _service_js_1.ClientExecuteRequestServiceDefault));
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return m[k];
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
} : function (o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
});
|
|
19
|
-
var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
value: v
|
|
23
|
-
});
|
|
24
|
-
} : function (o, v) {
|
|
25
|
-
o["default"] = v;
|
|
26
|
-
});
|
|
27
|
-
var __importStar = void 0 && (void 0).__importStar || function () {
|
|
28
|
-
var ownKeys = function (o) {
|
|
29
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
-
var ar = [];
|
|
31
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
-
return ar;
|
|
33
|
-
};
|
|
34
|
-
return ownKeys(o);
|
|
35
|
-
};
|
|
36
|
-
return function (mod) {
|
|
37
|
-
if (mod && mod.__esModule) return mod;
|
|
38
|
-
var result = {};
|
|
39
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
-
__setModuleDefault(result, mod);
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
}();
|
|
44
|
-
Object.defineProperty(exports, "__esModule", {
|
|
45
|
-
value: true
|
|
46
|
-
});
|
|
47
|
-
exports.getFile = void 0;
|
|
48
|
-
const Micro = __importStar(require("effect/Micro"));
|
|
49
|
-
const errors_js_1 = require("../errors.js");
|
|
50
|
-
const getFile = (fileId, config, execute) => Micro.gen(function* () {
|
|
51
|
-
const response = yield* execute.execute("get_file", {
|
|
52
|
-
file_id: fileId
|
|
53
|
-
});
|
|
54
|
-
const file_path = response.file_path;
|
|
55
|
-
if (!file_path || file_path.length == 0) {
|
|
56
|
-
return yield* Micro.fail(new errors_js_1.TgBotClientError({
|
|
57
|
-
reason: {
|
|
58
|
-
type: "UnableToGetFile",
|
|
59
|
-
cause: "File path not defined"
|
|
60
|
-
}
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
const file_name = file_path.replaceAll("/", "-");
|
|
64
|
-
const url = `${config["base-url"]}/file/bot${config["bot-token"]}/${file_path}`;
|
|
65
|
-
const fileContent = yield* Micro.tryPromise({
|
|
66
|
-
try: () => fetch(url).then(_ => _.arrayBuffer()),
|
|
67
|
-
catch: cause => new errors_js_1.TgBotClientError({
|
|
68
|
-
reason: {
|
|
69
|
-
type: "UnableToGetFile",
|
|
70
|
-
cause
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
});
|
|
74
|
-
const file = new File([new Uint8Array(fileContent)], file_name);
|
|
75
|
-
return file;
|
|
76
|
-
});
|
|
77
|
-
exports.getFile = getFile;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isTgBotClientSettingsInput = exports.isTgBotApiResponse = exports.isFileContent = void 0;
|
|
7
|
-
const isFileContent = input => typeof input == "object" && input != null && "file_content" in input && input.file_content instanceof Uint8Array && "file_name" in input && typeof input.file_name == "string";
|
|
8
|
-
exports.isFileContent = isFileContent;
|
|
9
|
-
const isTgBotApiResponse = input => typeof input == "object" && input != null && "ok" in input && typeof input.ok == "boolean";
|
|
10
|
-
exports.isTgBotApiResponse = isTgBotApiResponse;
|
|
11
|
-
const isTgBotClientSettingsInput = input => typeof input == "object" && input != null && "bot-token" in input && typeof input["bot-token"] == "string";
|
|
12
|
-
exports.isTgBotClientSettingsInput = isTgBotClientSettingsInput;
|
package/dist/cjs/const.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isMessageEffect = exports.messageEffectIdCodes = exports.MESSAGE_EFFECTS = exports.defaultBaseUrl = void 0;
|
|
7
|
-
exports.defaultBaseUrl = "https://api.telegram.org";
|
|
8
|
-
exports.MESSAGE_EFFECTS = {
|
|
9
|
-
"🔥": "5104841245755180586",
|
|
10
|
-
"👍": "5107584321108051014",
|
|
11
|
-
"👎": "5104858069142078462",
|
|
12
|
-
"❤️": "5159385139981059251",
|
|
13
|
-
"🎉": "5046509860389126442",
|
|
14
|
-
"💩": "5046589136895476101"
|
|
15
|
-
};
|
|
16
|
-
exports.messageEffectIdCodes = Object.keys(exports.MESSAGE_EFFECTS);
|
|
17
|
-
const isMessageEffect = input => {
|
|
18
|
-
return typeof input === "string" && input in exports.MESSAGE_EFFECTS;
|
|
19
|
-
};
|
|
20
|
-
exports.isMessageEffect = isMessageEffect;
|
package/dist/cjs/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return m[k];
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
} : function (o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
});
|
|
19
|
-
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
});
|
|
25
|
-
__exportStar(require("./client/_client.js"), exports);
|
|
26
|
-
__exportStar(require("./bot/run.js"), exports);
|
|
27
|
-
__exportStar(require("./specification/api.js"), exports);
|
|
28
|
-
__exportStar(require("./specification/types.js"), exports);
|
|
29
|
-
__exportStar(require("./const.js"), exports);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as Micro from "effect/Micro";
|
|
2
|
-
import * as Context from "effect/Context";
|
|
3
|
-
import type { TgBotClientSettingsInput } from "../../client/guards.js";
|
|
4
|
-
import type { BotMessageHandlerSettings } from "../../bot/message-handler/types.js";
|
|
5
|
-
import { TgBotClientConfig } from "../../client/config.js";
|
|
6
|
-
declare const BotFactoryService_base: Context.TagClass<BotFactoryService, "BotFactoryService", {
|
|
7
|
-
makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<{
|
|
8
|
-
updates: import("../../index.js").Update[];
|
|
9
|
-
lastSuccessId: number | undefined;
|
|
10
|
-
hasError: boolean;
|
|
11
|
-
}, import("../../client/errors.js").TgBotClientError>, string, TgBotClientConfig>;
|
|
12
|
-
runBot: (input: RunBotInput) => Micro.Micro<Micro.MicroFiber<{
|
|
13
|
-
updates: import("../../index.js").Update[];
|
|
14
|
-
lastSuccessId: number | undefined;
|
|
15
|
-
hasError: boolean;
|
|
16
|
-
}, import("../../client/errors.js").TgBotClientError>, string, never>;
|
|
17
|
-
}>;
|
|
18
|
-
export declare class BotFactoryService extends BotFactoryService_base {
|
|
19
|
-
}
|
|
20
|
-
export type RunBotInput = ({
|
|
21
|
-
type: "fromJsonFile";
|
|
22
|
-
} | {
|
|
23
|
-
type: "config";
|
|
24
|
-
} & TgBotClientSettingsInput) & BotMessageHandlerSettings;
|
|
25
|
-
export declare const BotFactoryServiceDefault: {
|
|
26
|
-
makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<{
|
|
27
|
-
updates: import("../../index.js").Update[];
|
|
28
|
-
lastSuccessId: number | undefined;
|
|
29
|
-
hasError: boolean;
|
|
30
|
-
}, import("../../client/errors.js").TgBotClientError>, string, TgBotClientConfig>;
|
|
31
|
-
runBot: (input: RunBotInput) => Micro.Micro<Micro.MicroFiber<{
|
|
32
|
-
updates: import("../../index.js").Update[];
|
|
33
|
-
lastSuccessId: number | undefined;
|
|
34
|
-
hasError: boolean;
|
|
35
|
-
}, import("../../client/errors.js").TgBotClientError>, string, never>;
|
|
36
|
-
};
|
|
37
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as Micro from "effect/Micro";
|
|
2
|
-
import type { BotMessageHandlerSettings } from "../../bot/message-handler/types.js";
|
|
3
|
-
export declare const makeBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<{
|
|
4
|
-
updates: import("../..").Update[];
|
|
5
|
-
lastSuccessId: number | undefined;
|
|
6
|
-
hasError: boolean;
|
|
7
|
-
}, import("../../client/errors").TgBotClientError>, string, import("../../client/config").TgBotClientConfig>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as Context from "effect/Context";
|
|
2
|
-
import { BotMessageHandlerSettings } from "./types.js";
|
|
3
|
-
declare const BotMessageHandler_base: Context.TagClass<BotMessageHandler, "BotMessageHandler", BotMessageHandlerSettings>;
|
|
4
|
-
export declare class BotMessageHandler extends BotMessageHandler_base {
|
|
5
|
-
}
|
|
6
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Api } from "../../specification/api.js";
|
|
2
|
-
import type { Update } from "../../specification/types.js";
|
|
3
|
-
export type AvailableUpdateTypes = Exclude<keyof Update, 'update_id'>;
|
|
4
|
-
export type BotResponse = {
|
|
5
|
-
[K in keyof Api]: K extends `send_${infer R}` ? {
|
|
6
|
-
type: Lowercase<R>;
|
|
7
|
-
} & Omit<Parameters<Api[K]>[0], 'chat_id'> : never;
|
|
8
|
-
}[keyof Api];
|
|
9
|
-
export type BotMessageHandlers = {
|
|
10
|
-
[K in AvailableUpdateTypes as `on_${K}`]?: (update: NonNullable<Update[K]>) => BotResponse;
|
|
11
|
-
};
|
|
12
|
-
export type BotMessageHandlerSettings = {
|
|
13
|
-
readonly batch_size?: number;
|
|
14
|
-
readonly timeout?: number;
|
|
15
|
-
readonly max_empty_responses?: number;
|
|
16
|
-
} & BotMessageHandlers;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Update } from "../../specification/types.js";
|
|
2
|
-
import { AvailableUpdateTypes } from "./types.js";
|
|
3
|
-
export type ExtractedUpdate<K extends AvailableUpdateTypes> = {
|
|
4
|
-
type: K;
|
|
5
|
-
} & Update[K];
|
|
6
|
-
export declare const extractUpdate: <U extends AvailableUpdateTypes>(input: Update) => ExtractedUpdate<U> | undefined;
|
package/dist/dts/bot/run.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Micro } from "effect";
|
|
2
|
-
import { BotFactoryServiceDefault } from "./factory/_service.js";
|
|
3
|
-
export declare const runTgChatBot: (input: Parameters<typeof BotFactoryServiceDefault.runBot>[0]) => Promise<Micro.MicroFiber<{
|
|
4
|
-
updates: import("../index.js").Update[];
|
|
5
|
-
lastSuccessId: number | undefined;
|
|
6
|
-
hasError: boolean;
|
|
7
|
-
}, import("../client/errors.js").TgBotClientError>>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as Micro from "effect/Micro";
|
|
2
|
-
import * as Context from "effect/Context";
|
|
3
|
-
import { BotMessageHandlerSettings } from "../../bot/message-handler/types.js";
|
|
4
|
-
export type BotUpdatePollerServiceInterface = Micro.Micro.Success<typeof BotUpdatesPollerServiceDefault>;
|
|
5
|
-
declare const BotUpdatePollerService_base: Context.TagClass<BotUpdatePollerService, "BotUpdatePollerService", {
|
|
6
|
-
readonly runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<{
|
|
7
|
-
updates: import("../../index.js").Update[];
|
|
8
|
-
lastSuccessId: number | undefined;
|
|
9
|
-
hasError: boolean;
|
|
10
|
-
}, import("../../client/errors.js").TgBotClientError>, string, never>;
|
|
11
|
-
}>;
|
|
12
|
-
export declare class BotUpdatePollerService extends BotUpdatePollerService_base {
|
|
13
|
-
}
|
|
14
|
-
export declare const BotUpdatesPollerServiceDefault: Micro.Micro<{
|
|
15
|
-
readonly runBot: (messageHandler: BotMessageHandlerSettings) => Micro.Micro<Micro.MicroFiber<{
|
|
16
|
-
updates: import("../../index.js").Update[];
|
|
17
|
-
lastSuccessId: number | undefined;
|
|
18
|
-
hasError: boolean;
|
|
19
|
-
}, import("../../client/errors.js").TgBotClientError>, string, never>;
|
|
20
|
-
}, never, import("../../client/config.js").TgBotClientConfig>;
|
|
21
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as Micro from "effect/Micro";
|
|
2
|
-
import type { State } from "./poll-and-handle.js";
|
|
3
|
-
import type { SafeSettings } from "./settings.js";
|
|
4
|
-
import type { BotMessageHandlers } from "../message-handler/types.js";
|
|
5
|
-
import type { ClientExecuteRequestServiceInterface } from "../../client/execute-request/_service.js";
|
|
6
|
-
type Context = {
|
|
7
|
-
state: State;
|
|
8
|
-
settings: SafeSettings;
|
|
9
|
-
handlers: BotMessageHandlers;
|
|
10
|
-
execute: ClientExecuteRequestServiceInterface["execute"];
|
|
11
|
-
};
|
|
12
|
-
export declare const fetchUpdates: ({ state, settings, execute, handlers }: Context) => Micro.Micro<{
|
|
13
|
-
updates: import("../../index.js").Update[];
|
|
14
|
-
lastSuccessId: number | undefined;
|
|
15
|
-
hasError: boolean;
|
|
16
|
-
}, import("../../client/errors.js").TgBotClientError, never>;
|
|
17
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as Micro from "effect/Micro";
|
|
2
|
-
import type { ClientExecuteRequestServiceInterface } from "../../client/execute-request/_service.js";
|
|
3
|
-
import type { BotMessageHandlerSettings } from "../../bot/message-handler/types.js";
|
|
4
|
-
export type State = {
|
|
5
|
-
lastUpdateId: number | undefined;
|
|
6
|
-
emptyResponses: number;
|
|
7
|
-
};
|
|
8
|
-
export type PollAndHandleInput = {
|
|
9
|
-
settings: BotMessageHandlerSettings;
|
|
10
|
-
execute: ClientExecuteRequestServiceInterface["execute"];
|
|
11
|
-
};
|
|
12
|
-
export declare const pollAndHandle: (input: PollAndHandleInput) => Micro.Micro<{
|
|
13
|
-
updates: import("../../index.js").Update[];
|
|
14
|
-
lastSuccessId: number | undefined;
|
|
15
|
-
hasError: boolean;
|
|
16
|
-
}, import("../../client/errors.js").TgBotClientError, never>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { BotMessageHandlerSettings } from "../../bot/message-handler/types.js";
|
|
2
|
-
export type SafeSettings = ReturnType<typeof makeSettingsFrom>;
|
|
3
|
-
export declare const makeSettingsFrom: (input: BotMessageHandlerSettings) => {
|
|
4
|
-
readonly limit: number;
|
|
5
|
-
readonly timeout: number;
|
|
6
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ClientFileServiceInterface } from "./file/_service.js";
|
|
2
|
-
import { Api } from "../specification/api.js";
|
|
3
|
-
import type { TgBotClientSettingsInput } from "./guards.js";
|
|
4
|
-
export type TgBotClient = ReturnType<typeof makeTgBotClient>;
|
|
5
|
-
export declare const makeTgBotClient: (input: TgBotClientSettingsInput) => {
|
|
6
|
-
execute: <M extends keyof Api>(method: M, input: Parameters<Api[M]>[0]) => Promise<ReturnType<Api[M]>>;
|
|
7
|
-
getFile: (input: Parameters<ClientFileServiceInterface["getFile"]>[0]) => Promise<File>;
|
|
8
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as Context from "effect/Context";
|
|
2
|
-
import { TgBotClientSettingsInput } from "./guards.js";
|
|
3
|
-
export type TgBotClientConfigObject = Required<TgBotClientSettingsInput>;
|
|
4
|
-
export declare const makeTgBotClientConfig: (input: TgBotClientSettingsInput) => Required<TgBotClientSettingsInput>;
|
|
5
|
-
declare const TgBotClientConfig_base: Context.TagClass<TgBotClientConfig, "TgBotClientConfig", Required<TgBotClientSettingsInput>>;
|
|
6
|
-
export declare class TgBotClientConfig extends TgBotClientConfig_base {
|
|
7
|
-
}
|
|
8
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
type ErrorReason = {
|
|
2
|
-
readonly type: "NotOkResponse";
|
|
3
|
-
readonly errorCode?: number;
|
|
4
|
-
readonly details?: string;
|
|
5
|
-
} | {
|
|
6
|
-
readonly type: "UnexpectedResponse";
|
|
7
|
-
readonly response: unknown;
|
|
8
|
-
} | {
|
|
9
|
-
readonly type: "ClientInternalError";
|
|
10
|
-
readonly cause: unknown;
|
|
11
|
-
} | {
|
|
12
|
-
readonly type: "UnableToGetFile";
|
|
13
|
-
readonly cause: unknown;
|
|
14
|
-
};
|
|
15
|
-
declare const TgBotClientError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
16
|
-
readonly _tag: "TgBotClientError";
|
|
17
|
-
} & Readonly<A>;
|
|
18
|
-
export declare class TgBotClientError extends TgBotClientError_base<{
|
|
19
|
-
reason: ErrorReason;
|
|
20
|
-
}> {
|
|
21
|
-
static readonly missingSuccess: TgBotClientError;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as Micro from "effect/Micro";
|
|
2
|
-
import * as Context from "effect/Context";
|
|
3
|
-
import type { Api } from "../../specification/api.js";
|
|
4
|
-
import { TgBotClientError } from "../errors.js";
|
|
5
|
-
import { TgBotClientConfig } from "../config.js";
|
|
6
|
-
export type ClientExecuteRequestServiceInterface = Micro.Micro.Success<typeof ClientExecuteRequestServiceDefault>;
|
|
7
|
-
declare const ClientExecuteRequestService_base: Context.TagClass<ClientExecuteRequestService, "ClientExecuteRequestService", {
|
|
8
|
-
execute: <M extends keyof Api>(method: M, input: Parameters<Api[M]>[0]) => Micro.Micro<ReturnType<Api[M]>, TgBotClientError>;
|
|
9
|
-
}>;
|
|
10
|
-
export declare class ClientExecuteRequestService extends ClientExecuteRequestService_base {
|
|
11
|
-
}
|
|
12
|
-
export declare const ClientExecuteRequestServiceDefault: Micro.Micro<{
|
|
13
|
-
readonly execute: <M extends keyof Api>(method: M, input: Parameters<Api[M]>[0]) => Micro.Micro<ReturnType<Api[M]>, TgBotClientError, never>;
|
|
14
|
-
}, never, TgBotClientConfig>;
|
|
15
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import * as Micro from "effect/Micro";
|
|
2
|
-
import type { Api } from "../../specification/api.js";
|
|
3
|
-
import { TgBotClientError } from "../errors.js";
|
|
4
|
-
import { TgBotClientConfigObject } from "../config.js";
|
|
5
|
-
export declare const execute: <M extends keyof Api>(config: TgBotClientConfigObject, method: M, input: Parameters<Api[M]>[0]) => Micro.Micro<ReturnType<Api[M]>, TgBotClientError>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const makePayload: (body: object) => FormData | undefined;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as Micro from "effect/Micro";
|
|
2
|
-
import * as Context from "effect/Context";
|
|
3
|
-
import { TgBotClientConfig } from "../config.js";
|
|
4
|
-
import { getFile } from "./get-file.js";
|
|
5
|
-
export type ClientFileServiceInterface = Context.Tag.Service<typeof ClientFileService>;
|
|
6
|
-
declare const ClientFileService_base: Context.TagClass<ClientFileService, "ClientFileService", {
|
|
7
|
-
getFile: (input: {
|
|
8
|
-
file_id: string;
|
|
9
|
-
}) => ReturnType<typeof getFile>;
|
|
10
|
-
}>;
|
|
11
|
-
export declare class ClientFileService extends ClientFileService_base {
|
|
12
|
-
}
|
|
13
|
-
export declare const ClientFileServiceDefault: Micro.Micro<{
|
|
14
|
-
readonly getFile: (input: Parameters<ClientFileServiceInterface["getFile"]>[0]) => Micro.Micro<File, import("../errors.js").TgBotClientError, never>;
|
|
15
|
-
}, never, TgBotClientConfig>;
|
|
16
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import * as Micro from "effect/Micro";
|
|
2
|
-
import { TgBotClientError } from "../errors.js";
|
|
3
|
-
import { TgBotClientConfigObject } from "../config.js";
|
|
4
|
-
import { ClientExecuteRequestServiceInterface } from "../execute-request/_service.js";
|
|
5
|
-
export declare const getFile: (fileId: string, config: TgBotClientConfigObject, execute: ClientExecuteRequestServiceInterface) => Micro.Micro<File, TgBotClientError>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type FileContent = {
|
|
2
|
-
file_content: Uint8Array;
|
|
3
|
-
file_name: string;
|
|
4
|
-
};
|
|
5
|
-
export declare const isFileContent: (input: unknown) => input is FileContent;
|
|
6
|
-
export type TgBotApiResponseSchema = {
|
|
7
|
-
ok: boolean;
|
|
8
|
-
error_code?: number;
|
|
9
|
-
description?: string;
|
|
10
|
-
result?: unknown;
|
|
11
|
-
};
|
|
12
|
-
export declare const isTgBotApiResponse: (input: unknown) => input is TgBotApiResponseSchema;
|
|
13
|
-
export type TgBotClientSettingsInput = {
|
|
14
|
-
["bot-token"]: string;
|
|
15
|
-
["base-url"]?: string;
|
|
16
|
-
};
|
|
17
|
-
export declare const isTgBotClientSettingsInput: (input: unknown) => input is TgBotClientSettingsInput;
|
package/dist/dts/const.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare const defaultBaseUrl = "https://api.telegram.org";
|
|
2
|
-
export declare const MESSAGE_EFFECTS: {
|
|
3
|
-
readonly "\uD83D\uDD25": "5104841245755180586";
|
|
4
|
-
readonly "\uD83D\uDC4D": "5107584321108051014";
|
|
5
|
-
readonly "\uD83D\uDC4E": "5104858069142078462";
|
|
6
|
-
readonly "\u2764\uFE0F": "5159385139981059251";
|
|
7
|
-
readonly "\uD83C\uDF89": "5046509860389126442";
|
|
8
|
-
readonly "\uD83D\uDCA9": "5046589136895476101";
|
|
9
|
-
};
|
|
10
|
-
export type MessageEffect = keyof typeof MESSAGE_EFFECTS;
|
|
11
|
-
export declare const messageEffectIdCodes: MessageEffect[];
|
|
12
|
-
export declare const isMessageEffect: (input: unknown) => input is MessageEffect;
|