claude-telegram-bot 0.3.11 → 0.3.13
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/ctb.mjs +35 -11
- package/package.json +1 -1
package/ctb.mjs
CHANGED
|
@@ -17,6 +17,11 @@ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "
|
|
|
17
17
|
import { basename, dirname, join } from "node:path";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import { spawn } from "node:child_process";
|
|
20
|
+
import dns from "node:dns";
|
|
21
|
+
import net from "node:net";
|
|
22
|
+
|
|
23
|
+
dns.setDefaultResultOrder("ipv4first");
|
|
24
|
+
if (net.setDefaultAutoSelectFamily) net.setDefaultAutoSelectFamily(false);
|
|
20
25
|
|
|
21
26
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
22
27
|
const args = process.argv.slice(2);
|
|
@@ -28,7 +33,7 @@ const VERSION = (() => {
|
|
|
28
33
|
} catch {
|
|
29
34
|
return "?";
|
|
30
35
|
}
|
|
31
|
-
})()
|
|
36
|
+
})();;
|
|
32
37
|
|
|
33
38
|
function runBot(botArgs) {
|
|
34
39
|
const child = spawn(process.execPath, [join(HERE, "bot.mjs"), ...botArgs], {
|
|
@@ -56,7 +61,7 @@ function resolveConfig(arg) {
|
|
|
56
61
|
return existsSync(join(process.cwd(), arg)) ? join(process.cwd(), arg) : join(HERE, arg);
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
function main() {
|
|
64
|
+
async function main() {
|
|
60
65
|
if (a === "-h" || a === "--help") {
|
|
61
66
|
console.log(
|
|
62
67
|
`ctb v${VERSION} — claude-telegram-bot short CLI\n\n` +
|
|
@@ -122,9 +127,20 @@ function main() {
|
|
|
122
127
|
sessionId = JSON.parse(readFileSync(statePath, "utf8")).sessionId;
|
|
123
128
|
} catch {}
|
|
124
129
|
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
if (sessionId) {
|
|
131
|
+
process.stderr.write(`Resuming session: ${sessionId}\n`);
|
|
132
|
+
// 텔레그램 이전 대화와 구분하기 위해 세션에 시작 마커 삽입
|
|
133
|
+
await new Promise((resolve) => {
|
|
134
|
+
const marker = spawn("claude", [
|
|
135
|
+
"--resume", sessionId, "-p", "---ctb:start---", "--output-format", "json",
|
|
136
|
+
], { stdio: ["ignore", "ignore", "ignore"] });
|
|
137
|
+
marker.on("close", resolve);
|
|
138
|
+
marker.on("error", resolve);
|
|
139
|
+
setTimeout(() => { marker.kill(); resolve(); }, 15000);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
127
142
|
|
|
143
|
+
const finalArgs = sessionId ? ["--resume", sessionId, ...claudeArgs] : claudeArgs;
|
|
128
144
|
const child = spawn("claude", finalArgs, { stdio: "inherit" });
|
|
129
145
|
child.on("close", async (code) => {
|
|
130
146
|
cleanup();
|
|
@@ -135,8 +151,8 @@ function main() {
|
|
|
135
151
|
|
|
136
152
|
async function summarizeSession(sid, lang) {
|
|
137
153
|
const langInstruction = lang && lang.startsWith("ko")
|
|
138
|
-
? "한국어로 짧은 구문(10단어 이내)으로
|
|
139
|
-
: "
|
|
154
|
+
? "---ctb:start--- 마커 이후에 이 터미널 세션에서 한 작업을 한국어로 짧은 구문(10단어 이내)으로 요약해줘. 마크다운 없이 텍스트만. 마커 이후 중요한 작업이 없으면 정확히 이렇게만 답해: SKIP"
|
|
155
|
+
: "After the ---ctb:start--- marker in this conversation, what was accomplished in this terminal session? One short phrase, 10 words max, plain text. If nothing significant after the marker, reply: SKIP";
|
|
140
156
|
return new Promise((resolve) => {
|
|
141
157
|
const child = spawn("claude", [
|
|
142
158
|
"--resume", sid,
|
|
@@ -160,14 +176,22 @@ async function notifyTelegram(configPath, sessionId) {
|
|
|
160
176
|
try {
|
|
161
177
|
const cfg = JSON.parse(readFileSync(configPath, "utf8"));
|
|
162
178
|
if (!cfg.token || !cfg.allowedChatId || cfg.ctbNotify === false) return;
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
await
|
|
179
|
+
const lang = cfg.lang || process.env.LANG || "";
|
|
180
|
+
process.stderr.write("ctb: summarizing session...\n");
|
|
181
|
+
const summary = await summarizeSession(sessionId, lang);
|
|
182
|
+
if (!summary) { process.stderr.write("ctb: nothing to summarize (SKIP)\n"); return; }
|
|
183
|
+
process.stderr.write(`ctb: sending to Telegram — ${summary}\n`);
|
|
184
|
+
const label = lang.startsWith("ko") ? "[터미널]" : "[local]";
|
|
185
|
+
const r = await fetch(`https://api.telegram.org/bot${cfg.token}/sendMessage`, {
|
|
166
186
|
method: "POST",
|
|
167
187
|
headers: { "content-type": "application/json" },
|
|
168
|
-
body: JSON.stringify({ chat_id: cfg.allowedChatId, text: `💻 ${summary}` }),
|
|
188
|
+
body: JSON.stringify({ chat_id: cfg.allowedChatId, text: `💻 ${label} ${summary}` }),
|
|
169
189
|
});
|
|
170
|
-
|
|
190
|
+
const json = await r.json();
|
|
191
|
+
if (!json.ok) process.stderr.write(`ctb: Telegram error — ${JSON.stringify(json)}\n`);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
process.stderr.write(`ctb: notify error — ${e.message}\n`);
|
|
194
|
+
}
|
|
171
195
|
}
|
|
172
196
|
|
|
173
197
|
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-telegram-bot",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
4
4
|
"description": "Drive Claude Code from Telegram — messages run headless `claude -p` in a project dir and replies come back to the chat. Zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|