diff --git a/ROADMAP.md b/ROADMAP.md index adb624cc..8ea37c42 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -54,7 +54,7 @@ * [x] Automatic portal creation * [x] At startup * [x] When receiving invite or message - * [x] Private chat creation by inviting Matrix puppet of Telegram user to new room + * [x] Portal creation by inviting Matrix puppet of Telegram user to new room * [x] Option to use bot to relay messages for unauthenticated Matrix users (relaybot) * [x] Option to use own Matrix account for messages sent from other Telegram clients (double puppeting) * [ ] ‡ Calls (hard, not yet supported by Telethon) diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 71772b80..861569af 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -130,6 +130,7 @@ class Config(BaseBridgeConfig): copy("bridge.sync_direct_chat_list") copy("bridge.double_puppet_server_map") copy("bridge.double_puppet_allow_discovery") + copy("bridge.create_group_on_invite") if "bridge.login_shared_secret" in self: base["bridge.login_shared_secret_map"] = { base["homeserver.domain"]: self["bridge.login_shared_secret"] diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index 63923ba8..c3b311b4 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -312,6 +312,9 @@ bridge: kick_on_logout: true # Should the "* user joined Telegram" notice always be marked as read automatically? always_read_joined_telegram_notice: true + # auto-create group chat portals by inviting Matrix puppet of Telegram user to a room + # requires double-puppeting to be enabled + create_group_on_invite: true # Settings for backfilling messages from Telegram. backfill: # Whether or not the Telegram ghosts of logged in Matrix users should be diff --git a/mautrix_telegram/matrix.py b/mautrix_telegram/matrix.py index fce2a1d6..b1eceacd 100644 --- a/mautrix_telegram/matrix.py +++ b/mautrix_telegram/matrix.py @@ -71,6 +71,11 @@ class MatrixHandler(BaseMatrixHandler): evt: StateEvent, members: list[UserID], ) -> None: + if not invited_by.is_logged_in: + await puppet.default_mxid_intent.leave_room( + room_id, reason="You are not logged into this Telegram bridge" + ) + return double_puppet = await pu.Puppet.get_by_custom_mxid(invited_by.mxid) if not double_puppet or self.az.bot_mxid in members: if self.az.bot_mxid not in members: @@ -92,6 +97,8 @@ class MatrixHandler(BaseMatrixHandler): room_id, reason="You do not have the permissions to bridge this room." ) return + elif not self.config["bridge.create_group_on_invite"]: + return await double_puppet.intent.invite_user(room_id, self.az.bot_mxid)