Matrix Client-Server API SDK core for MoonBit: identifiers, event model, request builders, error model and a resumable /sync state machine. Sans-IO; bring your own HTTP transport.
| Package | Contents |
|---|---|
| ids | User, room, event IDs, room aliases, server names |
| api | Request/Response, error model, discovery, login, room endpoints |
| events | Event envelope, message content and relations, state contents, redaction |
| sync | Filters, /sync parsing, Store, gap filling, snapshots |
| send | Outbox: the idempotent send queue |
| client | Client: a session combining the above; prepare makes HTTP-ready requests |
| transport | Native only: HTTP with moonbitlang/async, run_sync_loop |
| cmd/echo_bot | Example bot |
async fn run(homeserver : String, user : String, password : String, txn_prefix : String) -> Unit {
let login = @api.login_request(Password(User(user), password~))
let session = @api.parse_login(@transport.request(homeserver, login))
let c = @client.Client::new(homeserver, session, txn_prefix~)
@transport.run_sync_loop(c, summary => {
for r in summary.rooms {
for e in r.events {
if e.kind() is Message(m) && m.body == "!ping" {
ignore(c.send_message(r.room_id, @events.notice("pong").reply_to(e.event_id)))
}
}
}
true
}, persist=snapshot => save_somewhere(snapshot))
}let req = c.prepare(c.sync_request()) // verb, url, headers, body
let resp = @api.Response::new(status, body) // from your HTTP client
let summary = c.on_sync_response(resp)
// Handle summary and enqueue replies, then atomically save c.snapshot().
while c.next_send(now_ms) is Some((txn_id, req)) {
// Atomically save c.snapshot() BEFORE sending req (also saves its txn ID).
// send req, then:
ignore(c.on_send_response(txn_id, @api.Response::new(status, body), now_ms))
}MATRIX_HOMESERVER=https://matrix.example.org MATRIX_USER=@bot:example.org MATRIX_PASSWORD=secret MATRIX_STATE=bot.json moon run --target native cmd/echo_botmoon check --target all --deny-warnmoon test --target allmoon fmtbash interop/run.shInstall
Download zipMatrix Client-Server API SDK core for MoonBit: identifiers, event model, request builders, error model and a resumable /sync state machine. Sans-IO; bring your own HTTP transport.