|
|
3 年 前 | |
|---|---|---|
| .. | ||
| .gitignore | 3 年 前 | |
| LICENSE | 3 年 前 | |
| README.md | 3 年 前 | |
| archivebot.py | 3 年 前 | |
| export.py | 3 年 前 | |
| flask_app.py | 3 年 前 | |
| gunicorn_conf.py | 3 年 前 | |
| import.py | 3 年 前 | |
| requirements.txt | 3 年 前 | |
| utils.py | 3 年 前 | |
A bot that can search your slack message history. Makes it possible to search further back than 10,000 messages.
Install the requirements:
pip install -r requirements.txt
If you want to include your existing slack messages, export your team's slack history.
Download the archive and export it to a directory. Then run import.py
on the directory. For example:
python import.py export
This will create a file slack.sqlite.
Create a new Slack app.
Add the following bot token oauth scopes and install it to your workspace:
channels:historychannels:readchat:writegroups:history (if you want to archive/search private channels)groups:read (if you want to archive/search private channels)im:historyusers:readStart slack-archive-bot with:
SLACK_BOT_TOKEN=<BOT_TOKEN> SLACK_SIGNING_SECRET=<SIGNING_SECRET> python archivebot.py
Where SIGNING_SECRET is the "Signing Secret" from your app's "Basic Information" page and BOT_TOKEN is the
"Bot User OAuth Access Token" from the app's "OAuth & Permissions" page.
Use python archivebot.py -h for a list of all command line options.
3333. (i.e. http://<ip>:3333/slack/events)Then add the following bot events:
channel_renamegroup_rename (if you want to archive/search private channels)member_joined_channelmember_left_channelmessage.channelsmessage.groups (if you want to archive/search private channels)message.imuser_changeBy default when you run python archivebot.py it will launch a development server. But they don't recommend using it in production. The following is an example of using
Flask and Gunicorn to deploy slack-archive-bot, but it should work equally well with any other WSGI server.
pip install flask gunicornSLACK_BOT_TOKEN=<BOT_TOKEN> SLACK_SIGNING_SECRET=<SIGNING_SECRET> gunicorn flask_app:flask_app -c gunicorn_conf.py <other gunicorn args>flask_app.py provides a thin wrapper around archivebot.app using slack_bolt.adapter.flask.SlackRequestHandler. There are many other adapters provided by bolt. To use them, simply from archivebot import app and wrap app.gunicorn_conf.py ensures that the local database is updated when the server is started, but that it's not run for each worker.ARCHIVE_BOT_LOG_LEVEL and ARCHIVE_BOT_DATABASE_PATH to configure slack-archive-bot while running it via gunicorn.When running, ArchiveBot will continue to archive new messages for any channel it is invited to. To add the bot to your channels:
/invite @ArchiveBot
If @ArchiveBot is the name you gave your bot user.
To search the archive, direct message (DM) @ArchiveBot with the search query. For example, sending the word "pizza" will return the first 10 messages that contain the word "pizza". There are a number of parameters that can be provided to the query. The full usage is:
<query> from:<user> in:<channel> sort:asc|desc limit:<number>
query: The text to search for.
user: If you want to limit the search to one user, the username.
channel: If you want to limit the search to one channel, the channel name.
sort: Either asc if you want to search starting with the oldest messages,
or desc if you want to start from the newest. Default asc.
limit: The number of responses to return. Default 10.
slack-archive-bot v0.1 used the legacy Slack API which Slack ended support for in February 2021. To migrate to the new version:
Contributions are more than welcome. From bugs to new features. I threw this together to meet my team's needs, but there's plenty I've overlooked.
Code released under the MIT license.