nanobot-channel-web
A WebChannel plugin for nanobot that exposes chat APIs and validates tokens via an external auth service.
Features
POST /messageto send user text into nanobotGET /events/{chat_id}Server-Sent Events stream for assistant repliesGET /history/{chat_id}quick history for page refreshGET /healthhealth check- Optional external auth (
authEnabled=true+authServiceUrl) - Optional
apiTokenfallback (Bearerheader; SSE also supports?token=)
Install
Install in the same Python environment as nanobot:
cd nanobot-channel-web
pip install -e .
Confirm plugin discovery:
nanobot plugins list
You should see web from plugin source.
Config
Run nanobot onboard once after plugin installation to inject defaults, then edit ~/.nanobot/config.json:
{
"channels": {
"web": {
"enabled": true,
"host": "127.0.0.1",
"port": 9000,
"allowFrom": ["*"],
"apiToken": "change-this-token",
"authEnabled": true,
"authServiceUrl": "http://127.0.0.1:9100",
"authServiceTimeoutS": 8,
"corsOrigin": "*",
"historySize": 200,
"pingIntervalS": 15
}
}
}
If authEnabled is true, WebChannel validates bearer tokens by calling:
GET {authServiceUrl}/auth/me
Expected response shape:
{
"ok": true,
"user": {"id": 1, "phone": "13800000000"}
}
apiToken is used only when authEnabled is false.
Protected chat endpoints:
POST /messageGET /history/{chat_id}GET /events/{chat_id}
Use header for normal requests:
Authorization: Bearer change-this-token
For native browser EventSource, use query param:
/events/web-user?token=change-this-token
Run
nanobot gateway
Then point your frontend to http://127.0.0.1:9000.