Expand description
mxblocks: structured extras (“blocks”) on an ordinary Matrix
m.room.message (buttons, chips, tables, charts, cards, progress, …),
under the content key RICH_KEY. Clients that know the key (the
Element Web module in packages/mxblocks-element/) render it; everyone else sees
body/formatted_body and can use reactions, so the text must stand
alone. Normative spec: docs/spec.md.
"com.ianm.mtrix": {
"v": 1,
"blocks": [
{ "type": "buttons", "buttons": [
{ "label": "Send", "style": "primary", "action": { "type": "react", "key": "✅" } },
{ "label": "Drop", "style": "danger", "action": { "type": "react", "key": "❌" } }
] },
{ "type": "table", "columns": ["item", "price"], "rows": [["A", 10]] }
]
}A react action makes the client send an m.reaction annotation with
key on the message; a send action sends body as a message from the
clicking user. Action blocks (buttons, chips) are typed. Display
blocks (DISPLAY_TYPES) are carried as JSON and only checked for their
required fields and size; the renderer parses them defensively anyway.
Unknown block types load as Block::Unknown (so newer payloads still
deserialize) but don’t Rich::validate.
A stream block marks a reply the sender is still writing:
{"type": "stream", "id": "<id>", "url": "https://…/stream/<id>", "state": "live"}, "done" in the final edit. The renderer may follow
url (SSE) while it is live; the body is the fallback, kept current by
edits.
§Content keys
Default readers accept RICH_KEYS. Writers use WriteKey (including
caller-selected keys), while ContentKeys configures both the write key
and the exact read aliases. Applications can choose their own namespace.
Structs§
- Button
- One button or chip: a label and what a click does.
- Content
Keys - A writer namespace and an explicit, ordered set of reader namespaces.
- Math
- A math block’s TeX and whether it is display math (the default).
- Prompts
- The items of a
buttons/chipsblock plus the fields every block may carry. Shaped after MSC4139m.prompts: the items are preset prompts with stable ids,scopelists who may answer. - Rich
- A rich payload: the object stored under the content key
(
{"v":1,"blocks":[...]}).
Enums§
- Action
- What a button click does, tagged by
typeon the wire. - Block
- One entry of
blocks, tagged by itstypefield on the wire. - Kind
- The JSON kind a required display-block field must have.
- Stream
State - A
streamblock’s state. - Style
- A button’s look.
- Write
Key - Which key a writer puts the payload (and a click’s
.used, and an album’s.album) under. Default readers accept the public compatibility keys; useContentKeysfor custom reader namespaces.
Constants§
- ALBUM_
KEYS <key>.album: the gallery marker on album images, for every key inRICH_KEYS, in the same order.- BLOCK_
VERSION - The block version every block type is at.
- DISPLAY_
TYPES - JSON block types (display blocks, plus
form), with the fields each must have (docs/spec.md). - FORM_
KINDS - The field kinds a form may use (
fields[].kind). - FORM_
REPLY_ FORMAT - What a submit click sends (documentation; the Element module builds it).
- MAX_
BLOCKS - Blocks in one payload.
- MAX_
BLOCK_ BYTES - Serialized size of one display block, in bytes.
- MAX_
BUTTONS - Buttons in one
buttonsblock. - MAX_
CAPTION - Captions, alt texts and gallery titles, in characters.
- MAX_
CARD_ ACTIONS card.actions(ChatGPT Apps SDK: an inline card has at most 2 actions).- MAX_
CAROUSEL - Items in
cards(ChatGPT inline carousel: 3 to 8; fewer render as single cards). - MAX_
CAROUSEL_ ACTIONS - Actions per carousel item.
- MAX_
CHIPS - Chips in one
chipsblock. - MAX_
FALLBACK - A block’s
fallbacktext, in characters. - MAX_
FILE_ NAME - A file name, in characters.
- MAX_
FORM_ FIELDS - Fields in one form.
- MAX_
FORM_ OPTIONS - Options in one
selectorradiofield. - MAX_
FORM_ TEXT - A text field’s
maxlengthcap (and default). - MAX_
GALLERY - Most images in a
gallery. - MAX_KEY
- A reaction key, in characters.
- MAX_
LABEL - Button, chip and form labels, in characters: a whole sentence, which the renderer wraps.
- MAX_
MATH_ LINE math.alt/math.caption, in characters.- MAX_
OPTION_ VALUE - An option’s
value, in characters. - MAX_
PAYLOAD_ BYTES - Serialized size of the whole payload, in bytes (Matrix caps the whole
event at 65536, and
body/formatted_bodyneed room too). - MAX_
PREVIEW_ BYTES - A
fileblock’spreview, in bytes (UTF-8). - MAX_
PREVIEW_ LINES - A
fileblock’spreview: the first lines of a text file. - MAX_
SAFE_ INT - The largest integer canonical JSON allows (2^53 - 1); the smallest is its negation.
- MAX_
SCOPE scopeentries.- MAX_
SEEDS - Reaction seeds on one message.
- MAX_
SEND_ BODY - In UTF-16 code units, as the Element module (JS
length) counts. - MAX_
STREAM_ ID - Longest
streamblock id. - MAX_TEX
math.tex, in characters (the reference math renderer refuses longer input too).- MAX_
TRACKER_ ITEMS tracker.items.- MAX_
TRACKER_ STAGES tracker.stages.- MIN_
GALLERY - Images in a
gallery(validation refuses fewer or more; renderers draw 1 and drop past 20). - RICH_
KEY - The content key written today (
WriteKey::Legacy, the default). - RICH_
KEYS - Every content key a reader must accept, in the order to try them.
- RICH_
KEY_ NEW - The new content key (
WriteKey::New). Readers accept it now; writers switch to it once every renderer they target reads it. - RICH_
VERSION - The only payload version so far.
- STEP_
STATUSES progress.steps[].statusandtracker.stages[].status.- TRACKER_
KINDS tracker.kind.- TRACKER_
STATES tracker.state; the final edit setsdoneorcancelled.- USED_
KEYS <key>.used: what a click sent (on the clicking user’s message), for every key inRICH_KEYS, in the same order.
Functions§
- canonical_
content content(a whole event content,m.new_contentincluded) as canonical JSON, ready to send: floats become integers or decimal strings (canonical_numbers). Borrowed when it has no float; also borrowed, unchanged, when it can’t be fixed (an integer beyond ±MAX_SAFE_INT), so the homeserver’s own error reaches the caller.- canonical_
numbers - Every number in
v(any JSON, e.g. a whole event content with itsm.new_content) made canonical:number::canonicalizefrom the top. - canonicalize_
value - Rewrites every number in
vfor canonical JSON: a float with no fractional part in range becomes an integer, any other float its shortest decimal string (62.99→"62.99"). Integers outside ±(2^53 - 1) are an error (they would be rejected by the homeserver), as are NaN/Inf. - form_
fallback - A plain-text fallback for a (valid) form, for
body: the title, each field numbered with its options numbered, and how to answer by typing, e.g. - from_
args - The payload from
--buttonspecs (one buttons block) or a--richJSON text (not both);Nonewhen neither is given. - from_
args_ math from_argsplus--math: the math block first, then the buttons (--richwith--mathis refused: put the math block in the JSON).- has_
float - Whether
vhas a float anywhere (cheap check beforecanonical_numbers). - html_
escape - Escapes text for an HTML text node or a double-quoted attribute.
- image_
size - Width and height of a PNG, GIF, JPEG or WebP from its header, for
info.w/info.h(Element X sizes the image tile before loading it). - is_
decimal ^-?\d+(\.\d+)?([eE][-+]?\d+)?$.- is_mxc
mxc://server/mediaId(the renderer’s check, byte for byte).- is_num
- A numeric field’s value: an integer in ±(2^53 - 1) or a decimal string.
- math_
block - A math block (
--math TEX [--inline]). - non_
canonical - The path of the first float or out-of-range integer in
v, if any. - norm_
key - A reaction key as compared: without the U+FE0F variation selector (clients add or drop it).
- parse_
button - A
--buttonspec:[STYLE:]LABEL=react:KEYor[STYLE:]LABEL=send:BODY, STYLE one of primary, danger, default. The label can’t contain=(use--richfor that). - parse_
seeds --react-seed KEYS: comma-separated keys;""ornone: no seeds.- read_
album - An album marker under any of
ALBUM_KEYS(newest first). - read_
rich - The payload of an event
contentunder any ofRICH_KEYS: the first key, newest first, whose value deserializes. Not validated: the payload may come from a newer sender (unknown blocks load ascrate::Block::Unknown). - read_
used - A click’s
.usedecho under any ofUSED_KEYS(newest first). - rich_
from_ value - A payload from JSON, made canonical (
Rich::canonicalize) and validated, asRich::parsedoes with text. - rich_
value - The raw payload of an event
contentunder any ofRICH_KEYS(the newest key present wins), with the key it was under. - seeds
- The reactions to seed:
given(--react-seed), else the react keys. - strip_
rich - Removes the payload under every key in
RICH_KEYS(an edit that drops the blocks). Whether any was there. - text_
preview - The start of a text file for a
fileblock’spreview: at mostMAX_PREVIEW_LINESlines andMAX_PREVIEW_BYTESbytes, cut at a character boundary.Nonefor binary data (a NUL, or invalid UTF-8 before the cut) and for blank text. - validate_
id - An MSC4139 prompt id (buttons, forms, form fields): 1 to 64 of
[A-Za-z0-9_.:-]. - validate_
key - A reaction key: 1..=
MAX_KEYcharacters, no whitespace. - validate_
seeds - Reaction seeds: valid keys, at most
MAX_SEEDS, no duplicates.