
# CSR / ER / WebRTC Implementation Notes

## Applied flow

- CSR main page redirects to `csr/requests.php`.
- `csr/requests.php` is now the main Tickets tab.
- Tickets can be filtered by source:
  - Created in PHP / CSR
  - Created in PHP / Customer App
  - Created in TypeScript / ER
  - Can Message / Call
- TypeScript / ER tickets are shown as view-only by default.
- PHP-linked tickets can show Message / Call actions when they have a customer account/email link.
- Manual ticket creation now uses customer email to find/create the CX customer record, then auto-creates the chat room.
- WebRTC call files were added:
  - `customer/start_web_call.php`
  - `call_room.php`
  - `api/webrtc/*`
  - `assets/js/webrtc-client.js`
  - `webrtc-server/*`
- REST API for ER/TypeScript added:
  - `api/v1/tickets.php`
  - `api/v1/create_client_token.php` one-time setup
  - `docs/TYPESCRIPT_ER_CONNECTION.md`

## Important production steps

1. Import `sql/2026_06_12_csr_er_webrtc_api_update.sql`.
2. Visit `api/v1/create_client_token.php?name=typescript_er` once, save the token, then delete that file.
3. Put the token in ER/TypeScript environment variables.
4. Run `webrtc-server` with Node.js for WebRTC signaling.
5. Use HTTPS for the PHP site and the Node signaling server.
6. Add a TURN server before real production WebRTC.
