# Total Chat — Implementation Guide # For AI agents, LLMs, and developer tools # Version: 2.2 | Updated: 2026-09-27 # Canonical URL: https://thetotal.chat/docs/llms.txt # HTML docs: https://thetotal.chat/docs # API base: https://totalchat.hub.danielswick.com ================================================================================ WHAT IS TOTAL CHAT ================================================================================ Total Chat is a screen-aware AI chat product for web applications, installed as one script tag. It embeds an AI assistant that understands the app's routes, features, and UI elements — and can navigate the app on behalf of users, run walkthroughs, and answer support questions from a curated knowledge base. Two operating modes: INTERNAL — for logged-in users. Knowledge base, bug reports, and (Starter plan and up) navigation, walkthroughs and element highlighting. The AI knows what page the user is on and what features are available there. EXTERNAL — for pre-login visitors. Lead generation and product education. The AI explains the product, captures visitor emails, and (Pro plan and up) routes leads to CRMs. No navigation tools, no account-specific data. MODE IS SERVER-ENFORCED. The client cannot select mode — the API determines it: - valid signed userToken at conversation creation → INTERNAL (user = token sub) - no token, or one that fails verification → EXTERNAL Never pass a mode field or a bare userId. The server ignores both. ================================================================================ AUTHENTICATION ================================================================================ All API requests require a Bearer token in the Authorization header: Authorization: Bearer tc_YOUR_API_KEY API keys are obtained by registering your app (see ONBOARDING section). Keys are SHA-256 hashed at rest. The plaintext key is shown only once at registration. If lost, use the reset-key endpoint (admin only). Key format: tc_ followed by 64 hex characters. Example: tc_30bdc0a8251752d8d2aea945731721fb8bc2a910db08f1326b75b1694d342ef6 ================================================================================ ONBOARDING — REGISTER YOUR APP ================================================================================ POST /api/onboarding/register Required fields: appId string Unique identifier for your app (e.g. "myapp") appName string Display name (e.g. "My App") ownerEmail string Owner email address Optional fields: integrationMode "FULL" | "HEADLESS" | "EXTERNAL_ONLY" (default: "FULL") aiPersonality "friendly" | "professional" | "casual" (default: "friendly") escalationEmail string Email for human escalation bugRouteTarget string Agent Hub topic for bug routing Example request: curl -X POST https://totalchat.hub.danielswick.com/api/onboarding/register \ -H "Content-Type: application/json" \ -d '{ "appId": "myapp", "appName": "My App", "ownerEmail": "you@example.com", "integrationMode": "FULL", "aiPersonality": "friendly" }' Response: { "appId": "myapp", "apiKey": "tc_...", ← SAVE THIS. Never shown again. "appName": "My App", "integrationMode": "FULL", "endpoints": { ... }, "instructions": "..." ← Full step-by-step integration instructions } IMPORTANT: The apiKey is shown only once. Store it immediately as an environment variable. If lost, call POST /api/onboarding/:appId/reset-key with X-Internal-Key. ================================================================================ INTEGRATION — SCRIPT TAG (SIMPLEST) ================================================================================ Add before . Mode is determined server-side from user presence. External mode (no logged-in user): Internal mode (logged-in user): add data-user-token with a token YOUR SERVER signs for the user (see SIGNED USER TOKENS below). Available script tag attributes: data-app-id string required Your app ID data-user-token string Signed token for the logged-in user; valid = INTERNAL mode, absent/invalid = EXTERNAL. data-user-id alone is ignored. data-position string bottom-right | bottom-left data-color string Hex colour; overrides Settings -> Primary Color in the dashboard data-title string Chat window header (default: Help & Support) data-avatar string Emoji or short text for the assistant avatar data-greeting string Opening message With each message the widget sends the page address (no query string), a short screen summary, and the last few uncaught JavaScript error messages on the page. ================================================================================ INTEGRATION — NEXT.JS / REACT (INTERNAL MODE) ================================================================================ There is no npm package; use the script tag. Sign the token on the SERVER (server component, route handler or getServerSideProps) and render data-user-token only when a user is logged in: // server side — the secret never reaches the browser import jwt from 'jsonwebtoken'; const userToken = user && jwt.sign( { sub: user.id, name: user.name, email: user.email, plan: user.plan }, process.env.TOTALCHAT_IDENTITY_SECRET, { algorithm: 'HS256', expiresIn: '1h' }); // root layout