From 31801a436cf0c33c15c376bc2c3d41945518b525 Mon Sep 17 00:00:00 2001 From: Javier Cuevas Date: Thu, 23 May 2024 17:06:04 +0200 Subject: [PATCH 01/29] Add periodic connection refresh --- mautrix_telegram/abstract_user.py | 14 ++++++++++++++ mautrix_telegram/example-config.yaml | 2 ++ 2 files changed, 16 insertions(+) diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index 2eb96260..ef1df456 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -241,6 +241,20 @@ class AbstractUser(ABC): use_ipv6=self.config["telegram.connection.use_ipv6"], ) self.client.add_event_handler(self._update_catch) + self._schedule_reconnect() + + def _schedule_reconnect(self) -> None: + reconnect_interval = self.config["telegram.force_refresh_interval_seconds"] + if not reconnect_interval or reconnect_interval == 0: + return + refresh_time = time.time() + reconnect_interval + self.log.info("Scheduling forced reconnect in %d seconds. Connection will be refreshed at %s", reconnect_interval, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(refresh_time))) + self.loop.call_later(reconnect_interval, lambda: asyncio.create_task(self._reconnect())) + + async def _reconnect(self) -> None: + self.log.info("Reconnecting to Telegram...") + await self.stop() + await self.start() @abstractmethod async def on_signed_out(self, err: UnauthorizedError | AuthKeyError) -> None: diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index b23083e4..75da8958 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -581,6 +581,8 @@ telegram: # Should incoming updates be handled sequentially to make sure order is preserved on Matrix? sequential_updates: true exit_on_update_error: false + # Interval to force refresh the connection (full reconnect), default is 1 day. Set 0 to disable force refreshes. + force_refresh_interval_seconds: 10 # Telethon connection options. connection: From 716222a6716a6e0fadbce40dc381126d00fc48dd Mon Sep 17 00:00:00 2001 From: Javier Cuevas Date: Thu, 23 May 2024 17:18:06 +0200 Subject: [PATCH 02/29] Format to pass linting --- mautrix_telegram/abstract_user.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index ef1df456..cb480ccb 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -248,7 +248,11 @@ class AbstractUser(ABC): if not reconnect_interval or reconnect_interval == 0: return refresh_time = time.time() + reconnect_interval - self.log.info("Scheduling forced reconnect in %d seconds. Connection will be refreshed at %s", reconnect_interval, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(refresh_time))) + self.log.info( + "Scheduling forced reconnect in %d seconds. Connection will be refreshed at %s", + reconnect_interval, + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(refresh_time)), + ) self.loop.call_later(reconnect_interval, lambda: asyncio.create_task(self._reconnect())) async def _reconnect(self) -> None: From a35f6abfd17ed0671184fd5813ee52dd6e07ee83 Mon Sep 17 00:00:00 2001 From: Javier Cuevas Date: Fri, 24 May 2024 09:36:03 +0200 Subject: [PATCH 03/29] Change default for force_refresh_interval_seconds (disabled by default) --- mautrix_telegram/example-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index 75da8958..06b0e946 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -581,8 +581,8 @@ telegram: # Should incoming updates be handled sequentially to make sure order is preserved on Matrix? sequential_updates: true exit_on_update_error: false - # Interval to force refresh the connection (full reconnect), default is 1 day. Set 0 to disable force refreshes. - force_refresh_interval_seconds: 10 + # Interval to force refresh the connection (full reconnect). 0 disables it. + force_refresh_interval_seconds: 0 # Telethon connection options. connection: From 4b25e855e0a3ea5d8bc74a8b432fc4434637a86c Mon Sep 17 00:00:00 2001 From: Javier Cuevas Date: Fri, 24 May 2024 09:36:09 +0200 Subject: [PATCH 04/29] Add force_refresh_interval_seconds to config.py --- mautrix_telegram/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 14148881..84ed3d07 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -264,6 +264,7 @@ class Config(BaseBridgeConfig): copy("telegram.catch_up") copy("telegram.sequential_updates") copy("telegram.exit_on_update_error") + copy("telegram.force_refresh_interval_seconds") copy("telegram.connection.timeout") copy("telegram.connection.retries") From 6418202118483a3ed00d03bada3aa1027094d22d Mon Sep 17 00:00:00 2001 From: Javier Cuevas Date: Fri, 24 May 2024 09:39:20 +0200 Subject: [PATCH 05/29] Update mautrix_telegram/abstract_user.py Co-authored-by: Tulir Asokan --- mautrix_telegram/abstract_user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index cb480ccb..d3edf7ce 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -253,7 +253,7 @@ class AbstractUser(ABC): reconnect_interval, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(refresh_time)), ) - self.loop.call_later(reconnect_interval, lambda: asyncio.create_task(self._reconnect())) + self.loop.call_later(reconnect_interval, lambda: background_task.create(self._reconnect())) async def _reconnect(self) -> None: self.log.info("Reconnecting to Telegram...") From 0137bfcbf629d4f740c3c02641f1ef25d6f04bc4 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 9 Jul 2024 12:09:39 +0300 Subject: [PATCH 06/29] Update mautrix-python --- mautrix_telegram/portal.py | 15 ++++++--------- requirements.txt | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 6f0f51f6..40190987 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -2336,20 +2336,17 @@ class Portal(DBPortal, BasePortal): sender.command_status = None except (KeyError, TypeError): if not logged_in or ( - "filename" in content and content["filename"] != content.body + content.filename is not None and content.filename != content.body ): - if "filename" in content: - file_name = content["filename"] + if content.filename: + file_name = content.filename caption_content = TextMessageEventContent( msgtype=MessageType.TEXT, body=content.body, ) - if ( - "formatted_body" in content - and str(content.get("format")) == Format.HTML.value - ): - caption_content["formatted_body"] = content["formatted_body"] - caption_content["format"] = Format.HTML + if content.formatted_body and content.format == Format.HTML: + caption_content.formatted_body = content.formatted_body + caption_content.format = Format.HTML else: caption_content = None if caption_content: diff --git a/requirements.txt b/requirements.txt index 8677beac..7e3599de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ python-magic>=0.4,<0.5 commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 -mautrix>=0.20.4,<0.21 +mautrix>=0.20.5,<0.21 tulir-telethon==1.35.0a1 asyncpg>=0.20,<0.30 mako>=1,<2 From 99f633e98dff84fcd5887085abb473e737a70b21 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 9 Jul 2024 12:13:36 +0300 Subject: [PATCH 07/29] Update telethon and changelog --- CHANGELOG.md | 3 ++- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f03b4231..0d724203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # v0.15.2 (unreleased) * Dropped support for Python 3.9. -* Updated Telegram API to layer 179. +* Updated Telegram API to layer 183. +* Added support for authenticated media downloads. * Added support for receiving reactions when using a bot account. * Added option to limit file size by chat type. * Fixed reply bridging breaking in some cases. diff --git a/requirements.txt b/requirements.txt index 7e3599de..861231db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 mautrix>=0.20.5,<0.21 -tulir-telethon==1.35.0a1 +tulir-telethon==1.37.0a1 asyncpg>=0.20,<0.30 mako>=1,<2 setuptools From efcf1535ffe0a2a2dacf24ff0b3e707967a8bae4 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 12 Jul 2024 20:25:57 +0300 Subject: [PATCH 08/29] Update mautrix-python --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 861231db..790b74b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ python-magic>=0.4,<0.5 commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 -mautrix>=0.20.5,<0.21 +mautrix>=0.20.6,<0.21 tulir-telethon==1.37.0a1 asyncpg>=0.20,<0.30 mako>=1,<2 From 0068341185423c11254a0f686fb65ee1e165d28a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 16 Jul 2024 11:53:19 +0300 Subject: [PATCH 09/29] Bump version to 0.15.2 --- CHANGELOG.md | 2 +- mautrix_telegram/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d724203..5e0dc213 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# v0.15.2 (unreleased) +# v0.15.2 (2024-07-16) * Dropped support for Python 3.9. * Updated Telegram API to layer 183. diff --git a/mautrix_telegram/__init__.py b/mautrix_telegram/__init__.py index 142ae072..401431ad 100644 --- a/mautrix_telegram/__init__.py +++ b/mautrix_telegram/__init__.py @@ -1,2 +1,2 @@ -__version__ = "0.15.1" +__version__ = "0.15.2" __author__ = "Tulir Asokan " From de4df572787966635a7a0e1fd81eceb829cbe612 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 15 Jan 2025 17:49:18 +0200 Subject: [PATCH 10/29] Ignore partial quotes on sticker messages --- mautrix_telegram/portal_util/message_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mautrix_telegram/portal_util/message_convert.py b/mautrix_telegram/portal_util/message_convert.py index dbff006a..680ddc78 100644 --- a/mautrix_telegram/portal_util/message_convert.py +++ b/mautrix_telegram/portal_util/message_convert.py @@ -282,7 +282,7 @@ class TelegramMessageConverter: elif isinstance(evt.reply_to, MessageReplyStoryHeader): return - if evt.reply_to.quote and content.msgtype.is_text: + if evt.reply_to.quote and content.msgtype and content.msgtype.is_text: content.ensure_has_html() quote_html = await formatter.telegram_text_to_matrix_html( source, evt.reply_to.quote_text, evt.reply_to.quote_entities From cc6a915ef4e05e26777175a4511e1d715407dbe5 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 15 Jan 2025 17:54:33 +0200 Subject: [PATCH 11/29] Update dependencies --- optional-requirements.txt | 4 ++-- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/optional-requirements.txt b/optional-requirements.txt index 2def256b..492d6863 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -7,8 +7,8 @@ aiodns brotli #/qr_login -pillow>=10.0.1,<11 -qrcode>=6,<8 +pillow>=10.0.1,<12 +qrcode>=6,<9 #/formattednumbers phonenumbers>=8,<9 diff --git a/requirements.txt b/requirements.txt index 790b74b7..be50ccc2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,6 @@ aiohttp>=3,<4 yarl>=1,<2 mautrix>=0.20.6,<0.21 tulir-telethon==1.37.0a1 -asyncpg>=0.20,<0.30 +asyncpg>=0.20,<1 mako>=1,<2 setuptools From e1b181ed552aa64bf04cae31c968860a501ff9ca Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 15 Jan 2025 18:00:15 +0200 Subject: [PATCH 12/29] Update mautrix-python to support MSC4190 --- mautrix_telegram/example-config.yaml | 9 ++++++++- requirements.txt | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index 06b0e946..b37b0f21 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -272,8 +272,15 @@ bridge: # Default to encryption, force-enable encryption in all portals the bridge creates # This will cause the bridge bot to be in private chats for the encryption to work properly. default: false - # Whether to use MSC2409/MSC3202 instead of /sync long polling for receiving encryption-related data. + # Whether to use MSC3202/MSC4203 instead of /sync long polling for receiving encryption-related data. + # This option is not yet compatible with standard Matrix servers like Synapse and should not be used. + # Changing this option requires updating the appservice registration file. appservice: false + # Whether to use MSC4190 instead of appservice login to create the bridge bot device. + # Requires the homeserver to support MSC4190 and the device masquerading parts of MSC3202. + # Only relevant when using end-to-bridge encryption, required when using encryption with next-gen auth (MSC3861). + # Changing this option requires updating the appservice registration file. + msc4190: false # Require encryption, drop any unencrypted messages. require: false # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. diff --git a/requirements.txt b/requirements.txt index be50ccc2..6a470406 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ python-magic>=0.4,<0.5 commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 -mautrix>=0.20.6,<0.21 +mautrix>=0.20.8b1,<0.21 tulir-telethon==1.37.0a1 asyncpg>=0.20,<1 mako>=1,<2 From caefda582b0ba43f53cb66e5c0dffc65ab22b890 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 19 Jan 2025 20:38:39 +0200 Subject: [PATCH 13/29] Disable kicking unauthenticated users --- mautrix_telegram/portal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 40190987..44e3544f 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -1200,7 +1200,7 @@ class Portal(DBPortal, BasePortal): continue if mx_user.is_bot: await mx_user.unregister_portal(*self.tgid_full) - if not self.has_bot: + if not self.has_bot and mx_user.tgid: try: await self.main_intent.kick_user( self.mxid, mx_user.mxid, "You had left this Telegram chat." From 88c3a935267c3c7e443cae486cd28b00999365a8 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 9 Mar 2025 13:07:29 +0200 Subject: [PATCH 14/29] Fix text in poll bridging --- mautrix_telegram/portal_util/message_convert.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mautrix_telegram/portal_util/message_convert.py b/mautrix_telegram/portal_util/message_convert.py index 680ddc78..fe2fbebb 100644 --- a/mautrix_telegram/portal_util/message_convert.py +++ b/mautrix_telegram/portal_util/message_convert.py @@ -763,18 +763,18 @@ class TelegramMessageConverter: _n += 1 return _n - text_answers = "\n".join(f"{n()}. {answer.text}" for answer in poll.answers) - html_answers = "\n".join(f"
  • {answer.text}
  • " for answer in poll.answers) + text_answers = "\n".join(f"{n()}. {answer.text.text}" for answer in poll.answers) + html_answers = "\n".join(f"
  • {answer.text.text}
  • " for answer in poll.answers) vote_command = f"{self.command_prefix} vote {poll_id}" content = TextMessageEventContent( msgtype=MessageType.TEXT, format=Format.HTML, body=( - f"Poll: {poll.question}\n{text_answers}\n" + f"Poll: {poll.question.text}\n{text_answers}\n" f"Vote with {vote_command} " ), formatted_body=( - f"Poll: {poll.question}
    \n" + f"Poll: {poll.question.text}
    \n" f"
      {html_answers}
    \n" f"Vote with {vote_command} <choice number>" ), From 070bfd4f552903f2d7dc2c55037b178865d4ee50 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 9 Mar 2025 13:10:39 +0200 Subject: [PATCH 15/29] Update dependencies --- optional-requirements.txt | 6 +++--- requirements.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/optional-requirements.txt b/optional-requirements.txt index 492d6863..f61c7b56 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -2,7 +2,7 @@ # Uncommented lines after the group definition insert things into that group. #/speedups -cryptg>=0.1,<0.5 +cryptg>=0.1,<0.6 aiodns brotli @@ -11,7 +11,7 @@ pillow>=10.0.1,<12 qrcode>=6,<9 #/formattednumbers -phonenumbers>=8,<9 +phonenumbers>=8,<10 #/metrics prometheus_client>=0.6,<0.21 @@ -22,7 +22,7 @@ pycryptodome>=3,<4 unpaddedbase64>=1,<3 #/sqlite -aiosqlite>=0.16,<0.21 +aiosqlite>=0.16,<0.22 #/proxy python-socks[asyncio] diff --git a/requirements.txt b/requirements.txt index 6a470406..0deccbc2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 mautrix>=0.20.8b1,<0.21 -tulir-telethon==1.37.0a1 +tulir-telethon==1.99.0a1 asyncpg>=0.20,<1 mako>=1,<2 setuptools From c70ab2a12b7fb23c0a9a31c376ac7110cd5e22bd Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 19 Mar 2025 20:04:43 +0200 Subject: [PATCH 16/29] Update Telethon --- mautrix_telegram/portal.py | 2 +- mautrix_telegram/portal_util/sponsored_message.py | 2 +- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 44e3544f..a6a2c4c8 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -70,7 +70,6 @@ from telethon.tl.functions.channels import ( InviteToChannelRequest, JoinChannelRequest, UpdateUsernameRequest, - ViewSponsoredMessageRequest, ) from telethon.tl.functions.messages import ( AddChatUserRequest, @@ -87,6 +86,7 @@ from telethon.tl.functions.messages import ( SetTypingRequest, UnpinAllMessagesRequest, UpdatePinnedMessageRequest, + ViewSponsoredMessageRequest, ) from telethon.tl.patched import Message, MessageService from telethon.tl.types import ( diff --git a/mautrix_telegram/portal_util/sponsored_message.py b/mautrix_telegram/portal_util/sponsored_message.py index ec6ca286..1a86b074 100644 --- a/mautrix_telegram/portal_util/sponsored_message.py +++ b/mautrix_telegram/portal_util/sponsored_message.py @@ -18,7 +18,7 @@ from __future__ import annotations import base64 import html -from telethon.tl.functions.channels import GetSponsoredMessagesRequest +from telethon.tl.functions.messages import GetSponsoredMessagesRequest from telethon.tl.types import Channel, InputChannel, PeerChannel, PeerUser, SponsoredMessage, User from telethon.tl.types.messages import SponsoredMessages, SponsoredMessagesEmpty diff --git a/requirements.txt b/requirements.txt index 0deccbc2..9cb7f50a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 mautrix>=0.20.8b1,<0.21 -tulir-telethon==1.99.0a1 +tulir-telethon==1.99.0a2 asyncpg>=0.20,<1 mako>=1,<2 setuptools From 6480e7925e3353200b894ddc86e2880409b01ba3 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 19 Mar 2025 20:20:23 +0200 Subject: [PATCH 17/29] Fix login QR filename --- mautrix_telegram/commands/telegram/auth.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mautrix_telegram/commands/telegram/auth.py b/mautrix_telegram/commands/telegram/auth.py index 0a75b429..e1dc45ba 100644 --- a/mautrix_telegram/commands/telegram/auth.py +++ b/mautrix_telegram/commands/telegram/auth.py @@ -121,6 +121,7 @@ async def login_qr(evt: CommandEvent) -> EventID: mxc = await evt.az.intent.upload_media(qr, "image/png", "login-qr.png", len(qr)) content = MediaMessageEventContent( body=qr_login.url, + filename="login-qr.png", url=mxc, msgtype=MessageType.IMAGE, info=ImageInfo(mimetype="image/png", size=len(qr), width=size, height=size), From 530bd9e52e15c0fe4237756cd7880f4fafa8ddf1 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 19 Apr 2025 15:32:39 +0300 Subject: [PATCH 18/29] Update telethon --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9cb7f50a..d62d6182 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 mautrix>=0.20.8b1,<0.21 -tulir-telethon==1.99.0a2 +tulir-telethon==1.99.0a4 asyncpg>=0.20,<1 mako>=1,<2 setuptools From 8fbd723bfab367484ae97b36bb757d745c99308c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 7 May 2025 13:40:39 +0300 Subject: [PATCH 19/29] Enable captions by default --- mautrix_telegram/example-config.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index b37b0f21..8229c3e5 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -216,8 +216,7 @@ bridge: # to resolve redirects in invite links. invite_link_resolve: false # Send captions in the same message as images. This will send data compatible with both MSC2530 and MSC3552. - # This is currently not supported in most clients. - caption_in_message: false + caption_in_message: true # Maximum size of image in megabytes before sending to Telegram as a document. image_as_file_size: 10 # Maximum number of pixels in an image before sending to Telegram as a document. Defaults to 4096x4096 = 16777216. From c7dd08ecd1c0a9942db3bba40f14276f487d3984 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 16 Jun 2025 13:20:07 +0300 Subject: [PATCH 20/29] Update dependencies --- optional-requirements.txt | 2 +- requirements.txt | 4 ++-- setup.py | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/optional-requirements.txt b/optional-requirements.txt index f61c7b56..3fd62c53 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -14,7 +14,7 @@ qrcode>=6,<9 phonenumbers>=8,<10 #/metrics -prometheus_client>=0.6,<0.21 +prometheus_client>=0.6,<0.23 #/e2be python-olm>=3,<4 diff --git a/requirements.txt b/requirements.txt index d62d6182..fd9dd6ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,8 +3,8 @@ python-magic>=0.4,<0.5 commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 -mautrix>=0.20.8b1,<0.21 -tulir-telethon==1.99.0a4 +mautrix>=0.20.8,<0.21 +tulir-telethon==1.99.0a6 asyncpg>=0.20,<1 mako>=1,<2 setuptools diff --git a/setup.py b/setup.py index 94a23aae..6d8642e5 100644 --- a/setup.py +++ b/setup.py @@ -63,6 +63,7 @@ setuptools.setup( "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ], package_data={"mautrix_telegram": [ "web/public/*.mako", "web/public/*.png", "web/public/*.css", From 9ab2ee2970ebfc766a8a13baf61d700d00ccb5a1 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 16 Jun 2025 13:24:17 +0300 Subject: [PATCH 21/29] Disable reply fallbacks by default --- mautrix_telegram/example-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index 8229c3e5..3a08ff27 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -352,7 +352,7 @@ bridge: private_chat_portal_meta: default # Disable generating reply fallbacks? Some extremely bad clients still rely on them, # but they're being phased out and will be completely removed in the future. - disable_reply_fallbacks: false + disable_reply_fallbacks: true # Should cross-chat replies from Telegram be bridged? Most servers and clients don't support this. cross_room_replies: false # Whether or not the bridge should send a read receipt from the bridge bot when a message has From 31846e7a982e60d67ba1c5949771b6776cf2705f Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 16 Jun 2025 13:33:52 +0300 Subject: [PATCH 22/29] Update changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e0dc213..6bffad8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# v0.15.3 (unreleased) + +* Updated Telegram API to layer 204. +* Added support for MSC4190. +* Enabled captions by default, as they are now supported by most clients. + * Existing configs will still need to enable `caption_in_message` manually. +* Fixed bridging sticker messages with partial quote replies from Telegram. +* Fixed text in poll bridging. +* Disabled kicking unauthenticated users from portals. + # v0.15.2 (2024-07-16) * Dropped support for Python 3.9. From 35f137ccc19c8b28d6b86d46276cb38172592d45 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 15 Jul 2025 14:20:19 +0300 Subject: [PATCH 23/29] Hardcode v11 for new rooms Upcoming breaking changes in room v12 prevent safely using the default room version and security embargoes prevent fixing them ahead of time. --- mautrix_telegram/portal.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index a6a2c4c8..6b4b22ea 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -1038,6 +1038,7 @@ class Portal(DBPortal, BasePortal): initial_state=initial_state, creation_content=creation_content, beeper_auto_join_invites=autojoin_invites, + room_version="11", ) if not room_id: raise Exception(f"Failed to create room") From 53bf278f1e816642b5c9948d6d020e66dea4f3b8 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 16 Jul 2025 11:50:47 +0300 Subject: [PATCH 24/29] Bump version to 0.15.3 --- CHANGELOG.md | 4 +++- mautrix_telegram/__init__.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bffad8c..8bfcac29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ -# v0.15.3 (unreleased) +# v0.15.3 (2025-07-16) * Updated Telegram API to layer 204. * Added support for MSC4190. * Enabled captions by default, as they are now supported by most clients. * Existing configs will still need to enable `caption_in_message` manually. +* Changed new room creation to hardcode room v11 to avoid v12 rooms being + created before proper support for them can be added. * Fixed bridging sticker messages with partial quote replies from Telegram. * Fixed text in poll bridging. * Disabled kicking unauthenticated users from portals. diff --git a/mautrix_telegram/__init__.py b/mautrix_telegram/__init__.py index 401431ad..610cc0d7 100644 --- a/mautrix_telegram/__init__.py +++ b/mautrix_telegram/__init__.py @@ -1,2 +1,2 @@ -__version__ = "0.15.2" +__version__ = "0.15.3" __author__ = "Tulir Asokan " From b65a1cc60ae14e4ca9f2938d3458ff691ee41a37 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 16 Jul 2025 23:50:21 +0300 Subject: [PATCH 25/29] Update Docker image to Alpine 3.22 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 865bb22b..c78cba3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM dock.mau.dev/tulir/lottieconverter:alpine-3.19 +FROM dock.mau.dev/tulir/lottieconverter:alpine-3.22 RUN apk add --no-cache \ python3 py3-pip py3-setuptools py3-wheel \ From 2f34ebfed92df5d30ea10909582faa1c6a99867f Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 12 Aug 2025 16:20:45 +0300 Subject: [PATCH 26/29] Disable kicking unauthenticated joiners too --- mautrix_telegram/matrix.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/mautrix_telegram/matrix.py b/mautrix_telegram/matrix.py index 55fd3bec..fe6b3d46 100644 --- a/mautrix_telegram/matrix.py +++ b/mautrix_telegram/matrix.py @@ -155,14 +155,6 @@ class MatrixHandler(BaseMatrixHandler): room_id, user.mxid, "You are not whitelisted on this Telegram bridge." ) return - elif not await user.is_logged_in() and not portal.has_bot: - await portal.main_intent.kick_user( - room_id, - user.mxid, - "This chat does not have a bot on the Telegram side for relaying messages sent by" - " unauthenticated Matrix users.", - ) - return self.log.debug(f"{user.mxid} joined {room_id}") if await user.is_logged_in() or portal.has_bot: From 4641215e97a4f9bd958d7b51c9c531fe80d9c0f1 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 12 Aug 2025 16:21:05 +0300 Subject: [PATCH 27/29] Update issue templates --- .github/ISSUE_TEMPLATE/bug.md | 13 +++++++++++-- .github/ISSUE_TEMPLATE/enhancement.md | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index 02ed2844..3703df9e 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -1,7 +1,16 @@ --- name: Bug report about: If something is definitely wrong in the bridge (rather than just a setup issue), - file a bug report. Remember to include relevant logs. -labels: bug + file a bug report. Remember to include relevant logs. Asking in the Matrix room first + is strongly recommended. +type: Bug --- + + diff --git a/.github/ISSUE_TEMPLATE/enhancement.md b/.github/ISSUE_TEMPLATE/enhancement.md index 264e67ff..a04fe588 100644 --- a/.github/ISSUE_TEMPLATE/enhancement.md +++ b/.github/ISSUE_TEMPLATE/enhancement.md @@ -1,6 +1,6 @@ --- name: Enhancement request about: Submit a feature request or other suggestion -labels: enhancement +type: Feature --- From 4f1482e7b09016ccec16ad008e24eb2af2f0c9d6 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 17 Aug 2025 14:11:11 +0300 Subject: [PATCH 28/29] Update mautrix-python --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fd9dd6ad..898e0898 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ python-magic>=0.4,<0.5 commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 -mautrix>=0.20.8,<0.21 +mautrix>=0.20.9rc3,<0.21 tulir-telethon==1.99.0a6 asyncpg>=0.20,<1 mako>=1,<2 From 280c74e9cdbb7f057f5778bb31843647cf39925d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 24 Sep 2025 00:07:53 +0300 Subject: [PATCH 29/29] Add config option to self-sign bot device --- mautrix_telegram/example-config.yaml | 4 ++++ optional-requirements.txt | 1 + requirements.txt | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index 3a08ff27..3f3d938f 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -280,6 +280,10 @@ bridge: # Only relevant when using end-to-bridge encryption, required when using encryption with next-gen auth (MSC3861). # Changing this option requires updating the appservice registration file. msc4190: false + # Should the bridge bot generate a recovery key and cross-signing keys and verify itself? + # Note that without the latest version of MSC4190, this will fail if you reset the bridge database. + # The generated recovery key will be printed in logs. + self_sign: false # Require encryption, drop any unencrypted messages. require: false # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. diff --git a/optional-requirements.txt b/optional-requirements.txt index 3fd62c53..09acf5fd 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -20,6 +20,7 @@ prometheus_client>=0.6,<0.23 python-olm>=3,<4 pycryptodome>=3,<4 unpaddedbase64>=1,<3 +base58>=2,<3 #/sqlite aiosqlite>=0.16,<0.22 diff --git a/requirements.txt b/requirements.txt index 898e0898..4feb3f19 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ python-magic>=0.4,<0.5 commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 -mautrix>=0.20.9rc3,<0.21 +mautrix>=0.21.0b5,<0.22 tulir-telethon==1.99.0a6 asyncpg>=0.20,<1 mako>=1,<2