Skip to content

Concierge

Internals of the Concierge domain. For the public API, see Concierge API.

CoreAPI/domain/concierge (with handlers/ and routes/) is the in-room guest service: guest sign-in (TV PIN or room + password), calling, department chat and the AI hotel guide, voice, ordering, stays and the room TV. It maps to the future Engagement domain of the v3.4 ontology (see Domains). Partner reference pages: calling, chat, voice, stays, room TV and cast.

Calling

Architecture

A 1:1 WebRTC call between a hotel guest (guest webapp, or the room TV as a listener) and staff, built on a standalone Node mediasoup-service for the media plane. CoreAPI never touches RTP/SRTP: it relays the control-plane calls (capabilities, transports, produce/consume, close) and gates them behind real auth.

graph LR
    Guest["Guest webapp"]
    Staff["Staff app (SpatioViewMobile)"]
    TV["Room TV (playout app)"]
    CoreAPI["CoreAPI domain/concierge"]
    Mediasoup["mediasoup-service (Node)"]

    Guest -->|guest HS256| CoreAPI
    Staff -->|platform RS256| CoreAPI
    TV -->|device JWT| CoreAPI
    CoreAPI -->|control-plane only| Mediasoup
    Guest -.->|RTP/SRTP direct| Mediasoup
    Staff -.->|RTP/SRTP direct| Mediasoup
    TV -.->|RTP/SRTP direct, receive only| Mediasoup

Signaling goes client → CoreAPI only; media goes client → mediasoup-service directly. The /rtc/* responses are the mediasoup-service JSON bodies forwarded as-is (sendRaw, no {success, data} envelope). CoreAPI runs without mediasoup: if MEDIASOUP_SERVICE_URL is unset or the service is unreachable, every /rtc/* call answers 503 realtime media is temporarily unavailable and nothing else is affected.

Data model

CallLog (models.go), one row per call attempt:

Field Notes
Direction guest_to_staff (every row before 2026-11-11) or staff_to_guest
StaffUserID staff_to_guest: who rang
AcceptedBy guest_to_staff: who took the call
AnsweredOn staff_to_guest: phone or tv
StayID, DepartmentID The stay that placed or receives the call; the department
RoomID call-<id>, written after insert (needs the DB id); the mediasoup room both sides join
Status ringing → accepted → ended, or missed
StartedAt, AcceptedAt, EndedAt

CallTransport and CallProducer remember which party (staff, guest, tv) opened each transport and producer, so the TV can only receive the staff voice. StaffCallLog is the staff↔staff video call: a separate model because the ownership rule differs (exactly the two named participants, not "any staff of the org").

Auth model

  • /staff/*: middleware.ProtectedRS256. Org comes from claims.Org.OrgID. An earlier version read a client-supplied X-Organization-ID; fixed 2026-09-14.
  • Guest routes: RequireGuestSession, concierge's own HS256 token (Authorization: Bearer), checked against guest_sessions (not revoked, not expired). TTL CONCIERGE_SESSION_TTL_MINUTES (default 30 days). Signing in ends every other live phone session of the room ("one phone per room", replaceRoomPhones).
  • /rtc/*: RequireGuestOrStaff tries the guest token first, then RS256.
  • /tv/*: the provisioning device JWT (provisioning.ParseDeviceJWT); the room is devices.location_id, the stay is that room's active stay.

Per-room ownership. authorizeRoom (handler_rtc.go) looks up the call behind a roomId: a guest must own the call's StayID, staff must belong to the department's org; for a StaffCallLog the caller must be one of the two users. Applied on capabilities, producers and create-transport. Connect/produce/consume/close take only a transportId, which is only handed to an already-authorized caller, so they don't re-check (a deliberate scope cut). The TV media routes check more: the call must be an accepted staff call of the TV's stay, the transport must be one this TV opened, and it may consume only a staff producer.

Team scoping (since 2026-11-08). GET /staff/calls/ringing, staff chat and room calls go through staffScoper (staff_scope.go): a staff member sees the departments they work in; supervisors and people in no team see all. The /rtc/* check is still org-level. This replaced the "org-scoped, not department-scoped" rule and the planned "department-scoped call routing" (reusing tenancy's Team/TeamMember); hotel staff teams are kept by hotelinfo (/hotel/:ws/staff-teams).

Lifecycle

Step Effect
Guest POST /calls CallLog ringing; every member of the team gets an incoming-call push (Expo, best effort)
GET /staff/calls/ringing, GET /staff/calls/:id Staff poll (~1.5 s); no push signaling for status
POST /staff/calls/:id/accept ringing → accepted, only from ringing (no double accept)
PATCH /staff/calls/:id/end, guest PATCH /calls/:id/end → ended; mediasoup.CloseRoom cleans up server-side (fixes the port-exhaustion leak of abandoned calls, 2026-09-02)
Nobody accepts within CONCIERGE_CALL_RING_SECONDS (default 60) → missed (call_expiry.go, applied lazily on the next read); a task is left for the department

Staff calls a room (2026-11-11): POST /staff/room-calls {stayId, departmentId?} (department defaults to the hotel's front desk), one open staff call per stay (409). The guest's phone gets a web push when the guest enabled it. The guest answers on the phone (POST /calls/:id/answer) or the TV remote (POST /tv/call/:id/answer, answeredOn: "tv", after which the phone starts its microphone). The TV joins the same media room receive-only.

Still open

  • No queue or routing. A guest call goes to one department; no "assign to available staff", no reassignment on no answer (a missed call leaves a task).
  • No push signaling for call state. New producers and status changes are found by polling.
  • Generic error masking. ErrMediasoupUnavailable folds every failure (outage, bad producer ID, closed transport) into the same 503.
  • MEDIASOUP_ANNOUNCED_IP is manual and network-specific.

Run and test calling

mediasoup-service is a separate Node/Express container; CoreAPI does not start it.

cd Quickstart
make rtc       # CoreAPI + AuthAPI + infra + mediasoup-service
make rtc-down
  • MEDIASOUP_SERVICE_URL: CoreAPI's URL for mediasoup-service (domain/concierge/config.go). Unset = calling off. In compose, point it at the service (for example http://mediasoup:34430). See CoreAPI env vars.
  • MEDIASOUP_ANNOUNCED_IP: set on mediasoup-service. A real IP both the guest and staff networks can reach, not 127.0.0.1 unless both clients are on the same machine.

On staging (the feature has not shipped to production): guest app at stg.guest.castis.io, CoreAPI at stag.api.castis.io. The staff side has no web build: install SpatioViewMobile's staging EAS profile (eas build --profile staging --platform ios|android). Both staging apps use the same mediasoup-service instance. Guest sign-in uses a seeded stay's room login; the room and its password are in the CoreAPI seed data, not here.

Smoke-test mediasoup-service without a call. Its HTTP API has no auth of its own (CoreAPI is the gate), so it can be tested directly:

BASE="http://<mediasoup-service host>:34430"
ROOM="smoketest-1"
curl -X POST "$BASE/routers/$ROOM/capabilities"                 # router boots, codecs negotiated
curl -X POST "$BASE/routers/$ROOM/transports" -H "Content-Type: application/json" -d '{"direction":"send"}'
curl "$BASE/health"                                              # rooms/transports 1/1
curl -X POST "$BASE/routers/$ROOM/close"                        # what CoreAPI calls on hang-up
curl "$BASE/health"                                              # back to 0/0

The transport's iceCandidates[].ip must be the internet-reachable announced IP, not 127.0.0.1 or a LAN address. Confirmed 2026-09-20 against the live instance: it announced the droplet's public IP on real UDP/TCP ports.

History

The 2026-08-31 proof of concept (WEBRTC_POC_HANDOFF.md, WEBRTC_DEMO_RUNBOOK.md at the CoreAPI repo root) had no per-room ownership check and guest-only auth. Both were fixed on 2026-09-01 (74eca5b), when the staff-calling layer (CallLog wired for real) was added on top of the 7 unchanged signaling routes.

Chat and the AI hotel guide

Three features share the guest↔staff chat surface:

  1. Department chat. Since 2026-11-12 new threads are AI-first (dept_chat.go): the hotel assistant answers from the hotel's records, and a person is brought in when the guest asks, when the message is a request, after two unsure answers, after several answers, on a thumbs-down, or at once on an emergency word. Statuses ai, offered, waiting, claimed, closed; first staff member to accept wins (claimThread, ClaimTTL). Older threads keep the canned "X will get back to you shortly" reply and people-only behaviour.
  2. Best-effort translation. Guest messages get a background English translation for staff, staff replies are translated back into the guest's language. Fire-and-forget: never blocks a send.
  3. AI hotel guide. ChatThread.IsAI threads answered synchronously by an LLM.

All three depend on cdn-ai's agent (domain/ai client), a different team's /chat endpoint built for CDN analytics. See domain/ai/config.go and AI: CDN-AI system.

Translation

ai.Client (domain/ai/client.go):

Method Direction Used by
DetectLanguageAndTranslateToEnglish guest → English, once per thread SendMessage, first guest message
TranslateToEnglish guest → English later guest messages
TranslateFromEnglish English → guest's language StaffReplyToThread, the canned reply
Ask prompt → answer the AI guide

Stored in ChatMessageTranslation (one row per translated message) and ChatThread.GuestLanguage. Everything runs in a goroutine with context.Background(); a failure only logs ([concierge] translation failed for message %d), so a broken translation shows up as messages with no translatedBody, never as an error.

AI guide

answerGuestQuestion (handlers/handler_ai_guide.go) is awaited (the guest is waiting, with a typing indicator).

  • Full-context grounding, not retrieval. Every call sends every active PolicyEntry plus every active Outlet/MenuItem (buildGuideContext), fresh each time: no cache, no chunks, no embeddings. Revisit if the corpus grows past a few dozen entries.
  • Language. ChatThread.GuestLanguage is an explicit choice here (the globe selector): once set, answers are pinned to it. Without it the prompt says "answer in the same language as the question", which is unreliable for short input on a small quantized model.
  • Formatting. Only **bold** for a key number, price or time, and - bullets for 3+ items. Rendered by ConciergeGuestApp/src/utils/guideMarkdown.jsx, for AI-guide bubbles only.
  • Fails open to concierge.AIGuideFallbackMessage ("message Front desk directly") on any client error.
  • Every call sends use_tools: false and a short minimalSystemPrompt, opting out of cdn-ai's CDN system prompt and tool schemas.
  • Stateless. cdn-ai's run_loop_traced(question) takes one question, no history: "what time does it close?" after a pool question has no idea "it" is the pool.

Reliability incident (2026-09-23)

Symptom: the guide's fallback fired for questions the corpus covered ("can I bring my dog?"). cdn-ai's agent/api/logs/audit.jsonl showed Context size has been exceeded and Request timed out at 140-180 s.

Root cause: every /chat call paid for cdn-ai's SYSTEM_PROMPT (~3,268 tokens) plus its tool schemas (~10k tokens): ~13k of a ~15k-token guide prompt, against llama-server --ctx-size 40000 --parallel 6 --kv-unified, a pool shared by 6 slots (confirmed with ps aux on the Mac mini; n_ctx = 40192). A few concurrent heavy requests could exhaust it.

Fixes, live on staging: cdn-ai's ChatRequest gained use_tools/system_prompt (defaults unchanged); this domain sends the opt-out plus minimalSystemPrompt, cutting a guide call to ~2.2-2.5k tokens. Ask() got its own GuideTimeout (default 25 s) instead of translation's 6 s RequestTimeout. cdn-ai's mcp_client.py now caches MCP sessions for 10 minutes instead of opening one per call.

Restart demo

POST /concierge/demo/restart (handler_demo.go, guest session) soft-deletes the stay's ChatThreads and messages, hard-deletes Order/OrderItem/ServiceRequest rows, resets RoomControlState and rebuilds the two original FolioLines, but never touches the Stay, so the room login keeps working. Placed as a small link under Sign Out in the guest app's profile sheet. Known gap: no signal reaches SpatioViewMobile; a staff device shows stale state until its next poll.

Still open

  • Auto-detected language is unreliable; the selector is the mitigation.
  • No conversation memory in the guide.
  • Suggestion pills are a fixed list (ChatThread.jsx's AI_SUGGEST); there is no usage pipeline to derive them.

Voice

Guest app

ConciergeGuestApp: src/components/remote/VoiceButton.jsx, the voice part of src/hooks/useConciergeApp.js, src/utils/voiceLang.js. Hold-to-talk on the Room controls tab (Space or Enter work too). Browser speech recognition (SpeechRecognition / webkitSpeechRecognition, interimResults: true, continuous: false) unless the phone uses the hotel's speech-to-text (POST /voice/transcribe, whisper.cpp behind a Caddy proxy; clips up to 2 MB, one at a time per session, 429 when busy). The result is shown as a short note.

Language chip: EN (en-US, default) → TH (th-TH) → KO (ko-KR) → JA (ja-JP) → MS (ms-MY), saved in localStorage voiceLang. English is the default on purpose; "Auto" (stay language, then phone) exists but is off (AUTO_ENABLED = false) until the stay's language can be trusted. The server grammar accepts all its languages whatever the chip says.

Server

  • Grammar: ParseVoiceIntent (voice.go), keyword rules only, in English, Thai, Chinese, Japanese, Korean and Malay. Non-English phrases have had no native-speaker review. Rule order, first match wins: bare direction/OK word; absolute temperature 16-30 with a temperature word or degree sign; TV off, TV on; cooler/warmer; cast; named destination; close menu, open menu; previous/next channel; pause/resume; volume ("too loud"/"can't hear" before louder/quieter; a temperature sentence never counts as volume).
  • Destinations: voice_destinations.go is the only list; the grammar, the AI prompt, ClampVoiceIntent and NAVIGATE validation all read it. It merges the menus of every TV property template (Phoenix uses Golf, Sunway uses Explore).
  • AI fallback: through the domain/ai client (AI_AGENT_URL), 8-second limit (voiceAITimeout). The prompt lists actions, range and destinations, asks for one JSON object, fences the guest's words as data. ClampVoiceIntent drops unknown actions, clamps amount to 1-10, drops an out-of-range temp_set or unknown go_to, removes an unknown item, canonicalises names.
  • Playout commands go to tellyboard/devices/{deviceId}/player/command; volume to .../volume (up/down/level); screen power to .../power (ON/OFF). Publish confirmed within 5 s or 503.
  • POST /voice/speak, /tv/voice/speak: hosted text-to-speech (domain/ai/tts.go), off (501) until TTS_URL is set. ?url=1 stores the audio for 10 minutes under a 128-bit random id (GET /tv/voice/audio/:id, no login) because the LG media element refuses blob: and data: sources.

On the TV (launcher-app playout-app)

The playout app subscribes to its player/command topic. Home.jsx on NAVIGATE: Watch plays the last (or first) channel full screen (promo picture-in-picture if channels aren't loaded); a menu key opens that section, on the first row whose title contains item (case-insensitive); Apps with an item opens the app by id or name (Netflix and YouTube only when the launcher reports caps=apps); unknown targets are ignored. Sections come from playout-app/src/properties/<name>/content.json (menus[].key), chosen at build time with npm run build:phoenix|build:sunway|build:playtelly. The footer room label (useRoomNumber.js) polls GET /tv/room every 15 s, falls back to the stay's room from GET /tv/stay, keeps the last label after an error, and clears only the stay number on STAY_CHECKOUT. The TV app has no CI: a TV gets changes only after a packaged build is installed.

Still open

  • One destination table for every property, in code: a new TV section needs a CoreAPI deploy plus the TV's content.json. Per-hotel data is planned.
  • A question the grammar sends to the AI becomes only an action or a say suggestion; routing it to the AI guide is not built (the separate /assistant/ask path exists for Ask Telly).

Stays and the welcome screen

Thing Where it lives
Venue locations, location_type = 'venue'. Any venue can do check-in.
Hotel establishments, venue_id → the venue. Optional for check-in.
Room locations, location_type = 'space', below the venue
Endpoint endpoints, one per room: the slot a TV sits in
Stay stays, belongs to a room (space_id), never to a device

A TV finds its stay through devices.location_id → the room's active stay. The stay anchor (resolveStayAnchor): a venue with a hotel record resolves to the establishment id; a venue without one is its own anchor. Outlets, guide content, policies and the venue welcome message are keyed by it.

Welcome tables, created by CoreAPI at boot if missing (ensureWelcomeTables in routes/wire.go, because the registered-models migration is skipped when the schema fingerprint matches; that is how welcome_configs once went missing): welcome_configs (unique org + anchor), room_welcome_configs (unique org + space), plus tv_templates, tv_menus, tellyboard_states, stay_payments, guest_web_push_subs, welcome_backgrounds, landing_configs, tv_commands, tv_live_events. Staff check-out sends STAY_CHECKOUT over MQTT to the room's screens (best effort). The workspace-scoped stays routes (/staff/:ws/stays, 2026-11-14) refuse to check out a stay that belongs to a PMS reservation ("check it out from Front Desk").

Playout Admin pages. Check-in Demo (/checkin-demo, src/pages/playout/checkin-demo/): bookings table, New booking form (venue select drives the space select), a Room screen column that previews and edits the welcome (room by default, venue by a link), resets the viewed flag, and logs each API call. Hotel Setup (/hotel-setup, src/pages/playout/hotel-setup/), marked "mock UI": hotel list, three-step New hotel wizard, room tree with Add rooms, Rename and Delete; falls back to in-memory mock data on a 404 from /hotels.

Demo-only switches. CONCIERGE_DEMO_PMS=true enables the unauthenticated /concierge/public/stays, /public/rooms, /public/bookings, the staff GET /staff/stays/:id/room-screen link, and a stay_key shortcut on the TV welcome calls (and the /stays/:room?stay_key= page CoreAPI serves). SEED_DEMO_HOTEL=true seeds a small demo hotel. Neither is for shared environments. CoreAPI also serves a ready-made room screen at /welcome/?token=<device token>.

Room TV

  • Every /tv/* response goes through handlers.TVMediaURLs(), which rewrites our media addresses to http because old TVs can't open https (handlers/tv_media.go).
  • GET /tv/flights uses AeroDataBox (RapidAPI), cached 10 minutes per airport, keeping the last good board on provider failure. Needs AERODATABOX_API_KEY (optional AERODATABOX_HOST, FLIGHTS_AIRPORT default HAN, FLIGHTS_TIMEZONE default Asia/Ho_Chi_Minh); without it, 501 and the TV keeps its bundled snapshot.
  • POST /tv/pins (mint a PIN for a room) needs the internal PSK (RequireInternalToken); not partner-facing.
  • GET /tv/template: landing templates edited in Tellyboard's Experience Composer, applied by the playout app on webOS and Tizen (playout-app/src/template.js documents the fields). The app asks at start and every 2 minutes and caches the last one.
  • Live thumbnails (domain/playback/livethumb) accept .m3u8 sources; enable with LIVE_THUMBS_ENABLED=true and restart the pod.

Change history

Date Change
2026-11-14 Workspace-scoped staff stays routes /staff/:ws/stays (workspace:pms:view, workspace:pms:manage).
2026-11-12 AI-first department chat: thread statuses, GET /threads/:id, handoff, not-helpful, staff accept and close.
2026-11-11 Staff calls a room: /staff/room-calls, guest /calls/incoming and /calls/:id/answer, TV /tv/call* and receive-only /tv/rtc/*.
2026-11-08 Departments for every hotel; calls and chats scoped by team; missed calls. Hosted voice (/voice/speak).
2026-10-30 Hotel speech-to-text (/voice/transcribe).
2026-10-29 Landing templates (/tv/template, /staff/tv-templates).
2026-10-26 GET /tv/flights.
2026-10-11 GET /tv/room.
2026-10-08 POST /voice/intent; welcome screen and welcome config; TV cast session.
2026-09-24 Chat, translation and AI guide documented after the 2026-09-23 incident.
2026-09-22 Staff↔staff direct calls; staff chat routes.
2026-09-20 Calling documented from a code audit; OpenAPI file added.
2026-09-18 Staff check-in and check-out (/staff/stays).
2026-09-14 Staff org scope taken from the token, not X-Organization-ID.
2026-09-02 GET /staff/calls/:id; authoritative mediasoup room cleanup on hang-up.
2026-09-01 Per-room ownership check; staff calling (/staff/calls/*).
2026-08-31 Signaling routes /rtc/* (proof of concept).
2026-08-13 Guest chat threads.