API Guide
Technical reference for ConRev: widget embed, auth model, public endpoints, webhooks, and the MCP server.
ConRev API Documentation (Draft)
This document is the ConRev API reference. Status: planning draft, adjusted during implementation. The final version is also served as a public page at /api-docs in the app.
Base URL: https://conrev.temonjo.com
Auth Model
| Context | Auth method |
|---|---|
| Public widget | data-site-key (site public key) + domain whitelist + visitor token in localStorage |
| Signed identify | sig = HMAC-SHA256 of the payload using the site secret_key |
| Inbound webhook | Per-site secret in the path or header (X-ConRev-Secret) |
| Admin panel | Session cookie from /admin login |
| MCP / analytics API | Bearer API key per site (created in the settings page, scope read) |
| Customer portal | Session cookie from email + code login |
Rate limits apply to all public endpoints. Consistent error response: { "error": "code", "message": "explanation" } with the appropriate HTTP status.
Embed Snippet
<script defer src="https://conrev.temonjo.com/widget.js" data-site-key="PUBLIC_KEY"></script>
Optional, for logged-in users on the host website:
<script>
// sig is generated server-side: HMAC_SHA256(`${ts}|${email}|${tier}`, SECRET_KEY)
// ts = epoch milliseconds when the signature was created (valid for 10 minutes)
ConRev.identify({ email, name, tier, ts, sig });
</script>
Widget Endpoints (public)
POST /api/widget/init
Body: { site_key, page_url, page_title, visitor_token?, fbc?, fbp?, fbclid?, utm? } Returns: { visitor_token, mode, config, conversation_id?, reply_minutes } mode: chat | email_form | hidden. config.theme: { primary_color, bubble_icon, position, greeting, brand_name } from sites.settings.theme. config also includes strings (UI texts per settings.lang), prechat (require_email/require_whatsapp/topics), offline, businessHours, lang, site_name. Domain whitelist: the Origin/Referer header must match sites.domain (subdomains allowed), otherwise 403 domain_not_allowed.
POST /api/widget/pageview
Body: { visitor_token, url, title } Returns: { automation?: { id, delay_seconds, message, cta_label, cta_url } }
POST /api/widget/automation-event
Body: { visitor_token, automation_id, type } with type = shown|clicked|dismissed.
POST /api/widget/identify
Body: { site_key, visitor_token, name?, email?, whatsapp?, tier?, ts?, sig? }.
name/email/whatsapp are always accepted. tier is only accepted when sig is valid: sig = HMAC_SHA256(secret_key, ${ts}|${email}|${tier}) with ts in epoch ms (maximum difference of 10 minutes). The tier name must match sla_tiers.name for that site. Without a valid sig, the tier is rejected but the other fields are still saved.
Returns: { ok, tier: "accepted"|"rejected"|null, identified }. identified=true means the visitor has a valid tier (used by the identified_only visibility mode).
POST /api/widget/messages
Body: { visitor_token, conversation_id?, body, page_url?, name?, email?, whatsapp?, topic? } Returns: { conversation_id, conversation_number, message }. Reuses the latest open/pending ticket when conversation_id is empty; a message to a resolved ticket reopens it. topic is mapped to a ticket category and its hint is stored as a system message. On identified_only sites, visitors without a valid tier/identify are rejected with 403.
GET /api/widget/messages?conversation_id=&since=&visitor_token=
Message polling (the main transport of widget v1, since = last message id). Returns: { conversation: { id, number, status, rating }, messages: [...] } with agent sender_name and attachments per message.
POST /api/widget/conversations/{id}/attachments
Multipart file (image, max 5MB). The server converts it to WebP. Returns: { attachment: { id, url } }.
POST /api/widget/ping
Embed test ping (used by the /admin/setup setup wizard). Body: { site_key }. Marks sites.settings.last_ping_at. Rate limit 30/10 minutes.
POST /api/widget/support-form
Public email support form (fallback for identified_only mode). Body: { site_key, email, name?, message, page_url? }. Finds or creates a visitor per site (normalized email + MX check via assessEmail), creates or reuses an open/pending channel=email ticket, and sends a verification code once to the email (purpose email). Rate limit 5/10 minutes.
POST /api/widget/verify-email
Body: { visitor_token, email }. Sends a verification code (once, rate limited).
POST /api/widget/verify-email/confirm
Body: { visitor_token, code }. Marks email_status=verified.
POST /api/widget/conversations/{id}/rate
Body: { visitor_token, rating (1-5), comment? }. Only allowed for a conversation with resolved status owned by that visitor. Records a rated event.
Surveys: GET /s/{slug} and POST /api/surveys/{slug}
GET shows a minimalist survey page (stars/numbers/slider + optional comment). POST body: { score, comment?, visitor_token?, email?, conversation_id? }. One response per visitor per survey per conversation.
POST /api/widget/conversations/{id}/testimonial
Body: { visitor_token, content, rating? }. Enters the pool with pending status.
POST /api/widget/conversations/{id}/cta-click
Body: { visitor_token, url }. Records a cta_click event.
GET /ws
WebSocket upgrade. Auth via ?token= visitor token (visitor) or session cookie (agent). JSON events: message.new, conversation.updated, presence.
Other Public Endpoints
Lead magnet form: GET|POST /f/{slug}
GET shows the form (Name, Email, Submit). POST accepts { name, email }, creates a lead in Audience, and returns a page containing the lead magnet link/file.
Help desk portal (member area): /member
Server-rendered pages (not a JSON API), already live. The old /portal path redirects permanently to /member.
GET /member: code request form (email + honeypot, rate limited).POST /member: sends a 6-digit code (15 minutes, 60-second resend cooldown) to a visitor email that passes validation. The email contains a magic linkGET /member/verify?email&codefor one-click sign-in. The response is always generic (it does not reveal whether an email is registered).POST /member/verifyorGET /member/verify?email&code: exchanges the code for aconrev_portalcookie (30 days).GET /member/tickets: lists tickets belonging to that email (all visitor rows with the same email, across sites;spamstatus is hidden).GET /member/tickets/{id}: details + message history (internal notes are hidden) + attachments.POST /member/tickets/{id}/reply: replies from the portal; a resolved/pending ticket returns toopen+ areopenedevent.GET /member/go/{token}/{id?}: magic link from resume emails; the portal session token activates the session immediately and opens ticket {id} without typing a code.GET /member/logout: clears the session.
POST /api/webhooks/{site_key}/conversion
Header: X-ConRev-Secret: SECRET_KEY Body: { email, amount?, external_ref?, conversation_id? } Records a conversion and tries to match it to a visitor/conversation via email.
POST /api/inbound/email
Inbound provider webhook. Secret header INBOUND_EMAIL_WEBHOOK_SECRET. Body: provider payload (from, to, subject, text, headers). Replies to conv+{email_token}@conrev.temonjo.com are appended to the conversation and reopen it.
MCP Server (AI analysis)
ConRev provides an MCP (Model Context Protocol) endpoint at POST /mcp (Streamable HTTP transport) so AI assistants can help analyze incoming conversations.
Auth: Authorization: Bearer <site_api_key> (created in admin, scope read).
Exposed tools (MVP, read-only):
| Tool | Purpose |
|---|---|
list_conversations | List conversations with status/category/date filters |
get_conversation | Conversation detail + messages (without internal notes when scope is public) |
search_knowledge | Search the per-site knowledge base (FTS) |
conversation_stats | Aggregates: volume, first response time, resolution time, rating, NPS |
list_audience | List visitors/leads with filters |
topic_distribution | Discussion topic distribution |
Use case: external AI (Claude, GPT, internal agents) analyzing recurring questions, agent answer quality, and topics for automation. Write tools (reply, assign) are not exposed in the MVP.
Public Pages
/docs: usage documentation (embed guide, PHP/WordPress identify snippet, compact API reference)./changelog: release list, rendered fromCHANGELOG.mdin the repo (single source of truth).
Security Notes
- All public input is validated and rate limited.
- Visitor message bodies are sanitized before rendering in the panel (XSS).
- MCP API keys are
readscope only; keys can be revoked from admin. - Webhook endpoints require a secret; payloads are strictly validated.