Matrix Events
Everything in Matrix is an event. Understanding events is key to working with the protocol.
Event Structure
Every event has:
{
"type": "m.room.message",
"event_id": "$abc123:example.com",
"sender": "@user:example.com",
"room_id": "!room:example.com",
"origin_server_ts": 1234567890123,
"content": {
"msgtype": "m.text",
"body": "Hello"
}
}
Event Categories
Message Events
Appear in room timeline:
m.room.messagem.stickerm.room.encrypted
State Events
Define room state:
m.room.namem.room.topicm.room.memberm.room.power_levels
State events have a state_key field.
Ephemeral Events
Not persisted:
m.typingm.receiptm.presence
Common Event Types
m.room.message
{
"type": "m.room.message",
"content": {
"msgtype": "m.text",
"body": "Hello, world!"
}
}
Message types (msgtype):
| Type | Description |
|---|---|
m.text | Plain text |
m.notice | Bot/system message |
m.emote | /me action |
m.image | Image |
m.file | File |
m.audio | Audio |
m.video | Video |
m.location | Location |
m.room.member
{
"type": "m.room.member",
"state_key": "@user:example.com",
"content": {
"membership": "join",
"displayname": "User",
"avatar_url": "mxc://..."
}
}
Membership values:
invitejoinleavebanknock
m.room.power_levels
{
"type": "m.room.power_levels",
"state_key": "",
"content": {
"users_default": 0,
"events_default": 0,
"state_default": 50,
"ban": 50,
"kick": 50,
"redact": 50,
"invite": 0,
"users": {
"@admin:example.com": 100
}
}
}
m.reaction
{
"type": "m.reaction",
"content": {
"m.relates_to": {
"rel_type": "m.annotation",
"event_id": "$event:example.com",
"key": "👍"
}
}
}
Event Relationships
Replies
{
"content": {
"body": "> Original\n\nReply",
"m.relates_to": {
"m.in_reply_to": {
"event_id": "$original:example.com"
}
}
}
}
Threads
{
"content": {
"body": "Thread reply",
"m.relates_to": {
"rel_type": "m.thread",
"event_id": "$root:example.com"
}
}
}
Edits
{
"content": {
"body": "* Edited message",
"m.new_content": {
"body": "Edited message"
},
"m.relates_to": {
"rel_type": "m.replace",
"event_id": "$original:example.com"
}
}
}
Redaction
Redacted events have content removed:
{
"type": "m.room.message",
"content": {},
"unsigned": {
"redacted_because": {...}
}
}
Resources
Next: Rooms →