Add option to notify portal if incoming message bridging fails

This commit is contained in:
Tulir Asokan
2023-01-26 16:00:58 +02:00
parent e655e0a882
commit b1b633bcf9
4 changed files with 25 additions and 0 deletions

View File

@@ -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.

View File

@@ -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")

View File

@@ -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.

View File

@@ -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)