diff --git a/django_telegrambot/apps.py b/django_telegrambot/apps.py index 1ffacbb..9df2953 100644 --- a/django_telegrambot/apps.py +++ b/django_telegrambot/apps.py @@ -163,10 +163,15 @@ def ready(self): allowed_updates = b.get('ALLOWED_UPDATES', None) timeout = b.get('TIMEOUT', None) + proxy = b.get('PROXY', None) if self.mode == WEBHOOK_MODE: try: - bot = telegram.Bot(token=token) + request = None + if proxy: + request = telegram.utils.request.Request(proxy_url=proxy['proxy_url'], urllib3_proxy_kwargs=proxy['urllib3_proxy_kwargs']) + + bot = telegram.Bot(token=token, request=request) DjangoTelegramBot.dispatchers.append(Dispatcher(bot, None, workers=0)) hookurl = '{}/{}/{}/'.format(webhook_site, webhook_base, token) @@ -188,7 +193,7 @@ def ready(self): else: try: - updater = Updater(token=token) + updater = Updater(token=token, request_kwargs=proxy) bot = updater.bot bot.delete_webhook() DjangoTelegramBot.updaters.append(updater) diff --git a/sampleproject/sampleproject/local_settings.sample.py b/sampleproject/sampleproject/local_settings.sample.py index 6ddf1c5..d0bcadd 100644 --- a/sampleproject/sampleproject/local_settings.sample.py +++ b/sampleproject/sampleproject/local_settings.sample.py @@ -53,6 +53,17 @@ #'POLL_READ_LATENCY':(Optional[float|int]), # Grace time in seconds for receiving the reply from #server. Will be added to the `timeout` value and used as the read timeout from #server (Default: 2). + + #'PROXY':(Optional[dict]), # Use proxy to communicate with Telegram API server. Example: + # { + # 'proxy_url': 'socks5://ip:port', + # 'urllib3_proxy_kwargs': { + # 'username': 'username', + # 'password': 'password' + # } + # } + #Default is not to use any proxy. + }, #Other bots here with same structure. ],