@@ -186,7 +186,7 @@ The arguments passed to this callback are:
186186` ` ` python
187187async def check_media_file_for_spam(
188188 file_wrapper: "synapse.rest.media.v1.media_storage.ReadableFileWrapper",
189- file_info: "synapse.rest.media.v1._base.FileInfo"
189+ file_info: "synapse.rest.media.v1._base.FileInfo",
190190) -> bool
191191` ` `
192192
@@ -223,6 +223,66 @@ Called after successfully registering a user, in case the module needs to perfor
223223operations to keep track of them. (e.g. add them to a database table). The user is
224224represented by their Matrix user ID.
225225
226+ # ### Third party rules callbacks
227+
228+ Third party rules callbacks allow module developers to add extra checks to verify the
229+ validity of incoming events. Third party event rules callbacks can be registered using
230+ the module API's `register_third_party_rules_callbacks` method.
231+
232+ The available third party rules callbacks are :
233+
234+ ` ` ` python
235+ async def check_event_allowed(
236+ event: "synapse.events.EventBase",
237+ state_events: "synapse.types.StateMap",
238+ ) -> Tuple[bool, Optional[dict]]
239+ ` ` `
240+
241+ **<span style="color:red">
242+ This callback is very experimental and can and will break without notice. Module developers
243+ are encouraged to implement `check_event_for_spam` from the spam checker category instead.
244+ </span>**
245+
246+ Called when processing any incoming event, with the event and a `StateMap`
247+ representing the current state of the room the event is being sent into. A `StateMap` is
248+ a dictionary that maps tuples containing an event type and a state key to the
249+ corresponding state event. For example retrieving the room's `m.room.create` event from
250+ the `state_events` argument would look like this : ` state_events.get(("m.room.create", ""))` .
251+ The module must return a boolean indicating whether the event can be allowed.
252+
253+ Note that this callback function processes incoming events coming via federation
254+ traffic (on top of client traffic). This means denying an event might cause the local
255+ copy of the room's history to diverge from that of remote servers. This may cause
256+ federation issues in the room. It is strongly recommended to only deny events using this
257+ callback function if the sender is a local user, or in a private federation in which all
258+ servers are using the same module, with the same configuration.
259+
260+ If the boolean returned by the module is `True`, it may also tell Synapse to replace the
261+ event with new data by returning the new event's data as a dictionary. In order to do
262+ that, it is recommended the module calls `event.get_dict()` to get the current event as a
263+ dictionary, and modify the returned dictionary accordingly.
264+
265+ Note that replacing the event only works for events sent by local users, not for events
266+ received over federation.
267+
268+ ` ` ` python
269+ async def on_create_room(
270+ requester: "synapse.types.Requester",
271+ request_content: dict,
272+ is_requester_admin: bool,
273+ ) -> None
274+ ` ` `
275+
276+ Called when processing a room creation request, with the `Requester` object for the user
277+ performing the request, a dictionary representing the room creation request's JSON body
278+ (see [the spec](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-createroom)
279+ for a list of possible parameters), and a boolean indicating whether the user performing
280+ the request is a server admin.
281+
282+ Modules can modify the `request_content` (by e.g. adding events to its `initial_state`),
283+ or deny the room's creation by raising a `module_api.errors.SynapseError`.
284+
285+
226286# ## Porting an existing module that uses the old interface
227287
228288In order to port a module that uses Synapse's old module interface, its author needs to :
0 commit comments