@wirecat/cli-core 0.711.0 → 0.712.0
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/CHANGELOG.md +15 -0
- package/dist/background/deliver.d.ts +11 -4
- package/dist/background/deliver.js +47 -19
- package/dist/background/report/render.d.ts +10 -4
- package/dist/background/report/render.js +96 -8
- package/dist/background/report/templates/morning-digest.telegram.en.liquid +2 -2
- package/dist/background/report/templates/morning-digest.telegram.ru.liquid +2 -2
- package/dist/background/report/view.d.ts +4 -0
- package/dist/background/report/view.js +12 -8
- package/dist/background/schedules.js +4 -2
- package/dist/crm/digest.js +3 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,21 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.712.0 — 19.11.2026
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **The morning digest reaches Telegram whole.** A digest longer than one Telegram message (4096 characters) is sent
|
|
13
|
+
as several messages in order, split between sections, or between items when one section fills a message by itself;
|
|
14
|
+
no item is cut or left out. Each part is rendered by the template, so its markup stays valid. A later part's title
|
|
15
|
+
and a section that goes on carry "(продолжение)" / "(continued)"; the summary opens the first part, and the
|
|
16
|
+
sources and the footer close the last. Delivery sends the parts about a second apart (three in a group), as
|
|
17
|
+
Telegram's bot FAQ asks, and a part that fails stops the rest and is named in `last.json`. Before, items were dropped
|
|
18
|
+
until the text fit and counted in "ещё N".
|
|
19
|
+
- **A section shows up to 25 items, and the sources up to 10.** memo's digest now has 15 to 30 items, and its brief
|
|
20
|
+
allows 25 in one section; the old caps (7 today, 5 in most sections, 3 sources) cut it. The caps stay as a safety
|
|
21
|
+
net. The CRM digest keeps its own 7 per section. The `wirecat.report/1` document and mail are unchanged.
|
|
22
|
+
|
|
8
23
|
## 0.711.0 — 19.11.2026
|
|
9
24
|
|
|
10
25
|
### Added
|
|
@@ -27,7 +27,8 @@ export declare const DELIVERY_REASONS: {
|
|
|
27
27
|
};
|
|
28
28
|
export type DeliveryReason = (typeof DELIVERY_REASONS)[keyof typeof DELIVERY_REASONS];
|
|
29
29
|
/**
|
|
30
|
-
* One route's outcome, kept in `last.json`. `error` is the sending CLI's error code and reason id, never its message
|
|
30
|
+
* One route's outcome, kept in `last.json`. `error` is the sending CLI's error code and reason id, never its message,
|
|
31
|
+
* and for a split report which part failed (`part 2 of 3`).
|
|
31
32
|
* A send that went as plain text because Telegram refused the HTML, or a mail-cli older than `--html` refused the
|
|
32
33
|
* flag, is `ok` with the `html-fallback` reason, and the one line sent in place of a report that failed its check is
|
|
33
34
|
* `ok` with `report-invalid`.
|
|
@@ -56,7 +57,8 @@ export interface Parcel {
|
|
|
56
57
|
rendered?: RenderedParcel;
|
|
57
58
|
}
|
|
58
59
|
export interface RenderedParcel {
|
|
59
|
-
|
|
60
|
+
/** The Telegram messages, sent in this order. */
|
|
61
|
+
telegram: string[];
|
|
60
62
|
/** The email's HTML; without it, or when `mail` refuses `--html`, the email is `text`. */
|
|
61
63
|
email?: string;
|
|
62
64
|
text: string;
|
|
@@ -66,8 +68,11 @@ export interface RenderedParcel {
|
|
|
66
68
|
}
|
|
67
69
|
/** The caption as HTML: the head is cut in Markdown, where no tag can be split, and cut shorter until its HTML fits. */
|
|
68
70
|
export declare const htmlHeadOf: (title: string, report: string, limit?: number) => string;
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Hands the parcel to each route's CLI, one after another; a route that fails is recorded and the next one still goes.
|
|
73
|
+
* A report split into several Telegram messages sends them in order, a pause apart, and stops at the first that fails.
|
|
74
|
+
*/
|
|
75
|
+
export declare const deliver: (system: ServerSystem, env: NodeJS.ProcessEnv, routes: readonly string[], parcel: Parcel, { find, errorOf, locked, timeoutMs, wait, }: {
|
|
71
76
|
/** Where a program is on the run's PATH. */
|
|
72
77
|
find: (name: string, env: NodeJS.ProcessEnv) => string | undefined;
|
|
73
78
|
/** The one line kept of a failed send's stderr. */
|
|
@@ -75,4 +80,6 @@ export declare const deliver: (system: ServerSystem, env: NodeJS.ProcessEnv, rou
|
|
|
75
80
|
/** The lock the scheduler itself runs under: nothing goes out from a locked run. */
|
|
76
81
|
locked?: string;
|
|
77
82
|
timeoutMs?: number;
|
|
83
|
+
/** The pause between two parts of a split report. */
|
|
84
|
+
wait?: (ms: number) => Promise<void>;
|
|
78
85
|
}) => Promise<Delivery[]>;
|
|
@@ -84,8 +84,20 @@ const plainFit = (text) => {
|
|
|
84
84
|
const line = cut.lastIndexOf("\n");
|
|
85
85
|
return `${line > 0 ? cut.slice(0, line) : cut}\n…`;
|
|
86
86
|
};
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
const UNESCAPES = { "<": "<", ">": ">", """: '"', "&": "&" };
|
|
88
|
+
/** One part of a split report as plain text, so a refused part goes in place without shifting the others. */
|
|
89
|
+
const plainPart = (rendered, part) => rendered.telegram.length === 1
|
|
90
|
+
? plainFit(rendered.text)
|
|
91
|
+
: plainFit((rendered.telegram[part] ?? "")
|
|
92
|
+
.replace(/<[^>]*>/g, "")
|
|
93
|
+
.replace(/&(lt|gt|quot|amp);/g, (one) => UNESCAPES[one]));
|
|
94
|
+
/**
|
|
95
|
+
* Telegram's FAQ asks for about one message a second in a chat and twenty a minute in a group
|
|
96
|
+
* (https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this).
|
|
97
|
+
*/
|
|
98
|
+
const PART_GAP_MS = { chat: 1_100, group: 3_100 };
|
|
99
|
+
/** A rendered report needs no file: Telegram's parts were fitted when it was rendered, and mail has no limit. */
|
|
100
|
+
const renderedArgvOf = (program, route, rendered, plain = false, part = 0) => {
|
|
89
101
|
const lead = [program, route.profile, "--json", "--no-input"];
|
|
90
102
|
if (route.kind === "email")
|
|
91
103
|
return [
|
|
@@ -106,7 +118,7 @@ const renderedArgvOf = (program, route, rendered, plain = false) => {
|
|
|
106
118
|
...(plain ? [] : ["--html"]),
|
|
107
119
|
"--",
|
|
108
120
|
route.chat,
|
|
109
|
-
plain ?
|
|
121
|
+
plain ? plainPart(rendered, part) : (rendered.telegram[part] ?? ""),
|
|
110
122
|
];
|
|
111
123
|
};
|
|
112
124
|
const textOf = (title, report) => (report.trim() ? `${title}\n${report.trim()}` : title);
|
|
@@ -150,8 +162,11 @@ const argvOf = (program, route, title, report, copy, plain = false) => {
|
|
|
150
162
|
text,
|
|
151
163
|
];
|
|
152
164
|
};
|
|
153
|
-
/**
|
|
154
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Hands the parcel to each route's CLI, one after another; a route that fails is recorded and the next one still goes.
|
|
167
|
+
* A report split into several Telegram messages sends them in order, a pause apart, and stops at the first that fails.
|
|
168
|
+
*/
|
|
169
|
+
export const deliver = async (system, env, routes, parcel, { find, errorOf, locked, timeoutMs = DELIVERY_TIMEOUT_MS, wait = (ms) => new Promise((done) => setTimeout(done, ms)), }) => {
|
|
155
170
|
const failed = (to, reason, error) => ({
|
|
156
171
|
to,
|
|
157
172
|
ok: false,
|
|
@@ -194,20 +209,33 @@ export const deliver = async (system, env, routes, parcel, { find, errorOf, lock
|
|
|
194
209
|
timeoutMs,
|
|
195
210
|
...(route.kind === "email" ? { input: mailInput(plain) } : {}),
|
|
196
211
|
});
|
|
197
|
-
const argv = (plain
|
|
198
|
-
? renderedArgvOf(program, route, rendered, plain)
|
|
212
|
+
const argv = (plain, part) => rendered
|
|
213
|
+
? renderedArgvOf(program, route, rendered, plain, part)
|
|
199
214
|
: argvOf(program, route, parcel.title, report, copy, plain);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
215
|
+
const send = async (part) => {
|
|
216
|
+
const ran = await system.run(argv(false, part), childEnv, options());
|
|
217
|
+
const refused = ran.code !== 0 &&
|
|
218
|
+
ran.code !== TIMED_OUT &&
|
|
219
|
+
(route.kind === "telegram-bot"
|
|
220
|
+
? codeOf(ran.stderr) === REFUSED_CONTENT
|
|
221
|
+
: rendered?.email !== undefined && refusesHtmlFlag(ran.stderr));
|
|
222
|
+
if (!refused)
|
|
223
|
+
return { ran, fellBack: "" };
|
|
224
|
+
return {
|
|
225
|
+
ran: await system.run(argv(true, part), childEnv, options(true)),
|
|
226
|
+
fellBack: errorOf(ran.stderr, ran.code),
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
const parts = rendered && route.kind === "telegram-bot" ? rendered.telegram.length : 1;
|
|
230
|
+
let { ran, fellBack } = await send(0);
|
|
231
|
+
let part = 1;
|
|
232
|
+
for (; part < parts && ran.code === 0; part += 1) {
|
|
233
|
+
await wait(route.kind === "telegram-bot" && route.chat.startsWith("-") ? PART_GAP_MS.group : PART_GAP_MS.chat);
|
|
234
|
+
const next = await send(part);
|
|
235
|
+
ran = next.ran;
|
|
236
|
+
fellBack ||= next.fellBack;
|
|
210
237
|
}
|
|
238
|
+
const which = parts > 1 ? `part ${part} of ${parts}` : "";
|
|
211
239
|
if (ran.code === 0) {
|
|
212
240
|
out.push(rendered?.invalid
|
|
213
241
|
? { to, ok: true, reason: DELIVERY_REASONS.reportInvalid }
|
|
@@ -216,9 +244,9 @@ export const deliver = async (system, env, routes, parcel, { find, errorOf, lock
|
|
|
216
244
|
: { to, ok: true });
|
|
217
245
|
}
|
|
218
246
|
else if (ran.code === TIMED_OUT)
|
|
219
|
-
out.push(failed(to, DELIVERY_REASONS.timeout));
|
|
247
|
+
out.push(failed(to, DELIVERY_REASONS.timeout, which));
|
|
220
248
|
else
|
|
221
|
-
out.push(failed(to, DELIVERY_REASONS.failed, errorOf(ran.stderr, ran.code)));
|
|
249
|
+
out.push(failed(to, DELIVERY_REASONS.failed, [errorOf(ran.stderr, ran.code), which].filter(Boolean).join(" · ")));
|
|
222
250
|
}
|
|
223
251
|
catch {
|
|
224
252
|
out.push(failed(to, DELIVERY_REASONS.failed));
|
|
@@ -23,7 +23,10 @@ export declare const sanitizeHtml: (channel: Exclude<ReportChannel, "text">, htm
|
|
|
23
23
|
removed: string[];
|
|
24
24
|
};
|
|
25
25
|
export interface Rendering {
|
|
26
|
+
/** The parts joined by a blank line: the whole text everywhere but a Telegram digest split in several messages. */
|
|
26
27
|
text: string;
|
|
28
|
+
/** Telegram's messages in order, each within its limit; one part on every other channel. */
|
|
29
|
+
parts: string[];
|
|
27
30
|
/** The override template failed and the default was used. */
|
|
28
31
|
templateFailed: boolean;
|
|
29
32
|
/** Tags or attributes the platform rules took out. */
|
|
@@ -31,15 +34,16 @@ export interface Rendering {
|
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* One channel's text of a report. A failing `template` (a stored override, later) falls back to the shipped one for
|
|
34
|
-
* this channel only.
|
|
37
|
+
* this channel only. A digest too long for one Telegram message is split into several (`digestParts`); any other
|
|
38
|
+
* Telegram text, or a digest whose single item cannot fit, is rendered again with an item fewer until it fits.
|
|
35
39
|
*/
|
|
36
40
|
export declare const renderReport: (view: MessageView, channel: ReportChannel, { template }?: {
|
|
37
41
|
template?: string;
|
|
38
42
|
}) => Promise<Rendering>;
|
|
39
43
|
/**
|
|
40
44
|
* Why `source` may not be saved for this view, empty when it may, and what it renders: it must render, the platform
|
|
41
|
-
* rules may take nothing out, and a Telegram text must fit once the size fit dropped what
|
|
42
|
-
* `renderReport` it never falls back to the shipped template.
|
|
45
|
+
* rules may take nothing out, and a Telegram text must fit in its messages, split or once the size fit dropped what
|
|
46
|
+
* it could. Unlike `renderReport` it never falls back to the shipped template.
|
|
43
47
|
*/
|
|
44
48
|
export declare const checkTemplate: (view: MessageView, channel: ReportChannel, source: string) => Promise<{
|
|
45
49
|
problems: string[];
|
|
@@ -57,7 +61,8 @@ export interface ReportRun {
|
|
|
57
61
|
reasons?: string[];
|
|
58
62
|
}
|
|
59
63
|
export interface PreparedReport {
|
|
60
|
-
|
|
64
|
+
/** The Telegram messages, sent in this order. */
|
|
65
|
+
telegram: string[];
|
|
61
66
|
/** HTML with inline CSS for `mail messages send --html`; absent for an invalid report, which goes as `text`. */
|
|
62
67
|
email?: string;
|
|
63
68
|
/** Plain text with web links: the email when the installed mail cannot send `--html`. */
|
|
@@ -90,6 +95,7 @@ export declare const prepareReport: (answer: string, { language, now, timeZone,
|
|
|
90
95
|
}) => Promise<PreparedReport | undefined>;
|
|
91
96
|
/** A message other than the digest, rendered for every channel: what `deliver` sends as a rendered parcel. */
|
|
92
97
|
export interface PreparedMessage {
|
|
98
|
+
/** One Telegram message: a notice or the gaps are fitted to one by leaving the last gaps out. */
|
|
93
99
|
telegram: string;
|
|
94
100
|
email: string;
|
|
95
101
|
text: string;
|
|
@@ -140,6 +140,74 @@ const renderWithFallback = async (view, channel, template) => {
|
|
|
140
140
|
return { ...(await shipped()), templateFailed: true };
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
+
const fits = (text) => text.length <= TELEGRAM_TEXT_CHARS;
|
|
144
|
+
/**
|
|
145
|
+
* The items `from` up to `to` of the digest, counted across its sections in order, as one Telegram message: the
|
|
146
|
+
* summary on the first, the sources and the footer on the last, a section's "ещё N" and task links where it ends.
|
|
147
|
+
*/
|
|
148
|
+
const partOf = (view, from, to, first, last) => {
|
|
149
|
+
let at = 0;
|
|
150
|
+
const sections = view.sections.flatMap((section) => {
|
|
151
|
+
const start = at;
|
|
152
|
+
at += section.items.length;
|
|
153
|
+
const items = section.items.slice(Math.max(from - start, 0), Math.max(to - start, 0));
|
|
154
|
+
if (items.length === 0)
|
|
155
|
+
return [];
|
|
156
|
+
const ends = to >= at;
|
|
157
|
+
return [{ ...section, items, continued: from > start, ...(ends ? {} : { more: 0, groups: [], undated: null }) }];
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
...view,
|
|
161
|
+
sections,
|
|
162
|
+
summary: first ? view.summary : null,
|
|
163
|
+
health: last ? view.health : { ...view.health, items: [], more: 0 },
|
|
164
|
+
scope: last ? view.scope : null,
|
|
165
|
+
continued: !first,
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* A digest too long for one Telegram message as several, each rendered whole by the template, so every part's markup
|
|
170
|
+
* is complete and no item is cut. A section moves to the next message whole when it would fit there, and is split
|
|
171
|
+
* between items only when it fills a message by itself. Undefined when a single item cannot fit a message.
|
|
172
|
+
*/
|
|
173
|
+
const digestParts = async (view, render) => {
|
|
174
|
+
const ends = [];
|
|
175
|
+
for (const section of view.sections)
|
|
176
|
+
ends.push((ends.at(-1) ?? 0) + section.items.length);
|
|
177
|
+
const total = ends.at(-1) ?? 0;
|
|
178
|
+
const starts = new Set([0, ...ends]);
|
|
179
|
+
const endOf = (item) => ends.find((end) => end > item) ?? total;
|
|
180
|
+
const parts = [];
|
|
181
|
+
for (let from = 0;;) {
|
|
182
|
+
const first = parts.length === 0;
|
|
183
|
+
const rest = await render(partOf(view, from, total, first, true));
|
|
184
|
+
if (fits(rest))
|
|
185
|
+
return [...parts, rest];
|
|
186
|
+
let to = from;
|
|
187
|
+
let kept;
|
|
188
|
+
while (to < total) {
|
|
189
|
+
if (to > from && starts.has(to)) {
|
|
190
|
+
const whole = await render(partOf(view, from, endOf(to), first, false));
|
|
191
|
+
if (fits(whole)) {
|
|
192
|
+
kept = whole;
|
|
193
|
+
to = endOf(to);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (fits(await render(partOf(view, to, endOf(to), false, false))))
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
const text = await render(partOf(view, from, to + 1, first, false));
|
|
200
|
+
if (!fits(text))
|
|
201
|
+
break;
|
|
202
|
+
kept = text;
|
|
203
|
+
to += 1;
|
|
204
|
+
}
|
|
205
|
+
if (kept === undefined)
|
|
206
|
+
return undefined;
|
|
207
|
+
parts.push(kept);
|
|
208
|
+
from = to;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
143
211
|
/**
|
|
144
212
|
* The view with one item fewer: the digest's last item of its largest section, the last gap; counted in `more`.
|
|
145
213
|
* A notice has nothing to drop.
|
|
@@ -166,25 +234,40 @@ const dropOne = (view) => {
|
|
|
166
234
|
};
|
|
167
235
|
/**
|
|
168
236
|
* One channel's text of a report. A failing `template` (a stored override, later) falls back to the shipped one for
|
|
169
|
-
* this channel only.
|
|
237
|
+
* this channel only. A digest too long for one Telegram message is split into several (`digestParts`); any other
|
|
238
|
+
* Telegram text, or a digest whose single item cannot fit, is rendered again with an item fewer until it fits.
|
|
170
239
|
*/
|
|
171
240
|
export const renderReport = async (view, channel, { template } = {}) => {
|
|
241
|
+
const whole = await renderWithFallback(view, channel, template);
|
|
242
|
+
if (channel !== "telegram" || fits(whole.text))
|
|
243
|
+
return { ...whole, parts: [whole.text] };
|
|
244
|
+
if (view.kind === "morning-digest") {
|
|
245
|
+
const split = (source) => digestParts(view, async (part) => (await renderOnce(part, channel, source)).text);
|
|
246
|
+
const shipped = defaultTemplate(view.kind, channel, view.language);
|
|
247
|
+
let failed = whole.templateFailed;
|
|
248
|
+
const parts = await (failed || template === undefined ? split(shipped) : split(template)).catch(() => {
|
|
249
|
+
failed = true;
|
|
250
|
+
return split(shipped);
|
|
251
|
+
});
|
|
252
|
+
if (parts)
|
|
253
|
+
return { text: parts.join("\n\n"), parts, templateFailed: failed, templateTags: whole.templateTags };
|
|
254
|
+
}
|
|
172
255
|
let current = view;
|
|
173
256
|
let source = template;
|
|
174
257
|
for (;;) {
|
|
175
258
|
const rendering = await renderWithFallback(current, channel, source);
|
|
176
259
|
if (rendering.templateFailed)
|
|
177
260
|
source = undefined;
|
|
178
|
-
const smaller =
|
|
261
|
+
const smaller = fits(rendering.text) ? undefined : dropOne(current);
|
|
179
262
|
if (!smaller)
|
|
180
|
-
return { ...rendering, templateFailed: rendering.templateFailed || source !== template };
|
|
263
|
+
return { ...rendering, parts: [rendering.text], templateFailed: rendering.templateFailed || source !== template };
|
|
181
264
|
current = smaller;
|
|
182
265
|
}
|
|
183
266
|
};
|
|
184
267
|
/**
|
|
185
268
|
* Why `source` may not be saved for this view, empty when it may, and what it renders: it must render, the platform
|
|
186
|
-
* rules may take nothing out, and a Telegram text must fit once the size fit dropped what
|
|
187
|
-
* `renderReport` it never falls back to the shipped template.
|
|
269
|
+
* rules may take nothing out, and a Telegram text must fit in its messages, split or once the size fit dropped what
|
|
270
|
+
* it could. Unlike `renderReport` it never falls back to the shipped template.
|
|
188
271
|
*/
|
|
189
272
|
export const checkTemplate = async (view, channel, source) => {
|
|
190
273
|
let current = view;
|
|
@@ -202,8 +285,13 @@ export const checkTemplate = async (view, channel, source) => {
|
|
|
202
285
|
problems: [...new Set(rendering.removed)].map((what) => `the ${channel} rules would remove ${what}`),
|
|
203
286
|
text: rendering.text,
|
|
204
287
|
};
|
|
205
|
-
if (channel !== "telegram" || rendering.text
|
|
288
|
+
if (channel !== "telegram" || fits(rendering.text))
|
|
206
289
|
return { problems: [], text: rendering.text };
|
|
290
|
+
if (current === view && current.kind === "morning-digest") {
|
|
291
|
+
const parts = await digestParts(current, async (part) => (await renderOnce(part, channel, source)).text).catch(() => undefined);
|
|
292
|
+
if (parts)
|
|
293
|
+
return { problems: [], text: parts.join("\n\n") };
|
|
294
|
+
}
|
|
207
295
|
const smaller = dropOne(current);
|
|
208
296
|
if (!smaller)
|
|
209
297
|
return {
|
|
@@ -230,7 +318,7 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
|
|
|
230
318
|
if ("invalid" in parsed) {
|
|
231
319
|
const line = INVALID_LINES[language] ?? INVALID_LINES[DEFAULT_LANGUAGE];
|
|
232
320
|
return {
|
|
233
|
-
telegram: escapeHtml(line),
|
|
321
|
+
telegram: [escapeHtml(line)],
|
|
234
322
|
text: line,
|
|
235
323
|
terminal: line,
|
|
236
324
|
subject: line,
|
|
@@ -265,7 +353,7 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
|
|
|
265
353
|
];
|
|
266
354
|
const title = text.text.split("\n")[0] ?? "";
|
|
267
355
|
return {
|
|
268
|
-
telegram: telegram.
|
|
356
|
+
telegram: telegram.parts,
|
|
269
357
|
email: email.text,
|
|
270
358
|
text: text.text,
|
|
271
359
|
terminal: terminal.text,
|
|
@@ -6,7 +6,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
|
|
|
6
6
|
{% endcapture -%}
|
|
7
7
|
{%- assign weekdays = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" | split: "," -%}
|
|
8
8
|
{%- assign weekday = date.weekday | minus: 1 -%}
|
|
9
|
-
{{ emoji }} <b>Digest for {{ weekdays[weekday] }}, {{ date.date }}</b>
|
|
9
|
+
{{ emoji }} <b>Digest for {{ weekdays[weekday] }}, {{ date.date }}{% if continued %} (continued){% endif %}</b>
|
|
10
10
|
{%- if summary %}{{ nl }}{{ summary }}{% endif -%}
|
|
11
11
|
{%- if quiet -%}
|
|
12
12
|
{{ nl }}{{ nl }}
|
|
@@ -23,7 +23,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
|
|
|
23
23
|
{%- when "projects" %}Projects in motion
|
|
24
24
|
{%- when "mail" %}New mail
|
|
25
25
|
{%- when "crm" %}CRM
|
|
26
|
-
{%- endcase %}</b>
|
|
26
|
+
{%- endcase %}{% if section.continued %} (continued){% endif %}</b>
|
|
27
27
|
{%- for item in section.items -%}
|
|
28
28
|
{%- capture due -%}
|
|
29
29
|
{%- if item.due -%}
|
|
@@ -6,7 +6,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
|
|
|
6
6
|
{% endcapture -%}
|
|
7
7
|
{%- assign weekdays = "понедельник,вторник,среду,четверг,пятницу,субботу,воскресенье" | split: "," -%}
|
|
8
8
|
{%- assign weekday = date.weekday | minus: 1 -%}
|
|
9
|
-
{{ emoji }} <b>Сводка на {{ weekdays[weekday] }}, {{ date.date }}</b>
|
|
9
|
+
{{ emoji }} <b>Сводка на {{ weekdays[weekday] }}, {{ date.date }}{% if continued %} (продолжение){% endif %}</b>
|
|
10
10
|
{%- if summary %}{{ nl }}{{ summary }}{% endif -%}
|
|
11
11
|
{%- if quiet -%}
|
|
12
12
|
{{ nl }}{{ nl }}
|
|
@@ -23,7 +23,7 @@ Every string from the report is already escaped. Lines are written with {{ nl }}
|
|
|
23
23
|
{%- when "projects" %}Проекты в движении
|
|
24
24
|
{%- when "mail" %}Новая почта
|
|
25
25
|
{%- when "crm" %}CRM
|
|
26
|
-
{%- endcase %}</b>
|
|
26
|
+
{%- endcase %}{% if section.continued %} (продолжение){% endif %}</b>
|
|
27
27
|
{%- for item in section.items -%}
|
|
28
28
|
{%- capture due -%}
|
|
29
29
|
{%- if item.due -%}
|
|
@@ -59,6 +59,8 @@ export interface ViewSection {
|
|
|
59
59
|
count: number;
|
|
60
60
|
link: ViewLink | null;
|
|
61
61
|
} | null;
|
|
62
|
+
/** The section began in an earlier Telegram message: its heading says it goes on. */
|
|
63
|
+
continued: boolean;
|
|
62
64
|
}
|
|
63
65
|
export interface ViewHealth {
|
|
64
66
|
source: string;
|
|
@@ -106,6 +108,8 @@ export interface ReportView {
|
|
|
106
108
|
};
|
|
107
109
|
scope: ViewScope | null;
|
|
108
110
|
links: ViewLink[];
|
|
111
|
+
/** A later Telegram message of a digest split in several: the title says it goes on. */
|
|
112
|
+
continued: boolean;
|
|
109
113
|
}
|
|
110
114
|
/** Builds the URL a ref opens, or null; the renderer passes `linkFor` with the form its channel needs. */
|
|
111
115
|
export type LinkOf = (ref: string) => string | null;
|
|
@@ -12,15 +12,17 @@ export const SECTION_EMOJI = {
|
|
|
12
12
|
crm: "🤝",
|
|
13
13
|
mail: "📬",
|
|
14
14
|
};
|
|
15
|
+
// A safety net, not the digest's size: memo's brief allows up to 25 items, all of which may fall in one section, and
|
|
16
|
+
// Telegram splits a long digest into several messages.
|
|
15
17
|
export const SECTION_CAPS = {
|
|
16
|
-
today:
|
|
17
|
-
decisions:
|
|
18
|
-
money:
|
|
19
|
-
meetings:
|
|
20
|
-
projects:
|
|
21
|
-
crm:
|
|
22
|
-
mail:
|
|
23
|
-
health:
|
|
18
|
+
today: 25,
|
|
19
|
+
decisions: 25,
|
|
20
|
+
money: 25,
|
|
21
|
+
meetings: 25,
|
|
22
|
+
projects: 25,
|
|
23
|
+
crm: 25,
|
|
24
|
+
mail: 25,
|
|
25
|
+
health: 10,
|
|
24
26
|
};
|
|
25
27
|
const STALE_HOURS = 24;
|
|
26
28
|
const HOUR_MS = 3_600_000;
|
|
@@ -172,6 +174,7 @@ export const reportView = (report, { language, now, timeZone, linkOf = () => nul
|
|
|
172
174
|
more: more + Math.max(items.length - cap, 0),
|
|
173
175
|
groups: [],
|
|
174
176
|
undated: null,
|
|
177
|
+
continued: false,
|
|
175
178
|
},
|
|
176
179
|
];
|
|
177
180
|
});
|
|
@@ -215,5 +218,6 @@ export const reportView = (report, { language, now, timeZone, linkOf = () => nul
|
|
|
215
218
|
counts: { today: count("today"), money: count("money") },
|
|
216
219
|
scope: report.scope && scopeView(report.scope, language),
|
|
217
220
|
links: [],
|
|
221
|
+
continued: false,
|
|
218
222
|
};
|
|
219
223
|
};
|
|
@@ -450,7 +450,7 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
450
450
|
...(prepared ? { rendered: prepared } : {}),
|
|
451
451
|
}
|
|
452
452
|
: notice
|
|
453
|
-
? { title: notice.subject, rendered: notice }
|
|
453
|
+
? { title: notice.subject, rendered: { ...notice, telegram: [notice.telegram] } }
|
|
454
454
|
: {
|
|
455
455
|
title: `${title} failed · ${at}`,
|
|
456
456
|
line: `${title} failed at ${at} (exit ${exitCode}` +
|
|
@@ -465,7 +465,9 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
|
|
|
465
465
|
const message = gaps.gaps.length === 0
|
|
466
466
|
? undefined
|
|
467
467
|
: await prepareMessage("weekly-gaps", (language) => gapsView(gaps, { language, now: now().getTime(), linkOf: options.linkOf }), options).catch(() => undefined);
|
|
468
|
-
const deliveries = message
|
|
468
|
+
const deliveries = message
|
|
469
|
+
? await sendAlong({ title: message.subject, rendered: { ...message, telegram: [message.telegram] } })
|
|
470
|
+
: [];
|
|
469
471
|
writeSecurely(join(folder, WEEKLY_GAPS_FILE), `${JSON.stringify({ at: now().toISOString(), gaps: gaps.gaps.length, runs: gaps.runs, deliveries }, null, 2)}\n`, 0o600);
|
|
470
472
|
}
|
|
471
473
|
if ("once" in schedule.when) {
|
package/dist/crm/digest.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { zonedMoment } from "@wirecat/cli-base/query";
|
|
2
2
|
import { REPORT_FORMAT } from "../background/report/schema.js";
|
|
3
|
-
import { SECTION_CAPS } from "../background/report/view.js";
|
|
4
3
|
import { dayIn } from "../domain/moment.js";
|
|
5
4
|
import { taskAccount } from "../services/task-rules.js";
|
|
6
5
|
import { viewerSql } from "../store/sqlite/copy-viewer.js";
|
|
7
6
|
import { crmStatus, SYNC_FAILED } from "./sync.js";
|
|
8
7
|
const HOUR = 3_600_000;
|
|
8
|
+
// The CRM digest's own size, apart from the renderer's safety cap: a CRM section is a part of a morning, not all of it.
|
|
9
|
+
const SHOWN = 7;
|
|
9
10
|
const STALE_HOURS = 24;
|
|
10
11
|
const WORDS = {
|
|
11
12
|
en: {
|
|
@@ -49,7 +50,7 @@ const endOfDay = (now, zone) => {
|
|
|
49
50
|
export const crmDigest = async (store, account, options) => {
|
|
50
51
|
const { since, until, now, zone, viewer } = options;
|
|
51
52
|
const words = WORDS[options.language] ?? WORDS.en;
|
|
52
|
-
const cap =
|
|
53
|
+
const cap = SHOWN;
|
|
53
54
|
const window = { since, until, ...(viewer ? { viewer } : {}) };
|
|
54
55
|
const counts = await store.crm.changeCounts(account, window);
|
|
55
56
|
const changesOf = async (kind) => counts[kind] ? (await store.crm.changes(account, { ...window, changes: [kind], limit: cap, offset: 0 })).items : [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.712.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|