Skip to content

Commit 8ff102a

Browse files
committed
Merges #657 Closes #657 Closes #655
2 parents 1bbefb3 + a7cbc0b commit 8ff102a

3 files changed

Lines changed: 29 additions & 17 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ $ perceval rss 'https://blog.bitergia.com/feed/'
327327
```
328328

329329
### Slack
330+
331+
Slack backend requires an API token for authentication. Slack apps can be
332+
used to generate and configure this API token. The scopes required by a Slack
333+
app for the backend are `channels:history`, `channels:read` and `users:read`.
334+
To know more about Slack apps and its integration please refer the
335+
[Slack apps documentation](https://api.slack.com/start/overview).
336+
For more information about the scopes required by a Slack app please refer the
337+
[Scopes and permissions documentation](https://api.slack.com/scopes).
338+
339+
The following [script](https://gist.github.com/valeriocos/de31324625a3fab32449cf5d43b24075)
340+
can also be used to generate an OAuth2 token to access the Slack API.
341+
330342
```
331343
$ perceval slack C0001 --from-date 2016-01-12 -t abcedefghijk
332344
```

perceval/backends/core/slack.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Slack(Backend):
6161
:param archive: archive to store/retrieve items
6262
:param ssl_verify: enable/disable SSL verification
6363
"""
64-
version = '0.9.0'
64+
version = '0.9.1'
6565

6666
CATEGORIES = [CATEGORY_MESSAGE]
6767
EXTRA_SEARCH_FIELDS = {
@@ -302,9 +302,9 @@ class SlackClient(HttpClient):
302302
URL = urijoin(SLACK_URL, 'api', '%(resource)s')
303303

304304
AUTHORIZATION_HEADER = 'Authorization'
305-
RCONVERSATION_INFO = 'conversations.members'
306-
RCHANNEL_INFO = 'channels.info'
307-
RCHANNEL_HISTORY = 'channels.history'
305+
RCONVERSATION_MEMBERS = 'conversations.members'
306+
RCONVERSATION_INFO = 'conversations.info'
307+
RCONVERSATION_HISTORY = 'conversations.history'
308308
RUSER_INFO = 'users.info'
309309

310310
PCHANNEL = 'channel'
@@ -327,7 +327,7 @@ def conversation_members(self, conversation):
327327
"""
328328
members = 0
329329

330-
resource = self.RCONVERSATION_INFO
330+
resource = self.RCONVERSATION_MEMBERS
331331

332332
params = {
333333
self.PCHANNEL: conversation,
@@ -348,7 +348,7 @@ def conversation_members(self, conversation):
348348
def channel_info(self, channel):
349349
"""Fetch information about a channel."""
350350

351-
resource = self.RCHANNEL_INFO
351+
resource = self.RCONVERSATION_INFO
352352

353353
params = {
354354
self.PCHANNEL: channel,
@@ -361,7 +361,7 @@ def channel_info(self, channel):
361361
def history(self, channel, oldest=None, latest=None):
362362
"""Fetch the history of a channel."""
363363

364-
resource = self.RCHANNEL_HISTORY
364+
resource = self.RCONVERSATION_HISTORY
365365

366366
params = {
367367
self.PCHANNEL: channel,

tests/test_slack.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
from base import TestCaseBackendArchive
4545

4646

47-
SLACK_API_URL = 'https://slack.com/api'
48-
SLACK_CHANNEL_INFO_URL = SLACK_API_URL + '/channels.info'
49-
SLACK_CHANNEL_HISTORY_URL = SLACK_API_URL + '/channels.history'
50-
SLACK_CONVERSATION_MEMBERS = SLACK_API_URL + '/conversations.members'
51-
SLACK_USER_INFO_URL = SLACK_API_URL + '/users.info'
47+
SLACK_API_URL = 'https://slack.com/api/'
48+
SLACK_CHANNEL_INFO_URL = SLACK_API_URL + SlackClient.RCONVERSATION_INFO
49+
SLACK_CHANNEL_HISTORY_URL = SLACK_API_URL + SlackClient.RCONVERSATION_HISTORY
50+
SLACK_CONVERSATION_MEMBERS = SLACK_API_URL + SlackClient.RCONVERSATION_MEMBERS
51+
SLACK_USER_INFO_URL = SLACK_API_URL + SlackClient.RUSER_INFO
5252

5353

5454
def read_file(filename, mode='r'):
@@ -703,7 +703,7 @@ def test_conversation_members(self):
703703

704704
req = http_requests[0]
705705
self.assertEqual(req.method, 'GET')
706-
self.assertRegex(req.path, '/conversations.members')
706+
self.assertRegex(req.path, SlackClient.RCONVERSATION_MEMBERS)
707707

708708
for i in range(len(expected)):
709709
self.assertIn((SlackClient.AUTHORIZATION_HEADER, 'Bearer aaaa'), http_requests[i].headers._headers)
@@ -727,7 +727,7 @@ def test_channel_info(self):
727727

728728
req = http_requests[0]
729729
self.assertEqual(req.method, 'GET')
730-
self.assertRegex(req.path, '/channels.info')
730+
self.assertRegex(req.path, SlackClient.RCONVERSATION_INFO)
731731
self.assertDictEqual(req.querystring, expected)
732732
self.assertIn((SlackClient.AUTHORIZATION_HEADER, 'Bearer aaaa'), req.headers._headers)
733733

@@ -754,7 +754,7 @@ def test_history(self):
754754

755755
req = http_requests[0]
756756
self.assertEqual(req.method, 'GET')
757-
self.assertRegex(req.path, '/channels.history')
757+
self.assertRegex(req.path, SlackClient.RCONVERSATION_HISTORY)
758758
self.assertDictEqual(req.querystring, expected)
759759
self.assertIn((SlackClient.AUTHORIZATION_HEADER, 'Bearer aaaa'), req.headers._headers)
760760

@@ -781,7 +781,7 @@ def test_history_format_latest(self):
781781

782782
req = http_requests[0]
783783
self.assertEqual(req.method, 'GET')
784-
self.assertRegex(req.path, '/channels.history')
784+
self.assertRegex(req.path, SlackClient.RCONVERSATION_HISTORY)
785785
self.assertDictEqual(req.querystring, expected)
786786
self.assertIn((SlackClient.AUTHORIZATION_HEADER, 'Bearer aaaa'), req.headers._headers)
787787

@@ -804,7 +804,7 @@ def test_user(self):
804804

805805
req = http_requests[0]
806806
self.assertEqual(req.method, 'GET')
807-
self.assertRegex(req.path, '/users.info')
807+
self.assertRegex(req.path, SlackClient.RUSER_INFO)
808808
self.assertDictEqual(req.querystring, expected)
809809
self.assertIn((SlackClient.AUTHORIZATION_HEADER, 'Bearer aaaa'), req.headers._headers)
810810

0 commit comments

Comments
 (0)