简体   繁体   中英

Find out time stamp of Slack message from Python API

I created Slack app, added Bot and Incoming Webhook to it and posted some messages with Bot. Now I would like to find out time stamp of Slack message in order to delete it later with chat.delete method.

I found it that I can use channels.history method.

Here is how I tried to use it. I used it with token found under OAuth Access Token, since per docs I cannot use Bot token with channels.history method.

from slackclient import SlackClient
slack_token_user_token = 'xoxp-long_string_of_integers'
sc_user_token = SlackClient(slack_token_user_token)

sc_user_token.api_call(
    "channels.history",
  channel="CHXXXXXXX")

I got back the following error:

{'error': 'missing_scope',
 'headers': {'Access-Control-Allow-Headers': 'slack-route, x-slack-version-ts',
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Expose-Headers': 'x-slack-req-id',
  'Cache-Control': 'private, no-cache, no-store, must-revalidate',
  'Connection': 'keep-alive',
  'Content-Encoding': 'gzip',
  'Content-Length': '108',
  'Content-Type': 'application/json; charset=utf-8',
  'Date': 'Fri, 05 Apr 2019 18:18:11 GMT',
  'Expires': 'Mon, 26 Jul 1997 05:00:00 GMT',
  'Pragma': 'no-cache',
  'Referrer-Policy': 'no-referrer',
  'Server': 'Apache',
  'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload',
  'Vary': 'Accept-Encoding',
  'Via': '1.1 f0f1092b2ad1f0e573a4fcbefe4fb621.cloudfront.net (CloudFront)',
  'X-Accepted-OAuth-Scopes': 'channels:history',
  'X-Amz-Cf-Id': 'fSm6uo2H88E43JCvqd2h5mohnzA6z0B3kmdsG3u9nW0PJNrsrpK7mg==',
  'X-Cache': 'Miss from cloudfront',
  'X-Content-Type-Options': 'nosniff',
  'X-OAuth-Scopes': 'identify,bot,incoming-webhook',
  'X-Slack-Req-Id': 'c158668d-ddc9-4bbc-9a7d-6b9a9011d2dc',
  'X-Via': 'haproxy-www-yfr6',
  'X-XSS-Protection': '0'},
 'needed': 'channels:history',
 'ok': False,
 'provided': 'identify,bot,incoming-webhook'}

If this is permission issue, how do I find out proper token to use?

According to the error message you posted the token used is lacking the required scope.

'needed': 'channels:history'

It looks like you provided the bot token, which can not work.

'provided': 'identify,bot,incoming-webhook'

Provide the access token and make sure you first add the channel.history scope and reinstall the app to activate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM