API Endpoints
All endpoints are served by the chat worker at chat.anshulbisen.com.
Health Check
GET /health
Returns worker health status.
Response 200:
{ "status": "ok" }Session Management
POST /session
Create a new chat session. Rate limited to 3 per IP per hour.
Headers:
X-Bypass-Rate-Limit: <token>(optional, for E2E tests)
Body:
{
"name": "Visitor Name",
"email": "visitor@example.com",
"page": "/about",
"turnstileToken": "<cloudflare-turnstile-token>"
}Response 200:
{
"sessionId": "uuid-string",
"wsUrl": "wss://chat.anshulbisen.com/ws/uuid-string"
}Errors:
400— Missing required fields or invalid email403— Turnstile verification failed or blocked IP/email429— Rate limit exceeded502— Failed to create Slack thread or initialize session
GET /ws/:sessionId
WebSocket upgrade endpoint. See WebSocket Protocol for message types.
Authentication
POST /auth/bypass
Set the rate limit bypass cookie (owner only).
Body:
{ "token": "<RATE_LIMIT_BYPASS_TOKEN>" }Response 200:
{ "ok": true }Sets __bypass=1 HttpOnly cookie with 30-day expiry.
Errors:
403— Invalid token
POST /auth/bypass/clear
Clear the bypass cookie.
Response 200:
{ "ok": true }Sets cookie with Max-Age=0.
Slack Webhook
POST /slack/events
Receives Slack Events API webhooks. Handles:
- URL verification — responds to Slack's challenge request
- Message events — relays threaded replies back to the chat visitor
Headers (verified):
x-slack-request-timestampx-slack-signature
All requests are verified with HMAC-SHA256 signature before processing.
Response: 200 on success, 401 on invalid signature.
Internal Endpoints (Durable Object)
These endpoints are called internally by the worker, not exposed to the public:
POST /initialize
Initialize a new chat session in the Durable Object.
Body:
{
"name": "Visitor Name",
"email": "visitor@example.com",
"page": "/about",
"threadTs": "slack-thread-timestamp",
"channelId": "slack-channel-id"
}POST /initialize-bot
Initialize a bot-mode session (no Slack thread).
GET /state
Get current session state.
POST /relay
Relay a message from Slack to the visitor.
Body:
{
"text": "Message text",
"sender": "anshul"
}CORS
All endpoints use CORS middleware:
- Origin:
ALLOWED_ORIGINenv var (https://anshulbisen.comin production) - Methods:
GET, POST, OPTIONS - Headers:
Content-Type - Credentials:
true(for bypass cookie)