No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Satya Benson 200739f76a Migrate Matrix bridge to maintained mautrix-go client
Preserve reply routing, room/self filtering and initial-history suppression. Initialize the client before serving requests, escape visitor HTML, and update transitive security fixes. Exercise SDK send serialization and sync parsing with a mock homeserver.
2026-11-12 11:27:35 -05:00
.gitignore Initial commit: web-msg Go service 2026-08-20 13:59:02 +00:00
go.mod Migrate Matrix bridge to maintained mautrix-go client 2026-11-12 11:27:35 -05:00
go.sum Migrate Matrix bridge to maintained mautrix-go client 2026-11-12 11:27:35 -05: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
matrix_test.go Migrate Matrix bridge to maintained mautrix-go client 2026-11-12 11:27:35 -05:00
README.md Migrate Matrix bridge to maintained mautrix-go client 2026-11-12 11:27:35 -05:00
server.go Migrate Matrix bridge to maintained mautrix-go client 2026-11-12 11:27:35 -05:00
server_test.go Migrate Matrix bridge to maintained mautrix-go client 2026-11-12 11:27:35 -05: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. The service uses mautrix-go for the Matrix client API; encryption and the bridge framework are not enabled. Initial sync history is skipped after restart.

Build and run

Needs Go 1.27 or newer; the module selects Go 1.27.4 for security fixes.

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.