Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSC2409: Proposal to send EDUs to appservices #2409

Merged
merged 29 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
96213b5
Initial proposal commit
Half-Shot Feb 15, 2019
c70ba2b
Add body of proposal
Half-Shot Feb 15, 2019
553837c
Merge branch 'hs/appservice-edus' of https://github.com/Half-Shot/mat…
Sorunome Jan 14, 2020
771cafe
rename file
Sorunome Jan 14, 2020
7912fda
finish up MSC
Sorunome Jan 14, 2020
9339848
address issues
Sorunome Sep 1, 2020
49f2087
change key names and add unstable prefix
Sorunome Oct 13, 2020
4a06e25
Merge branch 'master' into soru+hs/appservice-edus
turt2live May 18, 2021
fdee029
Clarifications; to-device handling
turt2live May 18, 2021
231084d
It's not exactly like sync
turt2live May 18, 2021
0c794bc
Move to-device messages
turt2live Nov 24, 2021
9d20145
Copy edu_type behaviour
turt2live Nov 24, 2021
91436e4
Add full transaction example
turt2live Nov 24, 2021
ce393b1
Add implementation notes for to-device cleanup
turt2live Nov 24, 2021
c21f86a
Use type instead of edu_type to match realities of implementations
Half-Shot Oct 20, 2023
15f4582
Add note to say ephemeral can be omitted.
Half-Shot Nov 15, 2023
d1783c4
Improve wording on why we use a seperate array.
Half-Shot Nov 15, 2023
f4b1ec8
push_ephemeral -> receive_ephemeral
tulir Sep 28, 2024
3a8fc4d
Fix some typos and clarify EDU room association
tulir Sep 28, 2024
18abe04
Clarify EDU formatting
tulir Sep 28, 2024
5989fc8
Explicitly list all event types
tulir Sep 28, 2024
d7fb52a
Delete to-device events
tulir Sep 28, 2024
7057ba0
Update spec link and fix typo
tulir Sep 30, 2024
20501b4
Add private read receipt rules
tulir Sep 30, 2024
5a745fd
Apply suggestions from code review
tulir Oct 1, 2024
fa4d518
Wrap lines
tulir Oct 1, 2024
5431045
Apply suggestions from code review
tulir Oct 1, 2024
842c44e
Explicitly mention to-device events are not here
tulir Oct 1, 2024
94e605e
Mention the possibility of more granular filtering
tulir Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions proposals/2409-appservice-edus.md
tulir marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# MSC2409: Proposal to send typing, presence and receipts to appservices

*Note: This proposal is a continuation of [MSC1888](https://github.com/matrix-org/matrix-doc/pull/1888)
and deprecates that one.*

The [appservice /transactions API](https://spec.matrix.org/v1.11/application-service-api/#put_matrixappv1transactionstxnid)
currently supports pushing PDU events (regular message and state events)
however it doesn't provision for EDU events (typing, presence and receipts). This means that bridges cannot
react to Matrix users who send any typing or presence information in a room the service is part of.

There is an interest amongst the community to have equal bridging on both sides of a bridge, so that
read reciepts and typing notifications can be seen on the remote side. To that end, this proposal
specifies how these can be pushed to an appservice.
turt2live marked this conversation as resolved.
Show resolved Hide resolved

## Proposal

### Changes to the registration file

In order that appservices don't get flooded with EDUs, appservices have to opt-in to receive them by
setting `receive_ephemeral` to true. A registration file could look like following:

```yaml
id: "IRC Bridge"
url: "http://127.0.0.1:1234"
as_token: "30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46"
hs_token: "312df522183efd404ec1cd22d2ffa4bbc76a8c1ccf541dd692eef281356bb74e"
sender_localpart: "_irc_bot"
# We want to receive EDUs
receive_ephemeral: true
tulir marked this conversation as resolved.
Show resolved Hide resolved
namespaces:
users:
- exclusive: true
regex: "@_irc_bridge_.*"
aliases:
- exclusive: false
regex: "#_irc_bridge_.*"
rooms: []
```

For now, receiving EDUs is all-or-nothing. A future MSC may add more granular
filtering capabilities for appservices.

### Changes to the /transactions/ API

The `PUT /_matrix/app/v1/transactions/{txnId}` API currently supports sending PDUs
via the `events` array.

```json
{
"events": [
{
"content": {
"membership": "join",
"avatar_url": "mxc://domain.com/SEsfnsuifSDFSSEF#auto",
"displayname": "Alice Margatroid"
},
"type": "m.room.member",
"event_id": "$143273582443PhrSn:domain.com",
"room_id": "!jEsUZKDJdhlrceRyVU:domain.com",
"sender": "@example:domain.com",
"origin_server_ts": 1432735824653,
"unsigned": {
"age": 1234
},
"state_key": "@alice:domain.com"
}
]
}
```

This proposal would extend the `PUT /_matrix/app/v1/transactions/` endpoint to include a new key
`ephemeral` to behave similar to the various sections of the CS API `/sync` endpoint. The `ephemeral` key
tulir marked this conversation as resolved.
Show resolved Hide resolved
MAY be omitted entirely if there are no ephemeral events to send.

```json
{
"ephemeral": [
turt2live marked this conversation as resolved.
Show resolved Hide resolved
richvdh marked this conversation as resolved.
Show resolved Hide resolved
{
"type": "m.typing",
turt2live marked this conversation as resolved.
Show resolved Hide resolved
"room_id": "!jEsUZKDJdhlrceRyVU:domain.com",
"content": {
"user_ids": [
"@alice:example.com"
]
}
},
{
"type": "m.receipt",
"room_id": "!jEsUZKDJdhlrceRyVU:domain.com",
"content": {
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
"@rikj:jki.re": {
"ts": 1436451550453
}
}
}
}
}
],
"events": [
// ...
]
}
```

The reason for a new key rather than bundling the events into `events` is that
existing appservices may mistake them for PDUs and might behave erratically.
While `events` may now be a somewhat misleading name, this is an acceptable tradeoff.

The array is effectively a combination of the `presence` and `ephemeral` sections of the
client-server `/sync` API. User-defined ephemeral events don't exist yet, which means there are
only three event types that can currently occur:
[`m.presence`](https://spec.matrix.org/v1.11/client-server-api/#mpresence),
[`m.typing`](https://spec.matrix.org/v1.11/client-server-api/#mtyping),
and [`m.receipt`](https://spec.matrix.org/v1.11/client-server-api/#mreceipt).

This proposal does not cover any other types of events which are sent as EDUs in the federation API,
such as to-device events or other e2ee features. Those are left to a separate MSC.

EDUs are formatted the same way as they are in C-S sync, with the addition of the `room_id` field
for room-scoped EDUs (`m.typing` and `m.receipt`). `room_id` is not present in the C-S API because
sync nests EDUs inside a room object, but appservices get a flat list of events in all rooms.

### Expectations of when an EDU should be pushed to an appservice

It is not clear at face value what should be pushed to an appservice. Appservices claim
namespaces of users which registers "interest" in the rooms where those users reside, as
well as claiming namespaces of rooms for explicit interest. However, not all EDUs are
associated with a single room (presence, etc).

If the EDU is capable of being associated to a particular room (i.e. `m.typing` and `m.receipt`),
it should be sent to the appservice under the same rules as regular events (interest in the room
means sending it). For EDUs which are not associated with a particular room, the appservice
receives the EDU if it contextually *would* apply. For example, a presence update for a user an
appservice shares a room with (or is under the appservice's namespace) would be sent to the
appservice.

For `m.receipt`, private read receipts (`m.read.private`) should only be sent for users within the
appservice's namespaces. Normal read receipts and threaded read receipts are always sent.

## Potential issues

Determining which EDUs to transmit to the appservice could lead to quite some overhead on the
homeserver side. Additionally, more network traffic is produced, potentially straining the local
network and the appservice more. As such, appservices have to opt-in to receive EDUs.

## Security considerations
Sorunome marked this conversation as resolved.
Show resolved Hide resolved

The homeserver needs to accurately determine which EDUs to send to the appservice, as to not leak
any unnecessary metadata about users. Particularly `m.presence` could be tricky, as no `room_id` is present in
that EDU.

## Unstable prefix

In the transaction body, instead of `ephemeral`, `de.sorunome.msc2409.ephemeral` is used.

In the registration file, instead of `receive_ephemeral`, `de.sorunome.msc2409.push_ephemeral` is used.