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
+2
View File
@@ -6,6 +6,8 @@
* The option is only safe to enable on single-user instances, using it * 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 anywhere else will cause ghost user profiles to flip back and forth between
personal and default ones. personal and default ones.
* Added config option to notify Matrix room if bridging an incoming message
fails.
### Improved ### Improved
* Updated Docker image to Alpine 3.17. * Updated Docker image to Alpine 3.17.
+1
View File
@@ -151,6 +151,7 @@ class Config(BaseBridgeConfig):
copy("bridge.private_chat_portal_meta") copy("bridge.private_chat_portal_meta")
copy("bridge.delivery_receipts") copy("bridge.delivery_receipts")
copy("bridge.delivery_error_reports") copy("bridge.delivery_error_reports")
copy("bridge.incoming_bridge_error_reports")
copy("bridge.message_status_events") copy("bridge.message_status_events")
copy("bridge.resend_bridge_info") copy("bridge.resend_bridge_info")
copy("bridge.mute_bridging") copy("bridge.mute_bridging")
+2
View File
@@ -317,6 +317,8 @@ bridge:
delivery_receipts: false delivery_receipts: false
# Whether or not delivery errors should be reported as messages in the Matrix room. # Whether or not delivery errors should be reported as messages in the Matrix room.
delivery_error_reports: false 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. # Whether the bridge should send the message status as a custom com.beeper.message_send_status event.
message_status_events: false 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. # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run.
+20
View File
@@ -3266,6 +3266,26 @@ class Portal(DBPortal, BasePortal):
async def handle_telegram_message( async def handle_telegram_message(
self, source: au.AbstractUser, sender: p.Puppet | None, evt: 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: ) -> None:
if not self.mxid: if not self.mxid:
self.log.trace("Got telegram message %d, but no room exists, creating...", evt.id) self.log.trace("Got telegram message %d, but no room exists, creating...", evt.id)