@gonzih/cc-tg 0.1.2 → 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) => {
@@ -89,6 +92,7 @@ export class CcTgBot {
89
92
  // Ignore `assistant` streaming chunks to avoid duplicates.
90
93
  if (msg.type !== "result")
91
94
  return;
95
+ this.stopTyping(session);
92
96
  const text = extractText(msg);
93
97
  if (!text)
94
98
  return;
@@ -98,6 +102,20 @@ export class CcTgBot {
98
102
  clearTimeout(session.flushTimer);
99
103
  session.flushTimer = setTimeout(() => this.flushPending(chatId, session), FLUSH_DELAY_MS);
100
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
+ }
101
119
  flushPending(chatId, session) {
102
120
  const text = session.pendingText.trim();
103
121
  session.pendingText = "";
@@ -116,6 +134,7 @@ export class CcTgBot {
116
134
  killSession(chatId) {
117
135
  const session = this.sessions.get(chatId);
118
136
  if (session) {
137
+ this.stopTyping(session);
119
138
  session.claude.kill();
120
139
  this.sessions.delete(chatId);
121
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-tg",
3
- "version": "0.1.2",
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": {