claude-telegram-bot 0.3.5 → 0.3.7

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/bot.mjs +20 -10
  2. package/package.json +1 -1
package/bot.mjs CHANGED
@@ -454,6 +454,20 @@ async function send(chatId, text) {
454
454
  }
455
455
  }
456
456
 
457
+ // ── Claude 에러 분류 ──────────────────────────────────────────────────────
458
+ function classifyClaudeError(raw, code) {
459
+ const t = raw.toLowerCase();
460
+ if (t.includes("credit") || t.includes("balance") || t.includes("billing") || t.includes("payment"))
461
+ return "💳 API 크레딧이 부족합니다. console.anthropic.com 에서 충전해주세요.";
462
+ if (t.includes("rate_limit") || t.includes("rate limit") || t.includes("too many requests") || code === 429)
463
+ return "⏱️ 요청이 너무 많습니다. 잠시 후 다시 시도해주세요.";
464
+ if (t.includes("overloaded") || code === 529)
465
+ return "🔄 Claude 서버가 일시적으로 과부하 상태입니다. 잠시 후 다시 시도해주세요.";
466
+ if (t.includes("context") && (t.includes("length") || t.includes("limit") || t.includes("window")))
467
+ return "📏 대화 맥락이 너무 길어졌습니다. `/new` 로 새 세션을 시작해주세요.";
468
+ return `Execution error (exit ${code}):\n${raw}`;
469
+ }
470
+
457
471
  // ── Claude 실행 ───────────────────────────────────────────────────────────
458
472
  function runClaude(prompt, sessionId, opts = {}) {
459
473
  return new Promise((resolve) => {
@@ -504,17 +518,13 @@ function runClaude(prompt, sessionId, opts = {}) {
504
518
  currentChild = null;
505
519
  try {
506
520
  const j = JSON.parse(out);
507
- resolve({
508
- ok: !j.is_error,
509
- text: j.result ?? "(empty response)",
510
- sessionId: j.session_id,
511
- cost: j.total_cost_usd,
512
- });
521
+ const text = j.is_error
522
+ ? classifyClaudeError(j.result ?? "", code)
523
+ : (j.result ?? "(empty response)");
524
+ resolve({ ok: !j.is_error, text, sessionId: j.session_id, cost: j.total_cost_usd });
513
525
  } catch {
514
- resolve({
515
- ok: false,
516
- text: `Execution error (exit ${code}):\n${(err || out || "no output").slice(0, 3500)}`,
517
- });
526
+ const raw = (err || out || "no output").slice(0, 3500);
527
+ resolve({ ok: false, text: classifyClaudeError(raw, code) });
518
528
  }
519
529
  });
520
530
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-telegram-bot",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
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": {