Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to connect via MTProxy. #344

Merged
merged 4 commits into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ telegram:
# Telethon proxy configuration.
# You must install PySocks from pip for proxies to work.
proxy:
# Allowed types: disabled, socks4, socks5, http
# Allowed types: disabled, socks4, socks5, http, mtproxy
type: disabled
# Proxy IP address and port.
address: 127.0.0.1
Expand Down
12 changes: 10 additions & 2 deletions mautrix_telegram/abstract_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def _proxy_settings(self) -> Optional[Tuple[int, str, str, str, str, str]]:
proxy_type = 2
elif proxy_type == "http":
proxy_type = 3
elif proxy_type == "mtproxy":
proxy_type = 4

return (proxy_type,
config["telegram.proxy.address"], config["telegram.proxy.port"],
Expand All @@ -119,6 +121,12 @@ def _init_client(self) -> None:
device = config["telegram.device_info.device_model"]
sysversion = config["telegram.device_info.system_version"]
appversion = config["telegram.device_info.app_version"]
import telethon
sot-tech marked this conversation as resolved.
Show resolved Hide resolved
connection = telethon.network.connection.ConnectionTcpFull
proxy = self._proxy_settings
if proxy is not None and proxy[0] == 4:
connection = telethon.network.connection.ConnectionTcpMTProxyRandomizedIntermediate
proxy = (proxy[1], proxy[2], proxy[5])

self.client = MautrixTelegramClient(
session=self.session,
Expand All @@ -135,8 +143,8 @@ def _init_client(self) -> None:
retry_delay=config["telegram.connection.retry_delay"],
flood_sleep_threshold=config["telegram.connection.flood_sleep_threshold"],
request_retries=config["telegram.connection.request_retries"],

proxy=self._proxy_settings,
connection=connection,
proxy=proxy,

loop=self.loop,
base_logger=base_logger
Expand Down