# Installing Xpace Chat

Two ways. Both give the same app.

## A. Hosted by Xpace IT (nothing to install)
1. Ask Xpace IT for your address, for example `https://chat.yourcompany.xpace.my`, and your admin login.
2. Open it, sign in, and follow **Connect** (scan one QR per salesperson).
3. In your CRM, upload the `xpace_chat` module, press **Enable**, and paste the address and the bridge key from **Settings > CRM**.

## B. On your own server (one Docker command)
You need a Linux server with Docker installed and a domain name pointing at it.

```bash
git clone <this repository> xpace-chat && cd xpace-chat
cp .env.example .env          # edit XC_BASE_URL, XC_ADMIN_EMAIL, XC_ADMIN_PASSWORD
docker compose up -d
```
Open `http://<server>:8787` (put a reverse proxy with https in front for production; the phone app and the CRM iframe need https).

- Data (database, linked WhatsApp sessions, media) lives in the Docker volume `xpace_data`. Back it up.
- Update: `git pull && docker compose up -d --build`.
- Logs: `docker compose logs -f`.

## After installing
1. Sign in as the admin. **Connect**: Option A links a phone (add it, then scan the code from WhatsApp > Linked devices). Option B links Meta's WhatsApp Business API (paste four details, then paste the webhook address into Meta). You can use either or both.
2. **Teach the AI**: fill the fact sheet, paste quick replies and winning chats, pick the AI engine and paste its key, set a monthly AI budget.
3. **Settings**: who gets leads, quiet hours, spend cap. Add staff with roles.
4. That is all. There is no test mode and no Go live button: messages send as soon as a number is linked. The list on the Connect page ("3 things left to set up") is only a guide. Open **?** (Help) in the top bar for the whole path in plain words.

Developer only: setting `XC_DRY_RUN=1` in the environment makes the app record every send as "would send" and send nothing. It never appears in the app. Leave it unset in production.

## Optional
- **WhatsApp Business API (Meta)** for campaigns and messages after 24 hours: Connect > tile 2.
- **WeCom** for internal rooms: Connect > tile 3 (corp id, secret, token, AES key; set the callback URL to `https://<your address>/hooks/wecom`).
- **Perfex CRM**: upload `crm-perfex/xpace_chat` to `modules/`, activate, paste address + bridge key; it adds the sidebar items and imports your 1.6.0 data.

## Claude (MCP) connector
The private address is `https://<your Xpace Chat address>/mcp/<key>`. Do not log request addresses for `/mcp` in your web server or proxy: the key is part of the address. If a log may have leaked it, press Reset on the Claude card (the old key stops at once).
