Quickly set up a temporary chat page on the same Wi-Fi: send messages, transfer files, paste images, and use it on both phones and computers.
Startup
python3 scripts/lan_chat.py --work-dir /path/to/workspace
The terminal outputs the LAN address (default port 11567), and devices on the same network can open it in a browser. Uploaded files are written to the workspace's lan_chat_uploads/, and are cleared when the service stops.
Parameters
| Parameter | Description |
|---|---|
--work-dir |
Workspace path, defaults to the current directory |
--port |
Listening port, default 11567 |
python3 scripts/lan_chat.py --work-dir . --port 8080
Features
- Chat: Enter to send, Shift+Enter for a new line
- Files: maximum single file size 2 GiB
- Paste images: paste directly into the input box as an attachment
- Member list: the sidebar shows online nicknames and IPs, and can be collapsed on narrow screens
- Bubbles: local messages are on the right, others' messages are on the left (distinguished by browser
member_id)
Constraints
- Use
--work-dirto point to the user's workspace; do not copy the script - After startupmusttell the user the LAN URL printed by the terminal exactly as-is, so the user can tap it on their phone to open it directly
- The script outputs the URL immediately via
flush=True; the agent must read that line from the terminal as the sole source of the URL - Send a message on behalf of the user:
curl --fail -X POST http://127.0.0.1:11567/api/messages \
-H 'Content-Type: application/json' \
--data-binary '{"name":"昵称","text":"消息内容","member_id":"唯一标识"}'
- Send a file on behalf of the user (
file=@uses an absolute path):
curl --fail -X POST http://127.0.0.1:11567/api/files \
-F 'name=昵称' \
-F 'member_id=唯一标识' \
-F 'file=@/absolute/path/to/file;filename=显示名.ext'
- When using a custom port, replace the port number in the above URL as well
- The request body uses
member_idto identify the sender; in the response JSON, the same field name issender_id