@gonzih/cc-tg 0.9.47 → 0.9.48

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/dist/bot.d.ts CHANGED
@@ -62,6 +62,13 @@ export declare class CcTgBot {
62
62
  * Called by the notifier when a UI message arrives via Redis pub/sub.
63
63
  */
64
64
  handleUserMessage(chatId: number, text: string): Promise<void>;
65
+ /**
66
+ * Forward a cc-agent job notification into an existing Claude session.
67
+ * Unlike handleUserMessage, this never creates a new session — if no session
68
+ * is active for the chatId, the notification is already visible in Telegram
69
+ * and we silently skip feeding it into Claude.
70
+ */
71
+ forwardNotification(chatId: number, text: string): void;
65
72
  private handleVoice;
66
73
  private handleVoiceRetry;
67
74
  private handlePhoto;
package/dist/bot.js CHANGED
@@ -526,6 +526,25 @@ export class CcTgBot {
526
526
  this.killSession(chatId, true);
527
527
  }
528
528
  }
529
+ /**
530
+ * Forward a cc-agent job notification into an existing Claude session.
531
+ * Unlike handleUserMessage, this never creates a new session — if no session
532
+ * is active for the chatId, the notification is already visible in Telegram
533
+ * and we silently skip feeding it into Claude.
534
+ */
535
+ forwardNotification(chatId, text) {
536
+ const key = this.sessionKey(chatId);
537
+ const session = this.sessions.get(key);
538
+ if (!session || session.claude.exited)
539
+ return;
540
+ try {
541
+ session.claude.sendPrompt(stampPrompt(text));
542
+ this.writeChatMessage("user", "cc-tg", text, chatId);
543
+ }
544
+ catch (err) {
545
+ console.error(`[forwardNotification:${chatId}] failed:`, err.message);
546
+ }
547
+ }
529
548
  async handleVoice(chatId, msg, threadId, threadName) {
530
549
  const fileId = msg.voice?.file_id ?? msg.audio?.file_id;
531
550
  if (!fileId)
package/dist/index.js CHANGED
@@ -142,8 +142,9 @@ const notifyChatId = process.env.CC_AGENT_NOTIFY_CHAT_ID
142
142
  // Mutable placeholder closures — filled in once `bot` is created below.
143
143
  let getLastActiveChatIdFn = () => undefined;
144
144
  let handleUserMessageFn;
145
+ let forwardNotificationFn;
145
146
  const notifierBot = new TelegramBot(telegramToken, { polling: false });
146
- const notifier = startNotifier(notifierBot, notifyChatId, namespace, sharedRedis, (cid, text) => handleUserMessageFn?.(cid, text), () => getLastActiveChatIdFn());
147
+ const notifier = startNotifier(notifierBot, notifyChatId, namespace, sharedRedis, (cid, text) => handleUserMessageFn?.(cid, text), (cid, text) => forwardNotificationFn?.(cid, text), () => getLastActiveChatIdFn());
147
148
  console.log(`[notifier] started for namespace=${namespace} chatId=${notifyChatId ?? "dynamic"}`);
148
149
  const bot = new CcTgBot({
149
150
  telegramToken,
@@ -158,6 +159,7 @@ const bot = new CcTgBot({
158
159
  // Wire closures now that bot is constructed
159
160
  getLastActiveChatIdFn = () => bot.getLastActiveChatId();
160
161
  handleUserMessageFn = (cid, text) => { void bot.handleUserMessage(cid, text); };
162
+ forwardNotificationFn = (cid, text) => { bot.forwardNotification(cid, text); };
161
163
  if (process.env.CC_AGENT_OPS_PORT) {
162
164
  const botInfo = await bot.getMe();
163
165
  const registry = new Registry(sharedRedis);
@@ -51,9 +51,10 @@ export interface NotifierHandle {
51
51
  * @param chatId - Telegram chat ID to forward notifications to. Pass null to use getActiveChatId.
52
52
  * @param namespace - cc-agent namespace (used to build Redis channel names)
53
53
  * @param redis - ioredis client in normal mode (will be duplicated for pub/sub)
54
- * @param handleUserMessage - Optional callback to feed UI messages into the active Claude session
55
- * @param getActiveChatId - Optional callback to resolve chatId dynamically (used when chatId is null)
54
+ * @param handleUserMessage - Optional callback to feed UI messages into the active Claude session
55
+ * @param forwardNotification - Optional callback to forward job notifications to an existing Claude session only (no session creation)
56
+ * @param getActiveChatId - Optional callback to resolve chatId dynamically (used when chatId is null)
56
57
  *
57
58
  * @returns NotifierHandle with registerRoutedChatId for per-namespace response routing
58
59
  */
59
- export declare function startNotifier(bot: TelegramBot, chatId: number | null, namespace: string, redis: Redis, handleUserMessage?: (chatId: number, text: string) => void, getActiveChatId?: () => number | undefined): NotifierHandle;
60
+ export declare function startNotifier(bot: TelegramBot, chatId: number | null, namespace: string, redis: Redis, handleUserMessage?: (chatId: number, text: string) => void, forwardNotification?: (chatId: number, text: string) => void, getActiveChatId?: () => number | undefined): NotifierHandle;
package/dist/notifier.js CHANGED
@@ -98,12 +98,13 @@ export function writeChatLog(redis, namespace, msg) {
98
98
  * @param chatId - Telegram chat ID to forward notifications to. Pass null to use getActiveChatId.
99
99
  * @param namespace - cc-agent namespace (used to build Redis channel names)
100
100
  * @param redis - ioredis client in normal mode (will be duplicated for pub/sub)
101
- * @param handleUserMessage - Optional callback to feed UI messages into the active Claude session
102
- * @param getActiveChatId - Optional callback to resolve chatId dynamically (used when chatId is null)
101
+ * @param handleUserMessage - Optional callback to feed UI messages into the active Claude session
102
+ * @param forwardNotification - Optional callback to forward job notifications to an existing Claude session only (no session creation)
103
+ * @param getActiveChatId - Optional callback to resolve chatId dynamically (used when chatId is null)
103
104
  *
104
105
  * @returns NotifierHandle with registerRoutedChatId for per-namespace response routing
105
106
  */
106
- export function startNotifier(bot, chatId, namespace, redis, handleUserMessage, getActiveChatId) {
107
+ export function startNotifier(bot, chatId, namespace, redis, handleUserMessage, forwardNotification, getActiveChatId) {
107
108
  // Per-namespace chatId registry: when a message is routed to a non-default namespace,
108
109
  // the originating Telegram chatId is registered here so responses go back to the right chat.
109
110
  const routedChatIds = new Map();
@@ -238,8 +239,8 @@ export function startNotifier(bot, chatId, namespace, redis, handleUserMessage,
238
239
  bot.sendMessage(targetId, text).catch((err) => {
239
240
  log("warn", "notify list sendMessage failed:", err.message);
240
241
  });
241
- if (handleUserMessage) {
242
- handleUserMessage(targetId, text);
242
+ if (forwardNotification) {
243
+ forwardNotification(targetId, text);
243
244
  }
244
245
  }
245
246
  if (remaining > 0) {
@@ -261,8 +262,8 @@ export function startNotifier(bot, chatId, namespace, redis, handleUserMessage,
261
262
  bot.sendMessage(targetId, text).catch((err) => {
262
263
  log("warn", "sendMessage failed:", err.message);
263
264
  });
264
- if (handleUserMessage) {
265
- handleUserMessage(targetId, text);
265
+ if (forwardNotification) {
266
+ forwardNotification(targetId, text);
266
267
  }
267
268
  }
268
269
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-tg",
3
- "version": "0.9.47",
3
+ "version": "0.9.48",
4
4
  "description": "Claude Code Telegram bot — chat with Claude Code via Telegram",
5
5
  "type": "module",
6
6
  "bin": {