claude-telegram-bot 0.3.9 → 0.3.11

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.
Files changed (2) hide show
  1. package/ctb.mjs +14 -6
  2. package/package.json +1 -1
package/ctb.mjs CHANGED
@@ -109,8 +109,13 @@ function main() {
109
109
  writeFileSync(lockPath, String(process.pid));
110
110
  const cleanup = () => { try { unlinkSync(lockPath); } catch {} };
111
111
  process.on("exit", cleanup);
112
- process.on("SIGINT", () => { cleanup(); process.exit(130); });
113
- process.on("SIGTERM", () => { cleanup(); process.exit(143); });
112
+
113
+ // SIGINT/SIGTERM: 종료 코드만 기록하고 exit 하지 않음.
114
+ // claude 도 같은 프로세스 그룹이라 동시에 신호를 받아 종료되고,
115
+ // child.on("close") 가 발화하면서 알림 전송 후 종료함.
116
+ let signalExitCode = null;
117
+ process.on("SIGINT", () => { signalExitCode = 130; });
118
+ process.on("SIGTERM", () => { signalExitCode = 143; });
114
119
 
115
120
  let sessionId;
116
121
  try {
@@ -124,15 +129,18 @@ function main() {
124
129
  child.on("close", async (code) => {
125
130
  cleanup();
126
131
  if (sessionId) await notifyTelegram(configPath, sessionId);
127
- process.exit(code ?? 0);
132
+ process.exit(signalExitCode ?? code ?? 0);
128
133
  });
129
134
  }
130
135
 
131
- async function summarizeSession(sid) {
136
+ async function summarizeSession(sid, lang) {
137
+ const langInstruction = lang && lang.startsWith("ko")
138
+ ? "한국어로 짧은 구문(10단어 이내)으로 이 세션에서 한 작업을 요약해줘. 마크다운 없이 텍스트만. 중요한 작업이 없으면 정확히 이렇게만 답해: SKIP"
139
+ : "In one short phrase (10 words max), what was done this session? Plain text only. If nothing significant, reply: SKIP";
132
140
  return new Promise((resolve) => {
133
141
  const child = spawn("claude", [
134
142
  "--resume", sid,
135
- "-p", "Summarize what was accomplished in this session in one short sentence. Plain text only, no markdown, no filler. If nothing significant happened, reply with exactly: SKIP",
143
+ "-p", langInstruction,
136
144
  "--output-format", "json",
137
145
  ], { stdio: ["ignore", "pipe", "ignore"] });
138
146
  let out = "";
@@ -152,7 +160,7 @@ async function notifyTelegram(configPath, sessionId) {
152
160
  try {
153
161
  const cfg = JSON.parse(readFileSync(configPath, "utf8"));
154
162
  if (!cfg.token || !cfg.allowedChatId || cfg.ctbNotify === false) return;
155
- const summary = await summarizeSession(sessionId);
163
+ const summary = await summarizeSession(sessionId, cfg.lang);
156
164
  if (!summary) return;
157
165
  await fetch(`https://api.telegram.org/bot${cfg.token}/sendMessage`, {
158
166
  method: "POST",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-telegram-bot",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
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": {