@thibautrey/chatons-channel-telegram 2.0.0 → 2.0.1

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.
@@ -1,10 +1,4 @@
1
1
  {
2
- "id": "@thibautrey/chatons-channel-telegram",
3
- "name": "Telegram Channel",
4
- "version": "2.0.0",
5
- "description": "Telegram channel bridge for Chatons. Automatically polls for messages, syncs replies, and runs in the background using the shared Chatons UI component library.",
6
- "kind": "channel",
7
- "icon": "icon.svg",
8
2
  "capabilities": [
9
3
  "ui.mainView",
10
4
  "queue.publish",
@@ -14,15 +8,21 @@
14
8
  "host.conversations.read",
15
9
  "host.conversations.write"
16
10
  ],
11
+ "description": "Telegram channel bridge for Chatons. Automatically polls for messages, syncs replies, and runs in the background using the shared Chatons UI component library.",
12
+ "icon": "icon.svg",
13
+ "id": "@thibautrey/chatons-channel-telegram",
14
+ "kind": "channel",
15
+ "name": "Telegram Channel",
17
16
  "ui": {
18
17
  "mainViews": [
19
18
  {
20
- "viewId": "telegram.main",
21
- "title": "Telegram",
22
19
  "icon": "MessageSquareShare",
23
- "webviewUrl": "chaton-extension://@thibautrey/chatons-channel-telegram/index.html",
24
- "initialRoute": "/"
20
+ "initialRoute": "/",
21
+ "title": "Telegram",
22
+ "viewId": "telegram.main",
23
+ "webviewUrl": "chaton-extension://@thibautrey/chatons-channel-telegram/index.html"
25
24
  }
26
25
  ]
27
- }
26
+ },
27
+ "version": "2.0.1"
28
28
  }
package/index.js CHANGED
@@ -307,10 +307,12 @@
307
307
  var key = mappingKeyForChat(chatId);
308
308
  var existing = asRecord(state.mappings[key]);
309
309
  if (existing.chatonsConversationId) {
310
+ console.log('[telegram-ext] ensureConversation: reusing existing conversation', { key: key, conversationId: existing.chatonsConversationId });
310
311
  return { key: key, conversationId: String(existing.chatonsConversationId) };
311
312
  }
312
313
 
313
314
  var chatTitle = msg.chat && (msg.chat.title || msg.chat.username || remoteUserName || ('Telegram ' + chatId));
315
+ console.log('[telegram-ext] ensureConversation: creating new thread', { key: key, chatTitle: chatTitle, modelKey: state.config.modelKey });
314
316
  var res = await hostCall('channels.upsertGlobalThread', {
315
317
  mappingKey: key,
316
318
  title: shorten('Telegram - ' + chatTitle, 72),
@@ -318,19 +320,11 @@
318
320
  });
319
321
 
320
322
  if (!res || !res.ok || !res.data || !res.data.conversation) {
321
- throw new Error((res && res.error && res.error.message) || 'Unable to create conversation');
323
+ console.error('[telegram-ext] upsertGlobalThread response:', JSON.stringify(res, null, 2));
324
+ throw new Error((res && res.error && res.error.message) || 'Unable to create conversation: ' + (res ? JSON.stringify(res) : 'no response'));
322
325
  }
323
326
 
324
- state.mappings[key] = {
325
- remoteThreadId: normalizeChatId(chatId),
326
- remoteChatTitle: chatTitle,
327
- remoteUserId: msg.from && msg.from.id ? String(msg.from.id) : '',
328
- remoteUserName: remoteUserName,
329
- chatonsConversationId: res.data.conversation.id,
330
- createdAt: nowIso(),
331
- updatedAt: nowIso(),
332
- };
333
- await saveMappings();
327
+ console.log('[telegram-ext] ensureConversation: created new conversation', { conversationId: res.data.conversation.id });
334
328
  return { key: key, conversationId: res.data.conversation.id };
335
329
  }
336
330
 
@@ -345,6 +339,14 @@
345
339
  var ensured = await ensureConversationForMessage(msg, remoteUserName);
346
340
  var idempotencyKey = String(update.update_id) + ':' + String(msg.message_id || '0');
347
341
 
342
+ console.log('[telegram-ext] ingestNormalizedMessage: about to ingest', {
343
+ conversationId: ensured.conversationId,
344
+ updateId: update.update_id,
345
+ messageId: msg.message_id,
346
+ idempotencyKey: idempotencyKey,
347
+ textLength: text.length
348
+ });
349
+
348
350
  var ingestRes = await hostCall('channels.ingestMessage', {
349
351
  conversationId: ensured.conversationId,
350
352
  message: text,
@@ -361,7 +363,8 @@
361
363
  });
362
364
 
363
365
  if (!ingestRes || !ingestRes.ok) {
364
- throw new Error((ingestRes && ingestRes.error && ingestRes.error.message) || 'Failed to ingest message');
366
+ console.error('[telegram-ext] ingestMessage response:', JSON.stringify(ingestRes, null, 2));
367
+ throw new Error((ingestRes && ingestRes.error && ingestRes.error.message) || 'Failed to ingest message: ' + (ingestRes ? JSON.stringify(ingestRes) : 'no response'));
365
368
  }
366
369
 
367
370
  state.mappings[mappingKeyForChat(chatId)] = {
@@ -849,7 +852,10 @@
849
852
  host: document.getElementById('modelPickerHost'),
850
853
  onChange: function (modelKey) {
851
854
  state.config.modelKey = modelKey || '';
852
- void persistConfig();
855
+ // Fire-and-forget: don't await, just save in background
856
+ persistConfig().catch(function (err) {
857
+ console.error('[telegram-ext] failed to persist model selection:', err);
858
+ });
853
859
  },
854
860
  labels: {
855
861
  filterPlaceholder: 'Filter models...',
@@ -859,10 +865,12 @@
859
865
  noModels: 'No models available'
860
866
  }
861
867
  });
862
- void window.chaton.listPiModels().then(function (res) {
868
+ window.chaton.listPiModels().then(function (res) {
863
869
  if (!res || !res.ok || !state.modelPicker) return;
864
870
  state.modelPicker.setModels(res.models || []);
865
871
  state.modelPicker.setSelected(state.config.modelKey || null);
872
+ }).catch(function (err) {
873
+ console.error('[telegram-ext] failed to list models:', err);
866
874
  });
867
875
  }
868
876
  }
@@ -880,6 +888,14 @@
880
888
  // Load persisted state
881
889
  await loadPersistedState();
882
890
 
891
+ console.log('[telegram-ext] initialized state:', {
892
+ token: maskToken(state.config.token),
893
+ botUsername: state.config.botUsername,
894
+ connected: state.config.connected,
895
+ modelKey: state.config.modelKey,
896
+ outboundEnabled: state.config.outboundEnabled
897
+ });
898
+
883
899
  // Register render function for background services to call when they update
884
900
  state.uiRenderFn = function () { if (app) render(); };
885
901
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thibautrey/chatons-channel-telegram",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "description": "Telegram channel bridge for Chatons. Automatically polls for messages, syncs replies, and runs in the background using the shared Chatons UI component library.",
6
6
  "main": "index.js",