claude-notification-plugin 1.0.21 → 1.0.23

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/bin/install.js +68 -24
  2. package/package.json +1 -1
package/bin/install.js CHANGED
@@ -80,42 +80,67 @@ async function main () {
80
80
  console.log('==================================');
81
81
  console.log('');
82
82
 
83
- // Telegram setup
84
- let token = '';
85
- let chatId = '';
83
+ // Load existing config
84
+ let existing = {};
85
+ if (fs.existsSync(configPath)) {
86
+ try {
87
+ existing = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
88
+ } catch {
89
+ // ignore malformed config
90
+ }
91
+ }
86
92
 
87
- const useTelegram = await ask(rl, 'Configure Telegram? (y/N): ');
93
+ const existingToken = existing.telegram?.token || '';
94
+ const existingChatId = existing.telegram?.chatId || '';
88
95
 
89
- if (useTelegram.toLowerCase() === 'y') {
90
- token = await ask(rl, 'Bot Token: ');
96
+ // Telegram setup
97
+ let token = existingToken;
98
+ let chatId = existingChatId;
99
+
100
+ if (existingToken) {
101
+ const masked = existingToken.slice(0, 6) + '...' + existingToken.slice(-4);
102
+ console.log(`Telegram token found: ${masked}`);
103
+ const reuse = await ask(rl, 'Keep existing token? (Y/n): ');
104
+ if (reuse.toLowerCase() === 'n') {
105
+ token = await ask(rl, 'New Bot Token: ');
106
+ chatId = ''; // reset chatId when token changes
107
+ }
108
+ } else {
109
+ const useTelegram = await ask(rl, 'Configure Telegram? (y/N): ');
110
+ if (useTelegram.toLowerCase() === 'y') {
111
+ token = await ask(rl, 'Bot Token: ');
112
+ }
113
+ }
91
114
 
92
- if (token) {
93
- console.log('');
94
- console.log('Send any message to your bot in Telegram, then press Enter.');
95
- await ask(rl, '');
115
+ // Fetch chatId if we have a token but no chatId
116
+ if (token && !chatId) {
117
+ console.log('');
118
+ console.log('Send any message to your bot in Telegram, then press Enter.');
119
+ await ask(rl, '');
96
120
 
97
- console.log('Fetching Chat ID...');
98
- chatId = await fetchChatId(token);
121
+ console.log('Fetching Chat ID...');
122
+ chatId = await fetchChatId(token);
99
123
 
100
- if (chatId) {
101
- console.log('Chat ID detected: ' + chatId);
102
- } else {
103
- console.log('Could not detect Chat ID automatically.');
104
- chatId = await ask(rl, 'Enter Chat ID manually: ');
105
- }
124
+ if (chatId) {
125
+ console.log('Chat ID detected: ' + chatId);
126
+ } else {
127
+ console.log('Could not detect Chat ID automatically.');
128
+ chatId = await ask(rl, 'Enter Chat ID manually: ');
106
129
  }
130
+ } else if (token && chatId) {
131
+ console.log(`Chat ID: ${chatId}`);
107
132
  }
108
133
 
109
134
  rl.close();
110
135
 
111
- // Create config
136
+ // Create / update config
112
137
  fs.mkdirSync(claudeDir, { recursive: true });
113
138
 
114
- const config = {
139
+ const defaults = {
115
140
  telegram: {
116
141
  enabled: true,
117
- token,
118
- chatId,
142
+ token: '',
143
+ chatId: '',
119
144
  deleteAfterHours: 24,
120
145
  },
121
146
  windowsNotification: {
@@ -129,8 +154,27 @@ async function main () {
129
154
  enabled: true,
130
155
  },
131
156
  minSeconds: 15,
157
+ notifyOnWaiting: false,
158
+ debug: false,
132
159
  };
133
160
 
161
+ // Merge defaults with existing config (user values take priority)
162
+ const config = { ...defaults, ...existing };
163
+ // Deep-merge nested objects
164
+ for (const key of Object.keys(defaults)) {
165
+ if (defaults[key] && typeof defaults[key] === 'object' && !Array.isArray(defaults[key])) {
166
+ config[key] = { ...defaults[key], ...(existing[key] || {}) };
167
+ }
168
+ }
169
+
170
+ // Apply Telegram credentials from this run (if provided)
171
+ if (token) {
172
+ config.telegram.token = token;
173
+ }
174
+ if (chatId) {
175
+ config.telegram.chatId = chatId;
176
+ }
177
+
134
178
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
135
179
 
136
180
  // Patch settings.json
@@ -163,10 +207,10 @@ async function main () {
163
207
  console.log('');
164
208
  console.log('Config: ' + configPath);
165
209
 
166
- if (token) {
210
+ if (config.telegram.token && config.telegram.chatId) {
167
211
  console.log('Telegram: configured');
168
212
  } else {
169
- console.log('Telegram: skipped (edit config later)');
213
+ console.log('Telegram: not configured (edit config later)');
170
214
  }
171
215
 
172
216
  console.log('');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "claude-notification-plugin",
3
3
  "productName": "claude-notification-plugin",
4
- "version": "1.0.21",
4
+ "version": "1.0.23",
5
5
  "description": "Telegram and Windows notifications for Claude Code task completion",
6
6
  "type": "module",
7
7
  "engines": {