@coffer-org/plugin-telegram 1.3.0 → 1.3.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/runtime/bot.js +4 -5
- package/dist/runtime/index.js +3 -1
- package/dist/schema.js +9 -106
- package/package.json +4 -4
package/dist/runtime/bot.js
CHANGED
|
@@ -6,11 +6,8 @@ import { StringSession } from 'telegram/sessions/index.js';
|
|
|
6
6
|
import { NewMessage } from 'telegram/events/index.js';
|
|
7
7
|
import { handleIncoming } from '@coffer-org/plugin-orchestrator/runtime';
|
|
8
8
|
import { loadBotConfig, hasCredentials } from "./config.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
warn: (m) => console.warn(`[telegram-bot] ${new Date().toISOString().slice(0, 19)} WARN ${m}`),
|
|
12
|
-
error: (m) => console.error(`[telegram-bot] ${new Date().toISOString().slice(0, 19)} ERROR ${m}`),
|
|
13
|
-
};
|
|
9
|
+
import { getLogger } from '@coffer-org/sdk/logger';
|
|
10
|
+
const log = getLogger('telegram');
|
|
14
11
|
function loadSessionString(file) {
|
|
15
12
|
try {
|
|
16
13
|
return fs.readFileSync(file, 'utf-8');
|
|
@@ -31,6 +28,8 @@ export async function startBot(opts = {}) {
|
|
|
31
28
|
log.warn('no credentials (api_id/api_hash + bot_token|phone) — not starting. Fill in the plugin settings or set the TELEGRAM_* env vars');
|
|
32
29
|
return false;
|
|
33
30
|
}
|
|
31
|
+
clearInterval(healthTimer);
|
|
32
|
+
healthTimer = undefined;
|
|
34
33
|
const sessionFile = path.join(cfg.stateDir, '.sessions', 'claude_bot.session');
|
|
35
34
|
const tg = new TelegramClient(new StringSession(loadSessionString(sessionFile)), cfg.apiId, cfg.apiHash, {
|
|
36
35
|
connectionRetries: Infinity,
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { getPluginSettings } from '@coffer-org/server/plugin-runtime';
|
|
2
2
|
import { startBot, stopBot } from "./bot.js";
|
|
3
|
+
import { getLogger } from '@coffer-org/sdk/logger';
|
|
4
|
+
const log = getLogger('telegram');
|
|
3
5
|
export { startBot, stopBot };
|
|
4
6
|
export { loadBotConfig, hasCredentials } from "./config.js";
|
|
5
7
|
export const serverHooks = {
|
|
6
8
|
init: async () => {
|
|
7
9
|
const dbSettings = await getPluginSettings('telegram');
|
|
8
|
-
void startBot({ dbSettings }).catch((e) =>
|
|
10
|
+
void startBot({ dbSettings }).catch((e) => log.warn(`failed to start: ${e.message}`));
|
|
9
11
|
},
|
|
10
12
|
teardown: async () => {
|
|
11
13
|
await stopBot();
|
package/dist/schema.js
CHANGED
|
@@ -21,14 +21,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
|
-
//#region ../sdk/
|
|
24
|
+
//#region ../sdk/dist/plugin.js
|
|
25
25
|
function definePlugin(p) {
|
|
26
26
|
if (!p.id) throw new Error("[plugin] missing id");
|
|
27
27
|
if (!p.version) console.warn(`[plugin] ${p.id}: missing version`);
|
|
28
28
|
return p;
|
|
29
29
|
}
|
|
30
30
|
//#endregion
|
|
31
|
-
//#region ../sdk/
|
|
31
|
+
//#region ../sdk/dist/settings.js
|
|
32
32
|
function defineSettings(s) {
|
|
33
33
|
return s;
|
|
34
34
|
}
|
|
@@ -4078,7 +4078,7 @@ function number(params) {
|
|
|
4078
4078
|
return /* @__PURE__ */ _coercedNumber(ZodNumber, params);
|
|
4079
4079
|
}
|
|
4080
4080
|
//#endregion
|
|
4081
|
-
//#region ../sdk/
|
|
4081
|
+
//#region ../sdk/dist/units.js
|
|
4082
4082
|
var UNITS_CURRENCY = [
|
|
4083
4083
|
{
|
|
4084
4084
|
value: "UAH",
|
|
@@ -4386,13 +4386,7 @@ function resolveUnits(u) {
|
|
|
4386
4386
|
return typeof u === "string" ? UNITS_MAP[u] : u;
|
|
4387
4387
|
}
|
|
4388
4388
|
//#endregion
|
|
4389
|
-
//#region ../sdk/
|
|
4390
|
-
/**
|
|
4391
|
-
* Валюти з вбудованого `Intl` (ISO 4217) — БЕЗ hand-list і без npm-залежності.
|
|
4392
|
-
* Коди — `Intl.supportedValuesOf('currency')`; символи/назви локалізовані через
|
|
4393
|
-
* `Intl.NumberFormat`/`Intl.DisplayNames`.
|
|
4394
|
-
*/
|
|
4395
|
-
/** Усі ISO 4217 коди. Fallback — кілька основних (на випадок старого рантайму). */
|
|
4389
|
+
//#region ../sdk/dist/currencies.js
|
|
4396
4390
|
var CURRENCY_CODES = (() => {
|
|
4397
4391
|
try {
|
|
4398
4392
|
return Intl.supportedValuesOf("currency");
|
|
@@ -4407,34 +4401,24 @@ var CURRENCY_CODES = (() => {
|
|
|
4407
4401
|
}
|
|
4408
4402
|
})();
|
|
4409
4403
|
var CODE_SET = new Set(CURRENCY_CODES);
|
|
4410
|
-
/** Чи валідний ISO 4217 код. */
|
|
4411
4404
|
var isCurrencyCode = (c) => CODE_SET.has(c);
|
|
4412
4405
|
//#endregion
|
|
4413
|
-
//#region ../sdk/
|
|
4414
|
-
/** Структуроване повідомлення для zod: JSON {code, params}. Декодує mutate.ts. */
|
|
4406
|
+
//#region ../sdk/dist/fields/validation.js
|
|
4415
4407
|
function vmsg(code, params) {
|
|
4416
4408
|
return JSON.stringify(params ? {
|
|
4417
4409
|
code,
|
|
4418
4410
|
params
|
|
4419
4411
|
} : { code });
|
|
4420
4412
|
}
|
|
4421
|
-
/** v4 error-map: повідомлення для відсутнього значення (колишній required_error). */
|
|
4422
4413
|
function reqErr(code = "required") {
|
|
4423
4414
|
return { error: (iss) => iss.input === void 0 ? vmsg(code) : void 0 };
|
|
4424
4415
|
}
|
|
4425
|
-
/** v4 error-map: повідомлення для невалідного типу (колишній invalid_type_error). */
|
|
4426
4416
|
function typeErr(code = "invalid_type") {
|
|
4427
4417
|
return { error: (iss) => iss.code === "invalid_type" ? vmsg(code) : void 0 };
|
|
4428
4418
|
}
|
|
4429
|
-
/** v4 error-map: required + invalid_type разом (колишні required_error + invalid_type_error). */
|
|
4430
4419
|
function reqTypeErr() {
|
|
4431
4420
|
return { error: (iss) => iss.code === "invalid_type" ? iss.input === void 0 ? vmsg("required") : vmsg("invalid_type") : void 0 };
|
|
4432
4421
|
}
|
|
4433
|
-
/** Parse a JSON string, else return the native value (object/array) as-is.
|
|
4434
|
-
* Tolerant input for native form-state AND legacy JSON-string payloads.
|
|
4435
|
-
* A string that fails JSON.parse is returned unchanged — callers detect
|
|
4436
|
-
* parse failure via `typeof result === 'string'` (inners here are object/array,
|
|
4437
|
-
* never a bare string). */
|
|
4438
4422
|
function jsonValue(raw) {
|
|
4439
4423
|
if (typeof raw === "string") try {
|
|
4440
4424
|
return JSON.parse(raw);
|
|
@@ -4443,12 +4427,6 @@ function jsonValue(raw) {
|
|
|
4443
4427
|
}
|
|
4444
4428
|
return raw;
|
|
4445
4429
|
}
|
|
4446
|
-
/**
|
|
4447
|
-
* Фабрика для полів, що зберігають JSON і валідуються вкладеною zod-схемою.
|
|
4448
|
-
* Приймає нативне object/array (native form-state) АБО JSON-рядок (legacy).
|
|
4449
|
-
* Single-parse через jsonValue → inner.safeParse → issue `code`; рядок, що не
|
|
4450
|
-
* розпарсився, лишається рядком → код 'json'.
|
|
4451
|
-
*/
|
|
4452
4430
|
function jsonRefined(inner, code) {
|
|
4453
4431
|
return unknown().superRefine((raw, ctx) => {
|
|
4454
4432
|
const parsed = jsonValue(raw);
|
|
@@ -4477,7 +4455,7 @@ function optionalize(schema, required) {
|
|
|
4477
4455
|
}).pipe(schema));
|
|
4478
4456
|
}
|
|
4479
4457
|
//#endregion
|
|
4480
|
-
//#region ../sdk/
|
|
4458
|
+
//#region ../sdk/dist/fields/normalize.js
|
|
4481
4459
|
function normalizeOpts(rawIn) {
|
|
4482
4460
|
const raw = rawIn;
|
|
4483
4461
|
const r = raw.rules ?? {};
|
|
@@ -4517,19 +4495,7 @@ function normalizeOpts(rawIn) {
|
|
|
4517
4495
|
return Object.fromEntries(Object.entries(result).filter(([, v]) => v !== void 0));
|
|
4518
4496
|
}
|
|
4519
4497
|
//#endregion
|
|
4520
|
-
//#region ../sdk/
|
|
4521
|
-
/**
|
|
4522
|
-
* Пресети полів — тонкі обгортки над базовими примітивами з fields.ts.
|
|
4523
|
-
*
|
|
4524
|
-
* Кожен пресет = один kind (один віджет). Пресети не приймають `format` —
|
|
4525
|
-
* вони самі є семантичними типами. min/max/step — через `config`.
|
|
4526
|
-
*
|
|
4527
|
-
* Пресети додаються до `f` через `composeF`, який гарантує, що жоден пресет
|
|
4528
|
-
* не перебиває примітив.
|
|
4529
|
-
*
|
|
4530
|
-
* Циклічний імпорт з fields.ts безпечний: фабрики/хелпери — hoisted-декларації,
|
|
4531
|
-
* а пресети викликають їх лише в тілі своїх функцій.
|
|
4532
|
-
*/
|
|
4498
|
+
//#region ../sdk/dist/field-presets.js
|
|
4533
4499
|
function email(raw) {
|
|
4534
4500
|
const o = normalizeOpts(raw);
|
|
4535
4501
|
const required = o.required ?? false;
|
|
@@ -4583,14 +4549,6 @@ function password(raw) {
|
|
|
4583
4549
|
zod: optionalize(s, required)
|
|
4584
4550
|
});
|
|
4585
4551
|
}
|
|
4586
|
-
/**
|
|
4587
|
-
* Internal API-token list — keyValue-shaped collection (name + write-only
|
|
4588
|
-
* token + timestamps), custom renderer (`kind:'internalApiToken'`, own
|
|
4589
|
-
* create/revoke UI — same trick as url()/perWeekday()). "Internal" = not a
|
|
4590
|
-
* general-purpose field type for plugin modules, only for the core account
|
|
4591
|
-
* settings page. `token` is `kind:'password'` so maskSecrets/preserveTree
|
|
4592
|
-
* already mask/preserve it for free.
|
|
4593
|
-
*/
|
|
4594
4552
|
function internalApiToken(o) {
|
|
4595
4553
|
return group({
|
|
4596
4554
|
key: o.key,
|
|
@@ -4683,9 +4641,7 @@ function link(raw) {
|
|
|
4683
4641
|
}, o.multiple ?? false));
|
|
4684
4642
|
}
|
|
4685
4643
|
var TEL_RE = /^\+?[\d\s()-]{4,}$/;
|
|
4686
|
-
/** Loose URL: будь-який scheme:// АБО host-з-крапкою (+опц. порт/шлях). Без пробілів. */
|
|
4687
4644
|
var LINK_RE = /^([a-z][a-z0-9+.-]*:\/\/\S+|[\w-]+(\.[\w-]+)+(:\d+)?(\/\S*)?)$/i;
|
|
4688
|
-
/** CSS named colors (CSS Color Module L4) — для f.colorname. */
|
|
4689
4645
|
var CSS_COLOR_NAMES = new Set([
|
|
4690
4646
|
"aliceblue",
|
|
4691
4647
|
"antiquewhite",
|
|
@@ -4944,7 +4900,6 @@ function reminder(raw) {
|
|
|
4944
4900
|
}
|
|
4945
4901
|
var _real = real;
|
|
4946
4902
|
var _int = int;
|
|
4947
|
-
/** Відсоток 0..100 — real з rules:{min:0,max:100}. */
|
|
4948
4903
|
function percent(o) {
|
|
4949
4904
|
return _real({
|
|
4950
4905
|
...o,
|
|
@@ -4955,7 +4910,6 @@ function percent(o) {
|
|
|
4955
4910
|
}
|
|
4956
4911
|
});
|
|
4957
4912
|
}
|
|
4958
|
-
/** Рік — int з rules:{min:1900,max:2100}; межі можна перекрити через rules.min/max. */
|
|
4959
4913
|
function year(o) {
|
|
4960
4914
|
return _int({
|
|
4961
4915
|
...o,
|
|
@@ -5776,7 +5730,7 @@ var require_data = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5776
5730
|
};
|
|
5777
5731
|
}));
|
|
5778
5732
|
//#endregion
|
|
5779
|
-
//#region ../sdk/
|
|
5733
|
+
//#region ../sdk/dist/fields/constants.js
|
|
5780
5734
|
var import_src = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
5781
5735
|
var LANGUAGES_LIST = require_data();
|
|
5782
5736
|
var LANGUAGES = {};
|
|
@@ -5832,21 +5786,7 @@ import_src.default.getAllCodes().map((code) => ({
|
|
|
5832
5786
|
name: import_src.default.getNativeName(code)
|
|
5833
5787
|
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
5834
5788
|
//#endregion
|
|
5835
|
-
//#region ../sdk/
|
|
5836
|
-
/**
|
|
5837
|
-
* The field type system — the heart of the platform. A pure, isomorphic module.
|
|
5838
|
-
* One field description → three consumers:
|
|
5839
|
-
* 1. `zod` — validation (identical on server and client)
|
|
5840
|
-
* 2. `column` — the DB column type
|
|
5841
|
-
* 3. `prim`/`kind` — keys for resolving the renderer (see web/render/registry)
|
|
5842
|
-
*/
|
|
5843
|
-
/**
|
|
5844
|
-
* A visual or storage group of fields (one level of nesting — no groups inside groups).
|
|
5845
|
-
* Without `key` → a layout group (not stored). With `key` → storage:
|
|
5846
|
-
* - embedded (key, no multiple): stored as a column or a nested object.
|
|
5847
|
-
* - collection (key + multiple): a child table (array of rows).
|
|
5848
|
-
* A storage group requires a `label` and only `FieldItem` children (with a storage key).
|
|
5849
|
-
*/
|
|
5789
|
+
//#region ../sdk/dist/fields.js
|
|
5850
5790
|
function group(o) {
|
|
5851
5791
|
const r = o.rules ?? {};
|
|
5852
5792
|
const v = o.view ?? {};
|
|
@@ -5869,7 +5809,6 @@ function group(o) {
|
|
|
5869
5809
|
fields: o.fields
|
|
5870
5810
|
};
|
|
5871
5811
|
}
|
|
5872
|
-
/** Layout group, flow nowrap + horizontal scroll (single line). Sugar over group(). */
|
|
5873
5812
|
function row(o) {
|
|
5874
5813
|
return group({
|
|
5875
5814
|
label: o.label,
|
|
@@ -5880,7 +5819,6 @@ function row(o) {
|
|
|
5880
5819
|
}
|
|
5881
5820
|
});
|
|
5882
5821
|
}
|
|
5883
|
-
/** Tabular collection (array of rows → <table>, aligned by columns). Sugar. */
|
|
5884
5822
|
function table(o) {
|
|
5885
5823
|
return group({
|
|
5886
5824
|
key: o.key,
|
|
@@ -5895,11 +5833,6 @@ function table(o) {
|
|
|
5895
5833
|
}
|
|
5896
5834
|
});
|
|
5897
5835
|
}
|
|
5898
|
-
/**
|
|
5899
|
-
* Layout group with a 2D layout (rows×columns → aligned CSS grid).
|
|
5900
|
-
* Keyless (flat parent fields). Rows are glued together with brk() separators
|
|
5901
|
-
* into a flat fields; the renderer reconstructs the 2D by splitting on brk. Sugar over group().
|
|
5902
|
-
*/
|
|
5903
5836
|
function sheet(o) {
|
|
5904
5837
|
const flat = [];
|
|
5905
5838
|
o.fields.forEach((rowFields, i) => {
|
|
@@ -5915,12 +5848,6 @@ function sheet(o) {
|
|
|
5915
5848
|
}
|
|
5916
5849
|
});
|
|
5917
5850
|
}
|
|
5918
|
-
/**
|
|
5919
|
-
* Composite URL — embedded-group sugar. Storage: separate nested columns
|
|
5920
|
-
* (`key__scheme`, `key__host`, `key__port`, …) in the same table. The renderer
|
|
5921
|
-
* is custom (a single link/input, `kind:'url'`) — string↔parts via
|
|
5922
|
-
* parseUrl/buildUrl. Partial/invalid URLs are stored by parts.
|
|
5923
|
-
*/
|
|
5924
5851
|
function url(o) {
|
|
5925
5852
|
return group({
|
|
5926
5853
|
key: o.key,
|
|
@@ -5954,22 +5881,18 @@ function keyed(o) {
|
|
|
5954
5881
|
fixed: o.fixed
|
|
5955
5882
|
};
|
|
5956
5883
|
}
|
|
5957
|
-
/** Horizontal divider. */
|
|
5958
5884
|
function divider() {
|
|
5959
5885
|
return { el: "divider" };
|
|
5960
5886
|
}
|
|
5961
|
-
/** Forced flow-row wrap (subsequent fields start on a new row). No <hr>. */
|
|
5962
5887
|
function brk() {
|
|
5963
5888
|
return { el: "break" };
|
|
5964
5889
|
}
|
|
5965
|
-
/** Reference markdown block by i18n key. */
|
|
5966
5890
|
function info(textKey) {
|
|
5967
5891
|
return {
|
|
5968
5892
|
el: "info",
|
|
5969
5893
|
text: textKey
|
|
5970
5894
|
};
|
|
5971
5895
|
}
|
|
5972
|
-
/** Action button: invokes the handler registered in actionRegistry under the key `value`. */
|
|
5973
5896
|
function button(o) {
|
|
5974
5897
|
return {
|
|
5975
5898
|
el: "button",
|
|
@@ -5979,7 +5902,6 @@ function button(o) {
|
|
|
5979
5902
|
variant: o.variant
|
|
5980
5903
|
};
|
|
5981
5904
|
}
|
|
5982
|
-
/** Wraps FieldMeta into FieldItem/StaticEl depending on opts.key/opts.value. */
|
|
5983
5905
|
function wrapKey(opts, meta) {
|
|
5984
5906
|
let m = meta;
|
|
5985
5907
|
if (opts.noEditControl) m = {
|
|
@@ -6018,14 +5940,6 @@ function safeJsonParse(s) {
|
|
|
6018
5940
|
return;
|
|
6019
5941
|
}
|
|
6020
5942
|
}
|
|
6021
|
-
/**
|
|
6022
|
-
* Wraps a field into a JSON array of values (storage: TEXT). The inner zod is `base.zod`.
|
|
6023
|
-
* Modifier order: base → applyMultiple.
|
|
6024
|
-
*
|
|
6025
|
-
* Exception: kind 'image'/'media' handle multiple themselves in the renderer (gallery) —
|
|
6026
|
-
* the MultipleField* wrappers on the web skip them.
|
|
6027
|
-
*/
|
|
6028
|
-
/** Zod "JSON array of inner values" — shared by applyMultiple and bindSelectSourceZod. */
|
|
6029
5943
|
function multipleZod(inner) {
|
|
6030
5944
|
return unknown().superRefine((raw, ctx) => {
|
|
6031
5945
|
let arr;
|
|
@@ -6618,11 +6532,6 @@ function geo(raw) {
|
|
|
6618
6532
|
zod: optionalize(s, required)
|
|
6619
6533
|
});
|
|
6620
6534
|
}
|
|
6621
|
-
/**
|
|
6622
|
-
* 7 values, Mon–Sun. A thin wrapper over keyed({fixed}): a fixed collection,
|
|
6623
|
-
* by=select('weekdays'), one real value per day. Its own kind 'per-weekday'
|
|
6624
|
-
* dispatches a compact renderer. Storage: a grandchild table of {day, value} rows.
|
|
6625
|
-
*/
|
|
6626
6535
|
function perWeekday(o) {
|
|
6627
6536
|
return {
|
|
6628
6537
|
...keyed({
|
|
@@ -6915,11 +6824,6 @@ function embed(raw) {
|
|
|
6915
6824
|
zod: optionalize(s, required)
|
|
6916
6825
|
});
|
|
6917
6826
|
}
|
|
6918
|
-
/**
|
|
6919
|
-
* Base primitives (storage-aligned) + structural types. Presets (thin wrappers
|
|
6920
|
-
* over these primitives) are added below from field-presets.ts and CANNOT override
|
|
6921
|
-
* any key from here (guard in composeF).
|
|
6922
|
-
*/
|
|
6923
6827
|
var PRIMITIVES = {
|
|
6924
6828
|
string,
|
|
6925
6829
|
text,
|
|
@@ -6969,7 +6873,6 @@ var PRIMITIVES = {
|
|
|
6969
6873
|
info,
|
|
6970
6874
|
button
|
|
6971
6875
|
};
|
|
6972
|
-
/** Assembles `f`, guaranteeing no preset shadows a primitive. */
|
|
6973
6876
|
function composeF(presets) {
|
|
6974
6877
|
for (const k of Object.keys(presets)) if (k in PRIMITIVES) throw new Error(`[f] preset '${k}' overrides a primitive`);
|
|
6975
6878
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffer-org/plugin-telegram",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
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": "^1.3.
|
|
29
|
-
"@coffer-org/sdk": "^1.
|
|
30
|
-
"@coffer-org/server": "^1.
|
|
28
|
+
"@coffer-org/plugin-orchestrator": "^1.3.1",
|
|
29
|
+
"@coffer-org/sdk": "^1.4.0",
|
|
30
|
+
"@coffer-org/server": "^1.4.0",
|
|
31
31
|
"input": "^1.0.1",
|
|
32
32
|
"telegram": "^2.26.0"
|
|
33
33
|
},
|