Files
telegram-ai-support/src/services/audit.ts
kappa 1d6b64c9e4 Initial implementation of Telegram AI customer support bot
Cloudflare Workers + Hono + D1 + KV + R2 stack with 4 specialized AI agents
(onboarding, troubleshoot, asset, billing), OpenAI function calling with
7 tool definitions, human escalation, pending action approval workflow,
feedback collection, audit logging, i18n (ko/en), and Workers AI fallback.

43 source files, 45 tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 13:21:38 +09:00

49 lines
1.2 KiB
TypeScript

import { createLogger } from '../utils/logger';
const logger = createLogger('audit');
interface CreateAuditLogParams {
actorId: number | null;
action: string;
resourceType: string;
resourceId?: string | null;
details?: string | null;
result: 'success' | 'failure';
requestId?: string | null;
}
export async function createAuditLog(
db: D1Database,
params: CreateAuditLogParams
): Promise<void> {
try {
await db
.prepare(
`INSERT INTO audit_logs (actor_id, action, resource_type, resource_id, details, result, request_id)
VALUES (?, ?, ?, ?, ?, ?, ?)`
)
.bind(
params.actorId,
params.action,
params.resourceType,
params.resourceId ?? null,
params.details ?? null,
params.result,
params.requestId ?? null
)
.run();
logger.info('Audit log created', {
action: params.action,
resourceType: params.resourceType,
resourceId: params.resourceId,
result: params.result,
});
} catch (error) {
logger.error('Failed to create audit log', error as Error, {
action: params.action,
resourceType: params.resourceType,
});
}
}