Add bots files handling logic
This commit is contained in:
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user