import { resolveBlueBubblesServerAccount } from "./account-resolve.js"; import { createBlueBubblesClientFromParts } from "./client.js"; import type { OpenClawConfig } from "./runtime-api.js";
export type BlueBubblesHistoryFetchResult = {
entries: BlueBubblesHistoryEntry[]; /** * True when at least one API path returned a recognized response shape. * False means all attempts failed or returned unusable data.
*/
resolved: boolean;
};
function clampHistoryLimit(limit: number): number { if (!Number.isFinite(limit)) { return0;
} const normalized = Math.floor(limit); if (normalized <= 0) { return0;
} return Math.min(normalized, MAX_HISTORY_FETCH_LIMIT);
}
function truncateHistoryBody(text: string): string { if (text.length <= MAX_HISTORY_BODY_CHARS) { return text;
} return `${text.slice(0, MAX_HISTORY_BODY_CHARS).trimEnd()}...`;
}
/** * Fetch message history from BlueBubbles API for a specific chat. * This provides the initial backfill for both group chats and DMs.
*/
export async function fetchBlueBubblesHistory(
chatIdentifier: string,
limit: number,
opts: BlueBubblesChatOpts = {},
): Promise<BlueBubblesHistoryFetchResult> { const effectiveLimit = clampHistoryLimit(limit); if (!chatIdentifier.trim() || effectiveLimit <= 0) { return { entries: [], resolved: true };
}
// Try different common API patterns for fetching messages const possiblePaths = [
`/api/v1/chat/${encodeURIComponent(chatIdentifier)}/messages?limit=${effectiveLimit}&sort=DESC`,
`/api/v1/messages?chatGuid=${encodeURIComponent(chatIdentifier)}&limit=${effectiveLimit}`,
`/api/v1/chat/${encodeURIComponent(chatIdentifier)}/message?limit=${effectiveLimit}`,
];
for (const path of possiblePaths) { try { const res = await client.request({
method: "GET",
path,
timeoutMs: opts.timeoutMs ?? 10000,
});
if (!res.ok) { continue; // Try next path
}
const data = await res.json().catch(() => null); if (!data) { continue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.