@coffer-org/plugin-telegram 2.2.1 → 2.2.3
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/runtime/index.js +5 -0
- package/dist/schema.js +29 -11
- package/package.json +4 -4
package/dist/runtime/index.js
CHANGED
|
@@ -2,16 +2,21 @@ import { getPluginSettings } from '@coffer-org/server/plugin-runtime';
|
|
|
2
2
|
import { pruneThreadMessages } from '@coffer-org/server/thread-store';
|
|
3
3
|
import { startBot, stopBot } from "./bot.js";
|
|
4
4
|
import { getLogger } from '@coffer-org/sdk/logger';
|
|
5
|
+
import { registerConnector } from '@coffer-org/plugin-orchestrator/runtime';
|
|
5
6
|
const log = getLogger('telegram');
|
|
6
7
|
const THREAD_TTL_MS = Number(process.env['TELEGRAM_THREAD_TTL_MS'] ?? 7 * 86_400_000);
|
|
8
|
+
let unregisterConnector;
|
|
7
9
|
export { startBot, stopBot };
|
|
8
10
|
export { loadBotConfig, hasCredentials } from "./config.js";
|
|
9
11
|
export const serverHooks = {
|
|
10
12
|
init: async () => {
|
|
13
|
+
unregisterConnector = registerConnector({ id: 'telegram' });
|
|
11
14
|
const dbSettings = await getPluginSettings('telegram');
|
|
12
15
|
void startBot({ dbSettings }).catch((e) => log.warn(`failed to start: ${e.message}`));
|
|
13
16
|
},
|
|
14
17
|
teardown: async () => {
|
|
18
|
+
unregisterConnector?.();
|
|
19
|
+
unregisterConnector = undefined;
|
|
15
20
|
await stopBot();
|
|
16
21
|
},
|
|
17
22
|
backgroundTasks: [
|
package/dist/schema.js
CHANGED
|
@@ -6426,15 +6426,23 @@ function check(raw) {
|
|
|
6426
6426
|
const required = o.required ?? false;
|
|
6427
6427
|
const multiple = o.multiple ?? false;
|
|
6428
6428
|
const slots = o.slots && o.slots.length > 0 ? o.slots : [""];
|
|
6429
|
+
const contentFields = o.fields?.length ? o.fields : [string({
|
|
6430
|
+
key: "text",
|
|
6431
|
+
label: "core.fields.text"
|
|
6432
|
+
})];
|
|
6433
|
+
const contentKeys = /* @__PURE__ */ new Set();
|
|
6434
|
+
for (const f of contentFields) {
|
|
6435
|
+
if (contentKeys.has(f.key)) throw new Error(`[field.check] duplicate content field '${f.key}'`);
|
|
6436
|
+
if (/^check\d+$/.test(f.key)) throw new Error(`[field.check] content field '${f.key}' is reserved for checkbox slots`);
|
|
6437
|
+
if (!multiple && (f.type.virtual || f.type.columns)) throw new Error(`[field.check] single content field '${f.key}' must be a scalar stored field`);
|
|
6438
|
+
contentKeys.add(f.key);
|
|
6439
|
+
}
|
|
6440
|
+
const checkFields = slots.map((label, i) => boolean({
|
|
6441
|
+
key: `check${i}`,
|
|
6442
|
+
label: label || "core.fields.check"
|
|
6443
|
+
}));
|
|
6429
6444
|
if (multiple) {
|
|
6430
|
-
const fields =
|
|
6431
|
-
key: `check${i}`,
|
|
6432
|
-
label: label || "core.fields.check"
|
|
6433
|
-
}));
|
|
6434
|
-
fields.push(string({
|
|
6435
|
-
key: "text",
|
|
6436
|
-
label: "core.fields.text"
|
|
6437
|
-
}));
|
|
6445
|
+
const fields = [...checkFields, ...contentFields];
|
|
6438
6446
|
return group({
|
|
6439
6447
|
key: o.key,
|
|
6440
6448
|
label: o.label ?? o.key,
|
|
@@ -6444,8 +6452,12 @@ function check(raw) {
|
|
|
6444
6452
|
view: { kind: "checklist" }
|
|
6445
6453
|
});
|
|
6446
6454
|
}
|
|
6447
|
-
const shape = {
|
|
6448
|
-
const columns = {
|
|
6455
|
+
const shape = {};
|
|
6456
|
+
const columns = {};
|
|
6457
|
+
for (const f of contentFields) {
|
|
6458
|
+
shape[f.key] = f.type.zod;
|
|
6459
|
+
columns[f.key] = f.type.column;
|
|
6460
|
+
}
|
|
6449
6461
|
slots.forEach((_, i) => {
|
|
6450
6462
|
shape[`check${i}`] = boolean$1();
|
|
6451
6463
|
columns[`check${i}`] = "boolean";
|
|
@@ -6471,7 +6483,13 @@ function check(raw) {
|
|
|
6471
6483
|
required,
|
|
6472
6484
|
prim: "check",
|
|
6473
6485
|
column: "text",
|
|
6474
|
-
hints: {
|
|
6486
|
+
hints: {
|
|
6487
|
+
slots,
|
|
6488
|
+
fields: contentFields.map((f) => ({
|
|
6489
|
+
key: f.key,
|
|
6490
|
+
...toClient(f.type)
|
|
6491
|
+
}))
|
|
6492
|
+
},
|
|
6475
6493
|
columns,
|
|
6476
6494
|
zod: optionalize(s, required)
|
|
6477
6495
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffer-org/plugin-telegram",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"test": "node --import tsx --test \"src/runtime/*.test.ts\""
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@coffer-org/plugin-orchestrator": "^2.
|
|
29
|
-
"@coffer-org/sdk": "^2.1.
|
|
30
|
-
"@coffer-org/server": "^2.
|
|
28
|
+
"@coffer-org/plugin-orchestrator": "^2.3.3",
|
|
29
|
+
"@coffer-org/sdk": "^2.1.3",
|
|
30
|
+
"@coffer-org/server": "^2.5.2",
|
|
31
31
|
"input": "^1.0.1",
|
|
32
32
|
"teleproto": "^1.228.1"
|
|
33
33
|
},
|