From 2cfc292c77db01c83347dbb2db330fe3a9cb7ee1 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Wed, 18 Jun 2025 17:58:09 +0100 Subject: [PATCH] Allow sending server notices via Module API --- synapse/module_api/__init__.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/synapse/module_api/__init__.py b/synapse/module_api/__init__.py index 656fe323f3..a974b1d08d 100644 --- a/synapse/module_api/__init__.py +++ b/synapse/module_api/__init__.py @@ -1892,6 +1892,33 @@ class ModuleApi: """Returns the current server time in milliseconds.""" return self._clock.time_msec() + async def send_server_notice( + self, user_id: str, type: str, event_content: JsonDict + ) -> JsonDict: + """Send a server notice to a user. + + Added in Synapse v1.133.0. + + Args: + user_id: The full user ID to send the server notice to. This must be a user + local to this homeserver. + type: The type of event to send. e.g. m.room.message + event_content: A dictionary representing the content of the event to send. + + Returns: + The event that was sent. If state event deduplication happened, then + the previous, duplicate event instead. + + Raises: + SynapseError if the event was not allowed. + """ + # Create and send the notice + event = await self._hs.get_server_notices_manager().send_notice( + user_id=user_id, event_content=event_content, type=type + ) + + return event + class PublicRoomListManager: """Contains methods for adding to, removing from and querying whether a room