@effect-ak/tg-bot-client 0.1.0 → 0.2.1
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/bot/factory/_service.js +59 -0
- package/dist/cjs/bot/factory/client-config.js +68 -0
- package/dist/cjs/bot/factory/make-bot.js +59 -0
- package/dist/cjs/bot/message-handler/_service.js +51 -0
- package/dist/cjs/bot/message-handler/types.js +5 -0
- package/dist/cjs/bot/message-handler/utils.js +19 -0
- package/dist/cjs/bot/run.js +10 -0
- package/dist/cjs/bot/update-poller/_service.js +78 -0
- package/dist/cjs/bot/update-poller/errors.js +5 -0
- package/dist/cjs/bot/update-poller/fetch-updates.js +109 -0
- package/dist/cjs/bot/update-poller/poll-and-handle.js +89 -0
- package/dist/cjs/bot/update-poller/settings.js +23 -0
- package/dist/cjs/client/_client.js +56 -14
- package/dist/cjs/client/config.js +56 -0
- package/dist/cjs/client/errors.js +47 -9
- package/dist/cjs/client/execute-request/_service.js +59 -0
- package/dist/cjs/client/execute-request/execute.js +98 -0
- package/dist/cjs/client/{request.js → execute-request/payload.js} +2 -2
- package/dist/cjs/client/file/_service.js +61 -0
- package/dist/cjs/client/file/get-file.js +77 -0
- package/dist/cjs/client/guards.js +12 -0
- package/dist/cjs/const.js +20 -0
- package/dist/cjs/index.js +24 -22
- package/dist/dts/bot/factory/_service.d.ts +37 -0
- package/dist/dts/bot/factory/client-config.d.ts +3 -0
- package/dist/dts/bot/factory/make-bot.d.ts +7 -0
- package/dist/dts/bot/message-handler/_service.d.ts +6 -0
- package/dist/dts/bot/message-handler/types.d.ts +16 -0
- package/dist/dts/bot/message-handler/utils.d.ts +6 -0
- package/dist/dts/bot/run.d.ts +7 -0
- package/dist/dts/bot/update-poller/_service.d.ts +21 -0
- package/dist/dts/bot/update-poller/errors.d.ts +1 -0
- package/dist/dts/bot/update-poller/fetch-updates.d.ts +17 -0
- package/dist/dts/bot/update-poller/poll-and-handle.d.ts +16 -0
- package/dist/dts/bot/update-poller/settings.d.ts +6 -0
- package/dist/dts/client/_client.d.ts +6 -17
- package/dist/dts/client/config.d.ts +8 -0
- package/dist/dts/client/errors.d.ts +6 -4
- package/dist/dts/client/execute-request/_service.d.ts +15 -0
- package/dist/dts/client/execute-request/execute.d.ts +5 -0
- package/dist/dts/client/file/_service.d.ts +16 -0
- package/dist/dts/client/file/get-file.d.ts +5 -0
- package/dist/dts/client/guards.d.ts +17 -0
- package/dist/dts/index.d.ts +4 -1
- package/dist/dts/specification/api.d.ts +14 -14
- package/dist/dts/specification/types.d.ts +77 -77
- package/dist/esm/bot/factory/_service.js +49 -0
- package/dist/esm/bot/factory/client-config.js +57 -0
- package/dist/esm/bot/factory/make-bot.js +46 -0
- package/dist/esm/bot/message-handler/_service.js +41 -0
- package/dist/esm/bot/message-handler/types.js +2 -0
- package/dist/esm/bot/message-handler/utils.js +16 -0
- package/dist/esm/bot/run.js +10 -0
- package/dist/esm/bot/update-poller/_service.js +68 -0
- package/dist/esm/bot/update-poller/errors.js +2 -0
- package/dist/esm/bot/update-poller/fetch-updates.js +86 -0
- package/dist/esm/bot/update-poller/poll-and-handle.js +74 -0
- package/dist/esm/bot/update-poller/settings.js +19 -0
- package/dist/esm/client/_client.js +50 -12
- package/dist/esm/client/config.js +46 -0
- package/dist/esm/client/errors.js +42 -8
- package/dist/esm/client/execute-request/_service.js +49 -0
- package/dist/esm/client/execute-request/execute.js +74 -0
- package/dist/esm/client/{request.js → execute-request/payload.js} +7 -5
- package/dist/esm/client/file/_service.js +51 -0
- package/dist/esm/client/file/get-file.js +61 -0
- package/dist/esm/client/guards.js +13 -0
- package/dist/esm/const.js +17 -0
- package/dist/esm/index.js +21 -4
- package/dist/esm/specification/api.js +2 -1
- package/dist/esm/specification/types.js +2 -1
- package/package.json +13 -9
- package/readme.md +75 -25
- package/dist/cjs/client/const.js +0 -20
- package/dist/cjs/client/download-file.js +0 -44
- package/dist/cjs/client/execute-request.js +0 -69
- package/dist/cjs/client/response.js +0 -22
- package/dist/dts/client/download-file.d.ts +0 -13
- package/dist/dts/client/execute-request.d.ts +0 -13
- package/dist/dts/client/response.d.ts +0 -7
- package/dist/esm/client/const.js +0 -13
- package/dist/esm/client/download-file.js +0 -36
- package/dist/esm/client/execute-request.js +0 -62
- package/dist/esm/client/response.js +0 -15
- /package/dist/dts/client/{request.d.ts → execute-request/payload.d.ts} +0 -0
- /package/dist/dts/{client/const.d.ts → const.d.ts} +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
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.TgBotClientConfig = exports.makeTgBotClientConfig = void 0;
|
|
48
|
+
const Context = __importStar(require("effect/Context"));
|
|
49
|
+
const const_js_1 = require("../const.js");
|
|
50
|
+
const makeTgBotClientConfig = input => TgBotClientConfig.of({
|
|
51
|
+
...input,
|
|
52
|
+
["base-url"]: input["base-url"] ?? const_js_1.defaultBaseUrl
|
|
53
|
+
});
|
|
54
|
+
exports.makeTgBotClientConfig = makeTgBotClientConfig;
|
|
55
|
+
class TgBotClientConfig extends Context.Tag("TgBotClientConfig")() {}
|
|
56
|
+
exports.TgBotClientConfig = TgBotClientConfig;
|
|
@@ -1,19 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
|
+
}();
|
|
3
44
|
Object.defineProperty(exports, "__esModule", {
|
|
4
45
|
value: true
|
|
5
46
|
});
|
|
6
47
|
exports.TgBotClientError = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
_tag = "TgBotClientError";
|
|
10
|
-
constructor(reason) {
|
|
11
|
-
super();
|
|
12
|
-
this.reason = reason;
|
|
13
|
-
}
|
|
48
|
+
const Data = __importStar(require("effect/Data"));
|
|
49
|
+
class TgBotClientError extends Data.TaggedError("TgBotClientError") {
|
|
14
50
|
static missingSuccess = new TgBotClientError({
|
|
15
|
-
|
|
16
|
-
|
|
51
|
+
reason: {
|
|
52
|
+
type: "ClientInternalError",
|
|
53
|
+
cause: "Expected 'success' to be defined"
|
|
54
|
+
}
|
|
17
55
|
});
|
|
18
56
|
}
|
|
19
57
|
exports.TgBotClientError = TgBotClientError;
|
|
@@ -0,0 +1,59 @@
|
|
|
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.ClientExecuteRequestServiceDefault = exports.ClientExecuteRequestService = 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 execute_js_1 = require("./execute.js");
|
|
52
|
+
class ClientExecuteRequestService extends Context.Tag("ClientExecuteRequestService")() {}
|
|
53
|
+
exports.ClientExecuteRequestService = ClientExecuteRequestService;
|
|
54
|
+
exports.ClientExecuteRequestServiceDefault = Micro.gen(function* () {
|
|
55
|
+
const config = yield* Micro.service(config_js_1.TgBotClientConfig);
|
|
56
|
+
return {
|
|
57
|
+
execute: (method, input) => (0, execute_js_1.execute)(config, method, input)
|
|
58
|
+
};
|
|
59
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
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;
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.makePayload = void 0;
|
|
7
|
-
const
|
|
7
|
+
const guards_js_1 = require("../guards.js");
|
|
8
8
|
const makePayload = body => {
|
|
9
9
|
const entries = Object.entries(body);
|
|
10
10
|
if (entries.length == 0) return undefined;
|
|
@@ -13,7 +13,7 @@ const makePayload = body => {
|
|
|
13
13
|
if (!value) continue;
|
|
14
14
|
if (typeof value != "object") {
|
|
15
15
|
result.append(key, `${value}`);
|
|
16
|
-
} else if (
|
|
16
|
+
} else if ((0, guards_js_1.isFileContent)(value)) {
|
|
17
17
|
result.append(key, new Blob([value.file_content]), value.file_name);
|
|
18
18
|
} else {
|
|
19
19
|
result.append(key, JSON.stringify(value));
|
|
@@ -0,0 +1,61 @@
|
|
|
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));
|
|
@@ -0,0 +1,77 @@
|
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
|
+
};
|
|
3
22
|
Object.defineProperty(exports, "__esModule", {
|
|
4
23
|
value: true
|
|
5
24
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _const[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _client = require("./client/_client.js");
|
|
18
|
-
Object.keys(_client).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _client[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _client[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
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);
|
|
@@ -0,0 +1,37 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,7 @@
|
|
|
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>;
|
|
@@ -0,0 +1,6 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
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>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
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 {};
|