Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't delete messages #86

Closed
leonard84 opened this issue Sep 8, 2020 · 8 comments
Closed

Can't delete messages #86

leonard84 opened this issue Sep 8, 2020 · 8 comments
Labels

Comments

@leonard84
Copy link

I want to delete all messages from the Travis-CI App older than one month. However, I only get exceptions.

When executing this command:
slack-cleaner --token <hidden> --message --channel ci --bot --before 20200801 --perform

Failed to delete (invalid_arguments)->
{   u'attachments': [   {   u'color': u'2eb886',
                            u'fallback': u'Build <https://travis-ci.com/spockframework/spock/builds/177459089?utm_source=slack&amp;utm_medium=notification|#2105> (<h
ttps://github.com/spockframework/spock/pull/1181|ca74b05>) of spockframework/spock@master in PR <https://github.com/spockframework/spock/pull/1181|#1181> by Marcin Z
aj\u0105czkowski passed in 46 min 55 sec',
                            u'id': 1,
                            u'mrkdwn_in': [u'text'],
                            u'text': u'Build <https://travis-ci.com/spockframework/spock/builds/177459089?utm_source=slack&amp;utm_medium=notification|#2105> (<https
://github.com/spockframework/spock/pull/1181|ca74b05>) of spockframework/spock@master in PR <https://github.com/spockframework/spock/pull/1181|#1181> by Marcin Zaj\u
0105czkowski passed in 46 min 55 sec'}],
    u'bot_id': u'B0556QQP4',
    u'subtype': u'bot_message',
    u'text': u'',
    u'ts': u'1595948956.000100',
    u'type': u'message'}
^CTraceback (most recent call last):
  File "/usr/local/bin/slack-cleaner", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 516, in main
    message_cleaner()
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 445, in message_cleaner
    clean_channel(channel_id, time_range, user_id=_user_id, bot=args.bot)
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 219, in clean_channel
    _clean_messages_impl(list_f, channel_id, time_range, user_id, bot)
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 190, in _clean_messages_impl
    delete_message_on_channel(channel_id, m)
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 236, in delete_message_on_channel
    slack.chat.delete(channel_id, message['ts'], as_user=args.as_user)
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 552, in delete
    'as_user': as_user
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 126, in post
    api, **kwargs
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 77, in _request
    url, timeout=self.timeout, proxies=self.proxies, **kwargs
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 114, in _session_post
    method='post', url=url, data=data, **kwargs
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python2.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python2.7/site-packages/urllib3/connectionpool.py", line 417, in _make_request
    httplib_response = conn.getresponse(buffering=True)
  File "/usr/local/lib/python2.7/httplib.py", line 1161, in getresponse
    response.begin()
  File "/usr/local/lib/python2.7/httplib.py", line 448, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python2.7/httplib.py", line 404, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/local/lib/python2.7/socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
  File "/usr/local/lib/python2.7/ssl.py", line 754, in recv
    return self.read(buflen)
  File "/usr/local/lib/python2.7/ssl.py", line 641, in read
    v = self._sslobj.read(len)
KeyboardInterrupt

I've tried the --as_user as was mentioned in #73

I get a slew of these messages

Failed to delete (cant_delete_message)->
{   u'attachments': [   {   u'color': u'a30200',
                            u'fallback': u'Build <https://travis-ci.com/spockframework/spock/builds/177258959?utm_source=slack&amp;utm_medium=notification|#2099> (<h
ttps://github.com/spockframework/spock/pull/1204|7f057e6>) of spockframework/spock@master in PR <https://github.com/spockframework/spock/pull/1204|#1204> by Bj\xf6rn
 Kautler failed in 37 min 54 sec',
                            u'id': 1,
                            u'mrkdwn_in': [u'text'],
                            u'text': u'Build <https://travis-ci.com/spockframework/spock/builds/177258959?utm_source=slack&amp;utm_medium=notification|#2099> (<https
://github.com/spockframework/spock/pull/1204|7f057e6>) of spockframework/spock@master in PR <https://github.com/spockframework/spock/pull/1204|#1204> by Bj\xf6rn Kau
tler failed in 37 min 54 sec'}],
    u'bot_id': u'B0556QQP4',
    u'subtype': u'bot_message',
    u'text': u'',
    u'ts': u'1595840987.000100',
    u'type': u'message'}
^CTraceback (most recent call last):
  File "/usr/local/bin/slack-cleaner", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 516, in main
    message_cleaner()
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 445, in message_cleaner
    clean_channel(channel_id, time_range, user_id=_user_id, bot=args.bot)
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 219, in clean_channel
    _clean_messages_impl(list_f, channel_id, time_range, user_id, bot)
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 190, in _clean_messages_impl
    delete_message_on_channel(channel_id, m)
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 236, in delete_message_on_channel
    slack.chat.delete(channel_id, message['ts'], as_user=args.as_user)
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 552, in delete
    'as_user': as_user
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 126, in post
    api, **kwargs
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 87, in _request
    response.headers.get('retry-after', DEFAULT_WAIT)

The Slack-Cleaner app has these scopes:

  • channels:history
  • channels:read
  • chat:write
  • groups:history
  • groups:read
  • users:read

Context

  • Version: 0.7.4
  • via Docker image

Side Note
It seems that one has to add the app to a channel, otherwise I get this error.

Deleting messages from channel scm
Traceback (most recent call last):
  File "/usr/local/bin/slack-cleaner", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 516, in main
    message_cleaner()
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 445, in message_cleaner
    clean_channel(channel_id, time_range, user_id=_user_id, bot=args.bot)
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 219, in clean_channel
    _clean_messages_impl(list_f, channel_id, time_range, user_id, bot)
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 141, in _clean_messages_impl
    res = list_f(latest, oldest).body
  File "/usr/local/lib/python2.7/site-packages/slack_cleaner/cli.py", line 217, in list_f
    return slack.conversations.history(channel_id, latest=latest, oldest=oldest, limit=1000)
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 172, in history
    'limit': limit
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 120, in get
    api, **kwargs
  File "/usr/local/lib/python2.7/site-packages/slacker/__init__.py", line 102, in _request
    raise Error(response.error)
slacker.Error: not_in_channel
@leonard84 leonard84 added the bug label Sep 8, 2020
@sgratzl
Copy link
Owner

sgratzl commented Sep 8, 2020

maybe related to #73

@leonard84
Copy link
Author

Yes, as I wrote with --as_user it changes from Failed to delete (invalid_arguments) to Failed to delete (cant_delete_message)

@1Rogue
Copy link

1Rogue commented Sep 8, 2020

Seemed to happen upon the same issue (at the same time no less!). Ran it with full perms on the bot user and the app access tokens; ran with both tokens as well (with --as_user as needed). I'm not getting backtraces (even on the first error), just this:

Failed to delete (cant_delete_message)->
{   u'team': u'T0L1219F0',
    u'text': u'<@U0L191X34>: is production rolled?',
    u'ts': u'1462825355.000122',
    u'type': u'message',
    u'user': u'U0L12DXB2'}

ad nauseum

@sgratzl
Copy link
Owner

sgratzl commented Sep 9, 2020

can you verify that you created the token as described in https://github.com/sgratzl/slack_cleaner2#token, please

@1Rogue
Copy link

1Rogue commented Sep 9, 2020

Indeed! It's made just according to that, and in fact I went ahead and gave it permissions it didn't even need. Everything short of admin.*, since those are enterprise.

If it helps, I'm trying to delete from the primary/#general channel:
slack-cleaner --token xoxb-00000000000-0000000000000-EEEEEEEEEEEEEEEEEEEEEEEE --message --channel gen --user "*" --as_user --perform

It definitely recognizes all the messages in there, but it doesn't seem to be capable of deleting them.

@leonard84
Copy link
Author

@sgratzl as I already wrote in my initial post, I've created the token with the following scopes

  • channels:history
  • channels:read
  • chat:write
  • groups:history
  • groups:read
  • users:read

these should suffice as far as I understand the instructions you mentioned.

@sgratzl
Copy link
Owner

sgratzl commented Sep 10, 2020

slack-cleaner --token xoxb-00000000000-0000000000000-EEEEEEEEEEEEEEEEEEEEEEEE --message --channel gen --user "*" --as_user --perform

see instructions:

The token should start with xoxp and not like bot tokens with xoxb.

@leonard84
Copy link
Author

leonard84 commented Sep 10, 2020

That was the problem, I used a Bot Token and not a User Token, maybe update the docs to make it more explicit, or better log an error with a helpful message when an xoxb token is used.

I just checked this hint is missing in the readme for https://github.com/sgratzl/slack-cleaner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants