Add a host property to the SlackService

This commit is contained in:
Eryn Wells 2016-09-26 00:07:22 -04:00
parent 2c53416cc6
commit eead3717c6
2 changed files with 20 additions and 2 deletions

View file

@ -10,8 +10,22 @@ class SlackService(object):
_API_BASE = 'https://slack.com/api'
def __init__(self, token):
def __init__(self, token, host):
self.token = token
self.host = host
def permalink(self, channel, message):
'''
Generate a permalink to the given message object in the given channel.
Channel should be the name of the channel, without the leading '#'.
`message` should have a `ts` field.
'''
try:
ts = message['ts']
except KeyError:
return
ts = ts.replace('.', '')
return 'https://{}/archives/{}/p{}'.format(self.host, channel, ts)
#
# Endpoints