diff --git a/extensions/bluebubbles/src/history.ts b/extensions/bluebubbles/src/history.ts index 29f6d7db695..c72d8387ac8 100644 --- a/extensions/bluebubbles/src/history.ts +++ b/extensions/bluebubbles/src/history.ts @@ -63,8 +63,12 @@ export async function fetchBlueBubblesHistory( for (const path of possiblePaths) { try { const url = buildBlueBubblesApiUrl({ baseUrl, path, password }); - const res = await blueBubblesFetchWithTimeout(url, { method: "GET" }, opts.timeoutMs ?? 10000); - + const res = await blueBubblesFetchWithTimeout( + url, + { method: "GET" }, + opts.timeoutMs ?? 10000, + ); + if (!res.ok) { continue; // Try next path } @@ -87,10 +91,10 @@ export async function fetchBlueBubblesHistory( } const historyEntries: BlueBubblesHistoryEntry[] = []; - + for (const item of messages) { const msg = item as BlueBubblesMessageData; - + // Skip messages without text content const text = msg.text?.trim(); if (!text) { @@ -102,7 +106,8 @@ export async function fetchBlueBubblesHistory( continue; } - const sender = msg.sender?.display_name || msg.sender?.address || msg.handle_id || "Unknown"; + const sender = + msg.sender?.display_name || msg.sender?.address || msg.handle_id || "Unknown"; const timestamp = msg.date_created || msg.date_delivered; historyEntries.push({ @@ -142,4 +147,4 @@ export function buildInboundHistoryFromEntries( body: entry.body, timestamp: entry.timestamp, })); -} \ No newline at end of file +} diff --git a/extensions/bluebubbles/src/monitor-processing.ts b/extensions/bluebubbles/src/monitor-processing.ts index 5d0bdd29714..189223ed268 100644 --- a/extensions/bluebubbles/src/monitor-processing.ts +++ b/extensions/bluebubbles/src/monitor-processing.ts @@ -10,6 +10,11 @@ import { } from "openclaw/plugin-sdk"; import { downloadBlueBubblesAttachment } from "./attachments.js"; import { markBlueBubblesChatRead, sendBlueBubblesTyping } from "./chat.js"; +import { + fetchBlueBubblesHistory, + buildInboundHistoryFromEntries, + type BlueBubblesHistoryEntry, +} from "./history.js"; import { sendBlueBubblesMedia } from "./media-send.js"; import { buildMessagePlaceholder, @@ -37,11 +42,6 @@ import { getCachedBlueBubblesPrivateApiStatus } from "./probe.js"; import { normalizeBlueBubblesReactionInput, sendBlueBubblesReaction } from "./reactions.js"; import { resolveChatGuidForTarget, sendMessageBlueBubbles } from "./send.js"; import { formatBlueBubblesChatTarget, isAllowedBlueBubblesSender } from "./targets.js"; -import { - fetchBlueBubblesHistory, - buildInboundHistoryFromEntries, - type BlueBubblesHistoryEntry, -} from "./history.js"; const DEFAULT_TEXT_LIMIT = 4000; const invalidAckReactions = new Set(); @@ -819,40 +819,37 @@ export async function processMessage( }; // Fetch history for backfill (both groups and DMs) - const historyLimit = isGroup + const historyLimit = isGroup ? (account.config.historyLimit ?? 0) : (account.config.dmHistoryLimit ?? 0); - + let inboundHistory: Array<{ sender: string; body: string; timestamp?: number }> | undefined; - + if (historyLimit > 0) { // Determine chat identifier for history fetching - const historyIdentifier = chatGuid || - chatIdentifier || + const historyIdentifier = + chatGuid || + chatIdentifier || (chatId ? String(chatId) : null) || (isGroup ? null : message.senderId); - + if (historyIdentifier) { try { const historyEntries = await fetchBlueBubblesHistory(historyIdentifier, historyLimit, { cfg: config, accountId: account.accountId, }); - + if (historyEntries.length > 0) { inboundHistory = buildInboundHistoryFromEntries(historyEntries); logVerbose( core, runtime, - `fetched ${historyEntries.length} history messages for ${isGroup ? 'group' : 'DM'}: ${historyIdentifier}` + `fetched ${historyEntries.length} history messages for ${isGroup ? "group" : "DM"}: ${historyIdentifier}`, ); } } catch (err) { - logVerbose( - core, - runtime, - `history fetch failed for ${historyIdentifier}: ${String(err)}` - ); + logVerbose(core, runtime, `history fetch failed for ${historyIdentifier}: ${String(err)}`); } } }