No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Satya Benson 81c684f955 Add README and MIT license
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 15:26:43 -04:00
.gitignore Initial commit: web-msg Go service 2026-08-20 13:59:02 +00:00
go.mod Initial commit: web-msg Go service 2026-08-20 13:59:02 +00:00
go.sum Initial commit: web-msg Go service 2026-08-20 13:59:02 +00:00
health.go Add GET /health 2026-10-05 16:52:27 +00:00
health_test.go Add GET /health 2026-10-05 16:52:27 +00:00
LICENSE Add README and MIT license 2026-10-05 15:26:43 -04:00
README.md Add README and MIT license 2026-10-05 15:26:43 -04:00
server.go Add GET /health 2026-10-05 16:52:27 +00:00
server_test.go Bound request size and in-memory state; token-only Matrix auth 2026-10-02 17:22:24 +00:00
web-msg.env.example Bound request size and in-memory state; token-only Matrix auth 2026-10-02 17:22:24 +00:00
web-msg.jpg Initial commit: web-msg Go service 2026-08-20 13:59:02 +00:00

web-msg

Backend for a website chat widget, bridged to a Matrix room. Visitor messages are posted into the room; the operator answers from any Matrix client and the answer is delivered back to the visitor's browser by polling. The widget front end itself is not part of this repository.

How it works

  • POST /send takes {"session_id": "...", "message": "..."} from the widget and forwards it to the configured room as <session_id>: <message>.
  • GET /poll?session_id=... returns (and clears) any queued replies for that session as a JSON array of {"content", "timestamp"}.
  • GET /health reports the service name, build commit and start time.

Routing operator messages back to a visitor:

  • A Matrix reply (or thread reply) to a forwarded visitor message goes to that visitor.
  • A plain message goes to the single visitor who sent something in the last 30 minutes. If there are none or several, nothing is delivered and the bot posts a notice in the room saying so.

State is held in memory only. Sessions idle for 24 hours are dropped. Request bodies are capped at 16 KiB and messages at 8 KiB.

Configuration

Settings come from the environment; see web-msg.env.example:

Variable Meaning
MATRIX_HOMESERVER Homeserver base URL
MATRIX_USER_ID The bot account's Matrix user ID
MATRIX_ROOM_ID Room the bot posts visitor messages to
MATRIX_ACCESS_TOKEN Access token for the bot account

The bot account must already be joined to the room.

Build and run

Needs Go.

go build
set -a; . ./web-msg.env; set +a
./web-msg

It listens on 127.0.0.1:4999; put a reverse proxy in front of it to expose /send and /poll to the widget.

Tests: go test ./...

License

MIT. See LICENSE.