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>
This commit is contained in:
48
src/services/audit.ts
Normal file
48
src/services/audit.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user