Liwan connector contract (v1)
Liwan is a shell: mic, stream, speaker. It carries the sound and nothing else. The agent, its behavior and its users stay with the owner. The phone only ever receives a one-call address.
Connecting. The owner gives one of:
- API address + API key: the key is kept on Liwan's server, never on phones. For each call Liwan's server sends the key to the API address (section 1).
- https:// call address: the phone asks your server for each call (section 1); your key stays with you.
- wss:// address: the agent's socket itself, for Public and Only me spaces.
When the owner presses Done, Liwan opens one call with no person. "Connected" shows, and the next step opens, when the agent's socket opens.
Who can talk. Liwan only streams. Your system makes the rules and keeps people apart.
- Only me (single user): you, signed in to Liwan. No person is sent with the call.
- Multi users, Public: anyone with the link or QR talks straight away. No person is sent.
- Multi users, Authenticated: people sign up or sign in on your own pages (section 3),
then talk. Liwan passes the
userIdyour page returned, as is.
1. Call address
POST <your address>
Request headers:
Content-Type: application/jsonAuthorization: Bearer <key>: when Liwan's server calls with your stored API key.Authorization: Bearer <token>: when the phone calls, only on Authenticated spaces whose sign-in page returned atoken.X-Liwan-Device: <uuid>: when the phone calls; a random id for this phone. Refuse it to block a device.
Body: { "spaceId": "...", "agentId": "...", "userId": "..." } (userId only on Authenticated spaces)
Answer 200 { "url": "wss://...", ... }: a single-use socket address. Anything else in the
answer is your agent's setup and is passed to the call as is; Liwan reads inputRate and
outputRate (or one sampleRate) from it. Answer 401/403 { "message": "..." } to refuse;
Liwan shows the message.
2. The socket (what url speaks)
| Direction | What |
|---|---|
| phone → agent | binary: the mic, 16-bit mono PCM at your inputRate, sent as it is captured |
| agent → phone | binary: your agent's voice, 16-bit mono PCM at your outputRate, played as it arrives |
| agent → phone | JSON: any message may carry inputRate / outputRate (or sampleRate) to set them |
Rates are in Hz (8000 to 48000); 16000 when your setup states none. Liwan reads nothing else from your messages. The user ending the call closes the socket.
3. Sign-in and sign-up pages (Authenticated spaces)
You give Liwan two pages of your own: a sign-in page and a sign-up page. Liwan opens them inside the app with two extra query parameters:
<your page>?redirect_uri=liwan://member&space=<spaceId>
When the person is signed in, send them to redirect_uri with their id in your system,
and optionally your session token:
liwan://member?userId=<their id>&token=<your session>
Liwan keeps both in the phone's keychain and sends them as is with every call (section 1). Accounts, passwords and account deletion stay on your pages.
All addresses must be https:// (wss:// for the socket).
