claude-tg 1.0.6 → 1.0.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.
package/bin/claude-tg.js CHANGED
@@ -276,15 +276,21 @@ program
276
276
  const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
277
277
  const hooks = settings.hooks || {};
278
278
 
279
+ // Extract script path from hook command (handles optional env prefix)
280
+ function extractScriptPath(cmd) {
281
+ const match = cmd.match(/node\s+(.+)$/);
282
+ return match ? match[1].trim() : null;
283
+ }
284
+
279
285
  const permHooks = hooks.PermissionRequest || [];
280
286
  const permCmd = permHooks[0]?.hooks?.[0]?.command || 'NOT FOUND';
281
287
  console.log(` PermissionRequest: ${permCmd}`);
282
288
  if (permCmd !== 'NOT FOUND') {
283
- const scriptPath = permCmd.replace(/^node\s+/, '');
284
- if (fs.existsSync(scriptPath)) {
289
+ const scriptPath = extractScriptPath(permCmd);
290
+ if (scriptPath && fs.existsSync(scriptPath)) {
285
291
  console.log(' File exists: YES');
286
292
  } else {
287
- console.log(` File exists: NO — ${scriptPath}`);
293
+ console.log(` File exists: NO — ${scriptPath || permCmd}`);
288
294
  ok = false;
289
295
  }
290
296
  }
@@ -293,11 +299,11 @@ program
293
299
  const notifCmd = notifHooks[0]?.hooks?.[0]?.command || 'NOT FOUND';
294
300
  console.log(` Notification: ${notifCmd}`);
295
301
  if (notifCmd !== 'NOT FOUND') {
296
- const scriptPath = notifCmd.replace(/^node\s+/, '');
297
- if (fs.existsSync(scriptPath)) {
302
+ const scriptPath = extractScriptPath(notifCmd);
303
+ if (scriptPath && fs.existsSync(scriptPath)) {
298
304
  console.log(' File exists: YES');
299
305
  } else {
300
- console.log(` File exists: NO — ${scriptPath}`);
306
+ console.log(` File exists: NO — ${scriptPath || notifCmd}`);
301
307
  ok = false;
302
308
  }
303
309
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-tg",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Control Claude Code from Telegram — approve permissions, answer questions, reply to idle sessions, send files, all from your phone",
5
5
  "bin": {
6
6
  "claude-tg": "./bin/claude-tg.js"
package/src/daemon.js CHANGED
@@ -93,7 +93,12 @@ function isTtyAlive(ttyPath) {
93
93
  * Escape a string for use inside AppleScript double-quoted strings.
94
94
  */
95
95
  function escapeAppleScript(str) {
96
- return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
96
+ return str
97
+ .replace(/\\/g, '\\\\')
98
+ .replace(/"/g, '\\"')
99
+ .replace(/\n/g, '\\n')
100
+ .replace(/\r/g, '\\r')
101
+ .replace(/\t/g, '\\t');
97
102
  }
98
103
 
99
104
  /**
@@ -450,9 +455,13 @@ async function sendElicitationQuestion(elicId) {
450
455
  }
451
456
 
452
457
  const keyboard = Markup.inlineKeyboard(rows);
453
- const sent = await bot.telegram.sendMessage(config.chatId, msg, keyboard);
454
- elic.telegramMessageIds.push(sent.message_id);
455
- elic.currentMessageId = sent.message_id;
458
+ try {
459
+ const sent = await bot.telegram.sendMessage(config.chatId, msg, keyboard);
460
+ elic.telegramMessageIds.push(sent.message_id);
461
+ elic.currentMessageId = sent.message_id;
462
+ } catch (err) {
463
+ log(`Elicitation question send failed: ${err.message}`);
464
+ }
456
465
  }
457
466
 
458
467
  /**
@@ -493,8 +502,12 @@ async function sendElicitationSummary(elicId) {
493
502
  }
494
503
  const keyboard = Markup.inlineKeyboard(summaryButtons);
495
504
 
496
- const sent = await bot.telegram.sendMessage(config.chatId, msg, keyboard);
497
- elic.telegramMessageIds.push(sent.message_id);
505
+ try {
506
+ const sent = await bot.telegram.sendMessage(config.chatId, msg, keyboard);
507
+ elic.telegramMessageIds.push(sent.message_id);
508
+ } catch (err) {
509
+ log(`Elicitation summary send failed: ${err.message}`);
510
+ }
498
511
  }
499
512
 
500
513
  /**
@@ -591,14 +604,18 @@ async function handleElicitationCallback(ctx, cbData) {
591
604
  try { await ctx.editMessageReplyMarkup(undefined); } catch {}
592
605
  try { await ctx.editMessageText(ctx.callbackQuery.message.text + '\n\n✏️ Selected: Custom'); } catch {}
593
606
 
594
- const prompt = await bot.telegram.sendMessage(
595
- config.chatId,
596
- `✏️ Type your custom answer for: "${q.question}"\n\nReply to this message with your answer.`
597
- );
598
-
599
- elic.customWaitingMessageId = prompt.message_id;
600
- elic.customWaitingQIdx = qIdx;
601
- elic.telegramMessageIds.push(prompt.message_id);
607
+ try {
608
+ const prompt = await bot.telegram.sendMessage(
609
+ config.chatId,
610
+ `✏️ Type your custom answer for: "${q.question}"\n\nReply to this message with your answer.`
611
+ );
612
+
613
+ elic.customWaitingMessageId = prompt.message_id;
614
+ elic.customWaitingQIdx = qIdx;
615
+ elic.telegramMessageIds.push(prompt.message_id);
616
+ } catch (err) {
617
+ log(`Elicitation custom prompt send failed: ${err.message}`);
618
+ }
602
619
  log(`Elicitation ${elicId}: waiting for custom answer to q${qIdx}`);
603
620
  return;
604
621
  }
@@ -909,6 +926,9 @@ function startBot() {
909
926
  } else if (action === 'always') {
910
927
  label = '✅ Always Allowed';
911
928
  pending.resolve({ decision: 'always' });
929
+ } else {
930
+ label = '❌ Denied';
931
+ pending.resolve({ decision: 'deny' });
912
932
  }
913
933
 
914
934
  try { await ctx.answerCbQuery(label); } catch {}
@@ -1056,7 +1076,13 @@ async function sendPermissionRequest(data) {
1056
1076
  Markup.button.callback('Always Allow', `${rid}:always`),
1057
1077
  ]);
1058
1078
 
1059
- const sent = await bot.telegram.sendMessage(config.chatId, msg, keyboard);
1079
+ let sent;
1080
+ try {
1081
+ sent = await bot.telegram.sendMessage(config.chatId, msg, keyboard);
1082
+ } catch (err) {
1083
+ log(`Permission send failed: ${err.message}`);
1084
+ return { decision: 'allow' }; // Fallback: allow if Telegram unreachable
1085
+ }
1060
1086
 
1061
1087
  // Track this message for reply routing
1062
1088
  messageToSession.set(sent.message_id, {