polygram 0.6.2 → 0.6.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.
Files changed (3) hide show
  1. package/lib/db.js +18 -0
  2. package/package.json +1 -1
  3. package/polygram.js +23 -0
package/lib/db.js CHANGED
@@ -463,6 +463,24 @@ function wrap(db) {
463
463
  return db.prepare(sql).all(...args);
464
464
  },
465
465
 
466
+ // Re-FK every attachment whose (chat_id, msg_id) is in `msg_ids` over
467
+ // to a single primary message row. Used when the media-group buffer
468
+ // coalesces N Telegram messages (each carrying one photo of an album)
469
+ // into one synthetic turn — siblings were recorded under their own
470
+ // msg_ids by recordInbound, but Claude needs to see them all under
471
+ // the primary message so handleMessage's per-message attachment
472
+ // lookup returns the full album.
473
+ reassignAttachmentsToMessage({ chat_id, msg_ids, target_message_id }) {
474
+ if (!Array.isArray(msg_ids) || msg_ids.length === 0) return { changes: 0 };
475
+ const placeholders = msg_ids.map(() => '?').join(',');
476
+ return db.prepare(`
477
+ UPDATE attachments
478
+ SET message_id = ?, msg_id = (SELECT msg_id FROM messages WHERE id = ?)
479
+ WHERE chat_id = ? AND msg_id IN (${placeholders})
480
+ AND message_id != ?
481
+ `).run(target_message_id, target_message_id, String(chat_id), ...msg_ids, target_message_id);
482
+ },
483
+
466
484
  // Look up the messages.id auto-pk for an inbound message. Used by
467
485
  // recordInbound to FK attachments to the just-inserted message even
468
486
  // when an ON-CONFLICT update happened (lastInsertRowid is 0 in that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polygram",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Telegram daemon for Claude Code that preserves the OpenClaw per-chat session model. Migration path for OpenClaw users moving to Claude Code.",
5
5
  "main": "lib/ipc-client.js",
6
6
  "bin": {
package/polygram.js CHANGED
@@ -1930,6 +1930,29 @@ function createBot(token) {
1930
1930
  // all-media-no-text groups.
1931
1931
  const primary = messages.find((m) => m.text || m.caption) || messages[0];
1932
1932
  const merged = messages.flatMap((m) => extractAttachments(m));
1933
+
1934
+ // 0.6.0 attachment-table regression fix: recordInbound (called per
1935
+ // sibling on bot.on('message')) inserted each photo's row under its
1936
+ // OWN msg_id. handleMessage looks up attachments via
1937
+ // getAttachmentsByMessage(primary.message_id) — which only returns
1938
+ // the primary's row. Without re-FK'ing the siblings we'd silently
1939
+ // drop N-1 of N photos in any album, exactly the umi-assistant bug
1940
+ // the user hit (saw 1 of 2 photos sent in a Telegram album).
1941
+ const chatId = String(primary.chat.id);
1942
+ const primaryDbId = db.getInboundMessageId({
1943
+ chat_id: chatId, msg_id: primary.message_id,
1944
+ });
1945
+ const siblingMsgIds = messages
1946
+ .filter((m) => m.message_id !== primary.message_id)
1947
+ .map((m) => m.message_id);
1948
+ if (primaryDbId && siblingMsgIds.length) {
1949
+ dbWrite(() => db.reassignAttachmentsToMessage({
1950
+ chat_id: chatId,
1951
+ msg_ids: siblingMsgIds,
1952
+ target_message_id: primaryDbId,
1953
+ }), 'reassign media-group sibling attachments');
1954
+ }
1955
+
1933
1956
  const synthetic = { ...primary, _mergedAttachments: merged };
1934
1957
  // Carry the primary's text verbatim (dispatchRegularMessage re-cleans
1935
1958
  // the mention). Caption → text so downstream sees it uniformly.