diff --git a/CHANGELOG.md b/CHANGELOG.md index 7271b7b5..f9a9b113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * The option is only safe to enable on single-user instances, using it anywhere else will cause ghost user profiles to flip back and forth between personal and default ones. +* Added config option to notify Matrix room if bridging an incoming message + fails. ### Improved * Updated Docker image to Alpine 3.17. diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 9e397a3a..492bbe07 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -151,6 +151,7 @@ class Config(BaseBridgeConfig): copy("bridge.private_chat_portal_meta") copy("bridge.delivery_receipts") copy("bridge.delivery_error_reports") + copy("bridge.incoming_bridge_error_reports") copy("bridge.message_status_events") copy("bridge.resend_bridge_info") copy("bridge.mute_bridging") diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index 0f01d0c0..0b80346f 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -317,6 +317,8 @@ bridge: delivery_receipts: false # Whether or not delivery errors should be reported as messages in the Matrix room. delivery_error_reports: false + # Should errors in incoming message handling send a message to the Matrix room? + incoming_bridge_error_reports: false # Whether the bridge should send the message status as a custom com.beeper.message_send_status event. message_status_events: false # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 67d61031..b46db06f 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -3266,6 +3266,26 @@ class Portal(DBPortal, BasePortal): async def handle_telegram_message( self, source: au.AbstractUser, sender: p.Puppet | None, evt: Message + ) -> None: + try: + await self._handle_telegram_message(source, sender, evt) + except Exception: + sender_id = sender.tgid if sender else None + self.log.exception( + f"Failed to handle Telegram message {evt.id} from {sender_id} via {source.tgid}" + ) + if self.config["bridge.incoming_bridge_error_reports"]: + intent = sender.intent_for(self) if sender else self.main_intent + await self._send_message( + intent, + TextMessageEventContent( + msgtype=MessageType.NOTICE, + body="Error processing message from Telegram", + ), + ) + + async def _handle_telegram_message( + self, source: au.AbstractUser, sender: p.Puppet | None, evt: Message ) -> None: if not self.mxid: self.log.trace("Got telegram message %d, but no room exists, creating...", evt.id)