A hook call used to record only how it was taken; its run's answer went to the chat alone and was lost to the call once the job was pruned. Now `bot_hook_events` keeps `response`, `response_message_id` and `responded_at`, written on every call a run took in when that run ends (completed, failed, lost, stopped or cancelled) by `recordHookCallResponse` in the job helpers, and calls turn done or failed. The Calls view searches what calls sent and what runs answered, filters by status and pages; Show all loads one call whole. Bots get `search_hook_calls` and `read_hook_call` for their own hooks (never in a hook call's own run), with payloads always marked as outside data. Calls are kept for the app setting `hook_events_keep_days` (Settings > General, default now 30 days). The caller still only gets 202 Queued. Co-Authored-By: Claude Opus 5.5 <[email protected]>
17 lines
627 B
TypeScript
17 lines
627 B
TypeScript
import BunSQLite from "@moduletrace/bun-sqlite";
|
|
import { grabHookEventsKeepDays } from "@/src/functions/backend/db/app-settings/grab-hook-events-keep-days";
|
|
|
|
/**
|
|
* Deletes hook calls (with their responses) older than the install's
|
|
* retention (`grabHookEventsKeepDays`). The runs they queued and the
|
|
* messages those posted stay.
|
|
*/
|
|
export default async function pruneBotHookEvents() {
|
|
const cutoff = Date.now() - (await grabHookEventsKeepDays()) * 24 * 60 * 60 * 1000;
|
|
|
|
return await BunSQLite.sql({
|
|
sql: `DELETE FROM bot_hook_events WHERE created_at < ? RETURNING id`,
|
|
values: [cutoff],
|
|
});
|
|
}
|