Skip to main content

Overview

The Internal Tickets Knowledge feature allows merchants to use their resolved live_supports tickets as a knowledge source for the AI. This document outlines the technical implementation and the privacy safeguards (PII redaction) in place.

Architecture

Data Flow

  1. Selection: Tickets are selected for embedding either manually (via the Dashboard UI) or automatically (via auto_embed_tickets setting).
  2. Sync API: The POST /api/websites/[id]/knowledge/tickets/sync endpoint is triggered.
  3. Content Processing:
    • The system fetches the ticket and its messages (live_support_messages).
    • Content is formatted into a transcript (Q&A format).
    • PII Redaction is applied to the message content.
  4. Embedding: The redacted content is inserted into pending_chunks with a ticket:// URL, triggering the standard embedding worker.

PII Redaction

To protect sensitive customer data, all ticket content passes through a redaction layer before being stored or embedded.

Implementation

The redaction logic is located in apps/web/lib/chat/pii-redaction.ts.

What is Redacted?

The system uses lib/chat/ticket-redaction.ts to redact the following PII types:
  1. Credit Cards: 13-19 digits with delimiters.
  2. Emails: Standard email patterns.
  3. Phone Numbers: Matches international and domestic formats.
  4. Personal IDs (SSN): Matches US SSN format (XXX-XX-XXXX).
  5. Addresses: Heuristic detection of street addresses.
  6. IP Addresses: IPV4 pattern.
Redaction Tokens: Redacted content is replaced with explicit tokens to guide the AI, e.g., [REDACTED_EMAIL], [REDACTED_PHONE]. System Note: A system note is appended to the embedded ticket content to instruct the AI on how to handle these redacted fields.

Logic Location

  • Utility: apps/web/lib/chat/ticket-redaction.ts
  • Tests: apps/web/lib/chat/ticket-redaction.test.ts

Database Schema

  • websites.auto_embed_tickets: Boolean flag to enable automatic processing.
  • website_content: Stores the final embedded chunks. Tickets are identified by url starting with ticket://.