Skip to content

Commit d0d71e9

Browse files
deferatogbin
authored andcommitted
Including the option to set a proxy when connecting using the SlackClient (errbotio#1180)
1 parent fe64f7c commit d0d71e9

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

docs/user_guide/configuration/slack.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ by setting up `BOT_IDENTITY` as follows::
3232
}
3333

3434

35+
Proxy setup
36+
-------------
37+
38+
In case you need to use a Proxy to connect to Slack,
39+
you can set the proxies with the token config.
40+
41+
BOT_IDENTITY = {
42+
'token': 'xoxb-4426949411-aEM7...',
43+
'proxies': {'http': 'some-http-proxy', 'https': 'some-https-proxy'}
44+
}
45+
46+
3547
Bot admins
3648
----------
3749

errbot/backends/slack.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ def __init__(self, config):
291291
super().__init__(config)
292292
identity = config.BOT_IDENTITY
293293
self.token = identity.get('token', None)
294+
self.proxies = identity.get('proxies', None)
294295
if not self.token:
295296
log.fatal(
296297
'You need to set your token (found under "Bot Integration" on Slack) in '
@@ -359,7 +360,11 @@ def update_alternate_prefixes(self):
359360
log.debug('Converted bot_alt_prefixes: %s', self.bot_config.BOT_ALT_PREFIXES)
360361

361362
def serve_once(self):
362-
self.sc = SlackClient(self.token)
363+
if not self.proxies:
364+
self.sc = SlackClient(self.token)
365+
else:
366+
self.sc = SlackClient(self.token, proxies=self.proxies)
367+
363368
log.info("Verifying authentication token")
364369
self.auth = self.api_call("auth.test", raise_errors=False)
365370
if not self.auth['ok']:

errbot/config-template.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@
170170

171171
## Slack mode (comment the others above if using this mode)
172172
# 'token': 'xoxb-4426949411-aEM7...',
173+
## you can also include the proxy for the SlackClient connection
174+
# 'proxies': {'http': 'some-http-proxy', 'https': 'some-https-proxy'}
173175

174176
## Telegram mode (comment the others above if using this mode)
175177
# 'token': '103419016:AAbcd1234...',

0 commit comments

Comments
 (0)