Add bots files handling logic

This commit is contained in:
2026-10-21 17:56:09 +01:00
parent b0af4db1bf
commit d17a4a7bdd
97 changed files with 5843 additions and 41 deletions
@@ -13,6 +13,11 @@ type Params = {
workspace_id?: number | null;
text: string;
needs_you?: boolean;
/**
* Files the bot saved and sent with it (`media` ids): a PDF it made, a
* generated image, a document it wrote.
*/
media_ids?: number[];
};
/**
@@ -25,6 +30,7 @@ export default async function insertBotMessage({
workspace_id,
text,
needs_you,
media_ids = [],
}: Params): Promise<BUN_SQLITE_COBBLE_BOT_MESSAGES> {
const now = Date.now();
const needs_you_flag = needs_you ? 1 : 0;
@@ -52,6 +58,13 @@ export default async function insertBotMessage({
throw new Error(`Failed to save message: ${res.msg}`);
}
for (const media_id of media_ids) {
await BunSQLite.sql({
sql: `INSERT INTO bot_message_media (created_at, updated_at, message_id, media_id) VALUES (?, ?, ?, ?)`,
values: [now, now, id, media_id],
}).catch(() => {});
}
await BunSQLite.sql({
sql: `UPDATE bot_sessions SET last_activity_at = ?, unread = 1 WHERE id = ?`,
values: [now, session_id],