Giter Club home page Giter Club logo

slack-exporter's Introduction

slack-exporter

A Slack bot and standalone script for exporting messages and file attachments from public and private channels, using Slack's new Conversations API.

A similar service is provided by Slack for workspace admins at https://my.slack.com/services/export (where my can be replaced with your full workspace name to refer to a workspace different than your default). However, it can only access public channels, while slack-exporter can retrieve data from any channel accessible to your user account.

Authentication with Slack

There are two ways to use slack-exporter (detailed below). Both require a Slack API token to be able to communicate with your workspace.

  1. Visit https://api.slack.com/apps/ and sign in to your workspace.
  2. Click Create New App. If prompted to select "how you'd like to configure your app's scopes", choose the App Manifest option. You can configure the app manually instead, but you will be prompted to enter an app name and additional steps to set up permissions instead of the single step below. Once creates, select your workspace.
  3. You should then be prompted for an app manifest. Paste the contents of the slack.yaml file (in the root of this repo) into the YAML box.
  4. Select Install to Workspace at the top of that page (or Reinstall to Workspace if you have done this previously) and accept at the prompt.
  5. Copy the OAuth Access Token (which will generally start with xoxp for user-level permissions and may be located in a section like "OAuth & Permissions" in the sidebar).

Usage

As a standalone script

exporter.py can create an archive of all conversation history in your workspace which is accessible to your user account.

  1. Either add

    SLACK_USER_TOKEN = xoxp-xxxxxxxxxxxxx...
    

    to a file named .env in the same directory as exporter.py, or run the following in your shell (replacing the value with the user token you obtained in the Authentication with Slack section above).

    export SLACK_USER_TOKEN=xoxp-xxxxxxxxxxxxx...
  2. If you cloned this repo, make sure that dependencies are installed by running pip install -r requirements.txt in the repo root directory.

  3. Run python exporter.py --help to view the available export options. You can test that access to Slack is working by listing available conversations: python exporter.py --lc.

As a Slack bot

bot.py is a Slack bot that responds to "slash commands" in Slack channels (e.g., /export-channel). To connect the bot to the Slack app generated in Authentication with Slack, create a file named .env in the root directory of this repo, and add the following line:

SLACK_USER_TOKEN = xoxp-xxxxxxxxxxxxx...

Save this file and run the Flask application in bot.py such that the application is exposed to the Internet. This can be done via a web server (e.g., Heroku), as well as via the ngrok service, which assigns your localhost server a public URL.

To use the ngrok method:

  1. Download the appropriate binary.

  2. Run python bot.py

  3. Run the ngrok binary with path/to/ngrok http 5000, where 5000 is the port on which the Flask application (step 2) is running. Copy the forwarding HTTPS address provided.

  4. Create the following slash commands will be created (one for each applicable Flask route in bot.py):

    Command Request URL Arguments Example Usage
    /export-channel https://[host_url]/slack/export-channel json | text /export-channel text
    /export-replies https://[host_url]/slack/export-replies json | text /export-replies json

    To do this, uncomment the slash-commands section in slack.yaml and replace YOUR_HOST_URL_HERE with something like https://xxxxxxxxxxxx.ngrok.io (if using ngrok). Then navigate back to OAuth & Permissions and click (Re)install to Workspace to add these slash commands to the workspace (ensure the OAuth token in your .env file is still correct).

Author

Seb Seager

License

This software is available under the GPL.

slack-exporter's People

Contributors

davidfichtmueller avatar ddabble avatar hnykda avatar iaguis avatar jaygooby avatar mberka avatar mcdamo avatar msaffitz avatar relaxhack avatar sanchosponcho avatar sebseager avatar silviot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

slack-exporter's Issues

Invalid auth

Hi! I'm trying to use this. I've set the token (tried both .env and the env variable directly), but I'm getting the following error:

> python3 exporter.py --lu
I encountered an error: {'ok': False, 'error': 'invalid_auth'}

Save specific channel with replies doesn't work without json

python exporter.py -o dynamic_pricing --ch <channel_id> -r results in:

Traceback (most recent call last):
  File "/<path>/slack-exporter/exporter.py", line 503, in <module>
    save_replies(channel_history(ch_id), ch_id, user_list())
  File "/<path>/slack-exporter/exporter.py", line 454, in save_replies
    ch_name, ch_type = name_from_ch_id(ch_id, ch_list)
NameError: name 'ch_list' is not defined

Adding the --json flag fixes it

I think ch_id should be channel_hist, but I'm not quite sure where ch_list should come from

Load user details for Slack Connect external users

Currently these come through as "null user".

Not sure exactly where the issue is or if this is even possible with the Slack API scopes available, but just documenting this as a limitation or potential improvement.

`--json` option doesn't output valid json

The json objects are single quoted and not double quoted, e.g.

[{'client_msg_id': '055bbe26-aa11-47cc-9ff7-effa09ef808b', 'type': 'message', 'text': 'blah blah', 'user': 'U01111'}]

so you can't then pipe this output to jq or other json parsing tools

The error "not_in_channel" occurs

Hi,

I try to use standalone script, but have an issue:

python3 exporter.py -c    
I encountered an error: {'ok': False, 'error': 'not_in_channel'}

There is only 1 private channel in my test environment and I invited the application to this channel, however an error occurs.

Import Error on MacOS Ventura 13.1

Attempting to run the script on macOS Ventura 13.1 via the command python3 exporter.py --help yields the following error:

ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with LibreSSL 2.8.3. See: https://github.com/urllib3/urllib3/issues/2168

Integration with slack-export-viewer?

Slack-exporter exports channel data without folder structure, while Slack’s native export function retains folders/usernames/etc, that can be natively loaded into helper viewers such as slack-export-viewer and SlackLogViewer. Has anyone sorted out a way to seamlessly put together the files generated by Slack-exporter so that they can accessed with an external viewers? This would greatly increase the accessibility of these exports and their usefulness.

KeyError: 'real_name'

python exporter.py -o out -c -r
Traceback (most recent call last):
File "exporter.py", line 410, in
data_ch = parse_channel_history(ch_hist, users)
File "exporter.py", line 263, in parse_channel_history
"real_name": name_from_uid(msg["user"], users, True),
File "exporter.py", line 204, in name_from_uid
return user["real_name"] if real else user["name"]
KeyError: 'real_name'

KeyError: 'paging' on get_file_list()

D:\slack-exporter> python exporter.py -o ./json --json -c -r --files
...
Writing output to D:\slack-exporter\json\slack_export_10-31-2022_221332\channel_A1B2C3D4E5F.json
Writing output to D:\slack-exporter\json\slack_export_10-31-2022_221332\channel-replies_A1B2C3D4E5F.json
...
Traceback (most recent call last):
  File "D:\slack-exporter\exporter.py", line 547, in <module>
    save_files(out_dir)
  File "D:\slack-exporter\exporter.py", line 404, in save_files
    for file_info in get_file_list():
  File "D:\slack-exporter\exporter.py", line 152, in get_file_list
    total_pages = json_data["paging"]["pages"]
KeyError: 'paging'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.