@gonzih/cc-tg 0.1.1 → 0.1.3

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
@@ -17,6 +17,8 @@ export declare class CcTgBot {
17
17
  private handleTelegram;
18
18
  private getOrCreateSession;
19
19
  private handleClaudeMessage;
20
+ private startTyping;
21
+ private stopTyping;
20
22
  private flushPending;
21
23
  private killSession;
22
24
  stop(): void;
package/dist/bot.js CHANGED
@@ -5,6 +5,7 @@
5
5
  import TelegramBot from "node-telegram-bot-api";
6
6
  import { ClaudeProcess, extractText } from "./claude.js";
7
7
  const FLUSH_DELAY_MS = 800; // debounce streaming chunks into one Telegram message
8
+ const TYPING_INTERVAL_MS = 4000; // re-send typing action before Telegram's 5s expiry
8
9
  export class CcTgBot {
9
10
  bot;
10
11
  sessions = new Map();
@@ -46,6 +47,7 @@ export class CcTgBot {
46
47
  const session = this.getOrCreateSession(chatId);
47
48
  try {
48
49
  session.claude.sendPrompt(text);
50
+ this.startTyping(chatId, session);
49
51
  }
50
52
  catch (err) {
51
53
  await this.bot.sendMessage(chatId, `Error sending to Claude: ${err.message}`);
@@ -64,6 +66,7 @@ export class CcTgBot {
64
66
  claude,
65
67
  pendingText: "",
66
68
  flushTimer: null,
69
+ typingTimer: null,
67
70
  };
68
71
  claude.on("message", (msg) => this.handleClaudeMessage(chatId, session, msg));
69
72
  claude.on("stderr", (data) => {
@@ -85,8 +88,11 @@ export class CcTgBot {
85
88
  return session;
86
89
  }
87
90
  handleClaudeMessage(chatId, session, msg) {
88
- if (msg.type !== "assistant" && msg.type !== "result")
91
+ // Use only the final `result` message — it contains the complete response text.
92
+ // Ignore `assistant` streaming chunks to avoid duplicates.
93
+ if (msg.type !== "result")
89
94
  return;
95
+ this.stopTyping(session);
90
96
  const text = extractText(msg);
91
97
  if (!text)
92
98
  return;
@@ -96,6 +102,20 @@ export class CcTgBot {
96
102
  clearTimeout(session.flushTimer);
97
103
  session.flushTimer = setTimeout(() => this.flushPending(chatId, session), FLUSH_DELAY_MS);
98
104
  }
105
+ startTyping(chatId, session) {
106
+ this.stopTyping(session);
107
+ // Send immediately, then keep alive every 4s
108
+ this.bot.sendChatAction(chatId, "typing").catch(() => { });
109
+ session.typingTimer = setInterval(() => {
110
+ this.bot.sendChatAction(chatId, "typing").catch(() => { });
111
+ }, TYPING_INTERVAL_MS);
112
+ }
113
+ stopTyping(session) {
114
+ if (session.typingTimer) {
115
+ clearInterval(session.typingTimer);
116
+ session.typingTimer = null;
117
+ }
118
+ }
99
119
  flushPending(chatId, session) {
100
120
  const text = session.pendingText.trim();
101
121
  session.pendingText = "";
@@ -114,6 +134,7 @@ export class CcTgBot {
114
134
  killSession(chatId) {
115
135
  const session = this.sessions.get(chatId);
116
136
  if (session) {
137
+ this.stopTyping(session);
117
138
  session.claude.kill();
118
139
  this.sessions.delete(chatId);
119
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-tg",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Claude Code Telegram bot — chat with Claude Code via Telegram",
5
5
  "type": "module",
6
6
  "bin": {