# eChatbot onboarding (Phase 1 + Phase 2)

## 1. Create an account
Register at your eChatbot app, then log in. A personal **workspace** is created automatically (you are admin).

## 2. Add AI API keys (BYOK)
Open **AI API keys** in the user menu. Paste keys for the providers you use:

- **OpenAI** (`sk-…`) — required for embeddings when using Claude/Grok chat; also used for OpenAI chat
- **Gemini** / **Claude** / **Grok** — optional, for chat with that provider

**Cost warning:** Document uploads (embeddings) and every chat turn call *your* provider keys. Usage is billed to your AI accounts — not eChatbot.

Rotating `APP_KEY` makes saved keys undecryptable; paste keys again.

## 3. Create a chatbot
Set name, system prompt, **AI provider + model**, welcome message, and optional **widget branding** (color, bot name, logo URL, position). Copy the **public UUID** for embed — never the numeric id.

## 4. Knowledge base
Open **Knowledge base**. Upload **PDF, TXT, DOCX, XLSX, CSV** (max 20MB), or **Crawl a URL** (single page). Status becomes `ready` after the queue worker embeds chunks.

```powershell
php artisan queue:work --sleep=3 --tries=3
```

## 5. Preview, history, analytics
- **Chat preview** — answers stream token-by-token; sources shown here only
- **Conversations** — review past sessions (workspace members with access)
- **Analytics** — counts, fallbacks, top questions

## 6. Embed on your site
```html
<script src="https://YOUR-DOMAIN/js/echatbot-widget.js" data-chatbot-id="YOUR-UUID" async></script>
```

Widget loads branding from config API (no snippet rebuild). Set **Allowed domains** before production.

Demo: `/widget-demo.html?uuid=YOUR-UUID`

## 7. Workspace, billing, quotas (Phase 2)
- Invite members: **Workspace members** (roles: admin / editor / viewer)
- Upgrade plan: **Billing** (Stripe test/live via env) — free plan has soft limits (chatbots, documents, public chats/month)
- Over limit or past-due → create/upload/public chat blocked; data is kept
- **Stripe = money source of truth.** Staff may apply a temporary **plan override** for support/beta via Platform Admin (`/admin`); that does not rewrite Stripe subscription fields.

## 8. Production checklist
- HTTPS, `APP_DEBUG=false`, `SESSION_SECURE_COOKIE=true`
- `/health` → `{"status":"ok"}`
- Queue worker running
- Domain allowlist set
- Stripe webhook endpoint configured (`/stripe/webhook`) with signing secret
- Platform admin seeded only via `php artisan platform:admin {email}` (never from customer UI)
- Never commit `.env` / live Stripe secrets
