feat(relay): named routes and replies routed back to a route #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/named-routes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements the relay-bot part of mxm/homelab#36.
Named routes
@bot !route set <name> <url>,!route reset <name>,!routelists all routes. Names: 1–32 ofa-z0-9-, notset|reset|route|name|help.!route set <url>/!route resetact ondefaultas before. The old single-routeroutestable is migrated at startup (one transaction) to(room_id, name)with each room's route asdefault.Display Name:prefix) names a route → post there with the rest astext; otherwise the whole text goes todefault. Payload gains"route".Who may trigger what
--command-user; everyone with--command-everyone).defaultwith its whole text (unchanged behaviour); an unmentioned reply is not forwarded. Sodefaultshould stay harmless (echo).Replies
/sendacceptsreplyRoute(route name) andcontext(JSON object ≤ 4 KiB, default{};contextalone → 400). After sending,event_id → room, route, contextgoes toreply_targetsinoutbox.sqlite, newest 1000 entries, max 30 days. If storing fails: HTTP 500 with the sentevent_id.m.relates_to.m.in_reply_to, ignoring threadis_falling_back) to such an event in the same room from a command user goes to that route without a mention, withroute,inReplyTo,context, andtext= the reply without its>fallback. If the route was removed meanwhile, the bot answers with a notice. Other replies are ordinary messages.>fallback is now stripped from the text of every reply.Tests
cargo fmt --check,cargo clippy --all-targets --all-features -- -D warnings, andcargo test --all-features(90 passed) with rustc/clippy 1.98.1. New tests cover parsing, migration, dispatch and permissions, reply routing, store bounds and expiry,/sendvalidation, and reply detection from raw events. No live Matrix test yet. One open point: the code relies on the SDK's decrypted event content containingm.relates_to.README also fixes the
/sendresponse example (event_id, as the code returns).🤖 Generated with Claude Code
/send accepts replyRoute (a route name) and context (a JSON object of at most 4 KiB, {} by default; context alone is refused). After sending, the bot stores event ID -> room, route and context in outbox.sqlite, keeping the newest 1000 entries for at most 30 days. If storing fails the answer is HTTP 500 with the sent event_id. A Matrix reply (m.relates_to.m.in_reply_to, not a thread's is_falling_back) to such an event, in the same room and from a command user, goes to that route without a mention. The payload adds route, inReplyTo and context, and text is the reply without its quoted fallback. If the route was removed meanwhile, the bot answers with a notice. Replies to other events, and from other senders, are ordinary messages: forwarded to default only when they mention the bot. A malformed relation is ignored instead of failing the sync. The quoted fallback is now stripped from the text of every reply, so the first word of a reply that mentions the bot can name a route. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>