Skip to content

Commit 54aa86e

Browse files
fix: notify links to GitHub repo, include English highlights
1 parent 6e41309 commit 54aa86e

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

src/notify-vi.ts

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
* Telegram notification for Vietnamese translated digests.
33
*
44
* Self-contained — does not import upstream source files.
5-
* Scans digests/{date}/ for *-vi.md files and sends links.
5+
* Scans digests/{date}/ for *-vi.md files, reads highlights.json (en),
6+
* and sends links pointing to raw GitHub files.
67
*
78
* Required env vars:
89
* TELEGRAM_BOT_TOKEN — bot token from @BotFather
910
* TELEGRAM_CHAT_ID — channel/group/user chat ID
1011
* Optional:
11-
* PAGES_URL — GitHub Pages base URL
12+
* GITHUB_REPO — owner/repo (default: compasify/agents-radar)
13+
* GITHUB_BRANCH — branch name (default: master)
1214
*/
1315

1416
import fs from "node:fs";
1517
import path from "node:path";
1618

1719
const DIGESTS_DIR = "digests";
18-
const PAGES_URL_DEFAULT = "https://compasify.github.io/agents-radar";
20+
const DEFAULT_REPO = "compasify/agents-radar";
21+
const DEFAULT_BRANCH = "master";
1922

2023
const LABELS: Record<string, string> = {
2124
"ai-cli-vi": "AI CLI Tools",
@@ -27,6 +30,14 @@ const LABELS: Record<string, string> = {
2730
"ai-monthly-vi": "AI Tools Monthly",
2831
};
2932

33+
const HIGHLIGHT_KEY: Record<string, string> = {
34+
"ai-cli-vi": "ai-cli",
35+
"ai-agents-vi": "ai-agents",
36+
"ai-web-vi": "ai-web",
37+
"ai-trending-vi": "ai-trending",
38+
"ai-hn-vi": "ai-hn",
39+
};
40+
3041
async function sendTelegram(text: string): Promise<void> {
3142
const BOT_TOKEN = process.env["TELEGRAM_BOT_TOKEN"] ?? "";
3243
const CHAT_ID = process.env["TELEGRAM_CHAT_ID"] ?? "";
@@ -57,26 +68,51 @@ function findViReports(date: string): string[] {
5768
.sort();
5869
}
5970

71+
function loadEnHighlights(date: string): Record<string, string[]> {
72+
const p = path.join(DIGESTS_DIR, date, "highlights.json");
73+
if (!fs.existsSync(p)) return {};
74+
try {
75+
const data = JSON.parse(fs.readFileSync(p, "utf-8")) as {
76+
en?: Record<string, string[]>;
77+
};
78+
return data.en ?? {};
79+
} catch {
80+
return {};
81+
}
82+
}
83+
6084
function buildMessage(date: string, reports: string[]): string {
61-
const PAGES_URL = (process.env["PAGES_URL"] ?? PAGES_URL_DEFAULT).replace(/\/$/, "");
85+
const repo = process.env["GITHUB_REPO"] ?? DEFAULT_REPO;
86+
const branch = process.env["GITHUB_BRANCH"] ?? DEFAULT_BRANCH;
87+
const baseUrl = `https://github.com/${repo}/blob/${branch}/digests/${date}`;
88+
6289
const isWeekly = reports.includes("ai-weekly-vi");
6390
const isMonthly = reports.includes("ai-monthly-vi");
64-
6591
const icon = isMonthly ? "📆" : isWeekly ? "📅" : "📡";
6692
const suffix = isMonthly ? " Monthly" : isWeekly ? " Weekly" : "";
6793
const lines: string[] = [`${icon} <b>agents-radar${suffix} (Vietnamese) · ${date}</b>`];
6894

95+
const highlights = loadEnHighlights(date);
96+
6997
const daily = reports.filter((r) => !r.includes("weekly") && !r.includes("monthly"));
7098
const rollup = reports.filter((r) => r.includes("weekly") || r.includes("monthly"));
7199

72100
for (const r of [...daily, ...rollup]) {
73101
const label = LABELS[r] ?? r;
74-
const url = `${PAGES_URL}/#${date}/${r}`;
102+
const url = `${baseUrl}/${r}.md`;
75103
lines.push("");
76104
lines.push(`• <a href="${url}">${label}</a>`);
105+
106+
const hKey = HIGHLIGHT_KEY[r];
107+
const items = hKey ? highlights[hKey] : undefined;
108+
if (items?.length) {
109+
for (const h of items) {
110+
lines.push(` ◦ ${h}`);
111+
}
112+
}
77113
}
78114

79-
lines.push(`\n<a href="${PAGES_URL}">🌐 Web UI</a> · <a href="${PAGES_URL}/feed.xml">⊕ RSS</a>`);
115+
lines.push(`\n<a href="https://github.com/${repo}">📂 Repository</a>`);
80116
return lines.join("\n");
81117
}
82118

0 commit comments

Comments
 (0)