Skip to content

Commit

Permalink
Add proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
rafis committed Jun 26, 2018
1 parent ce10c5a commit 370ca53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions django_telegrambot/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions sampleproject/sampleproject/local_settings.sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
],
Expand Down

0 comments on commit 370ca53

Please sign in to comment.