From 83d908962e0da4e696687ebbe7d1535742128973 Mon Sep 17 00:00:00 2001 From: dummyx <40601688+dummyx@users.noreply.github.com> Date: Tue, 16 Aug 2022 18:40:37 +0900 Subject: [PATCH 1/4] Update bolt to latest version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fb68377..22805a0 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ six>=1.10.0 -slack-bolt==1.2.1 +slack-bolt==1.14.3 From 1ea052ddef5c5e3a1a20904b396ab01c1cebc8d1 Mon Sep 17 00:00:00 2001 From: dummyx <40601688+dummyx@users.noreply.github.com> Date: Tue, 16 Aug 2022 18:40:57 +0900 Subject: [PATCH 2/4] Support socket mode --- archivebot.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/archivebot.py b/archivebot.py index 08b2c25..577a7b2 100644 --- a/archivebot.py +++ b/archivebot.py @@ -4,6 +4,7 @@ import traceback from slack_bolt import App +from slack_bolt.adapter.socket_mode import SocketModeHandler from utils import db_connect, migrate_db @@ -23,6 +24,12 @@ parser.add_argument( "-p", "--port", default=3333, help="Port to serve on. (default = 3333)" ) +parser.add_argument( + "-s", + "--socket", + action="store_true", + help=("enable socket mode") +) cmd_args, unknown = parser.parse_known_args() # Check the environment too @@ -351,10 +358,13 @@ def init(): def main(): - init() - # Start the development server - app.start(port=port) + if cmd_args.socket: + handler = SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]) + handler.start() + else: + init() + app.start(port=port) if __name__ == "__main__": From 4c0e31f966ea864050e8b1fd8cb06c60f30efa10 Mon Sep 17 00:00:00 2001 From: dummyx <40601688+dummyx@users.noreply.github.com> Date: Tue, 16 Aug 2022 18:43:04 +0900 Subject: [PATCH 3/4] Call init() properly --- archivebot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archivebot.py b/archivebot.py index 577a7b2..c3fb303 100644 --- a/archivebot.py +++ b/archivebot.py @@ -358,12 +358,12 @@ def init(): def main(): + init() # Start the development server if cmd_args.socket: handler = SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]) handler.start() else: - init() app.start(port=port) From 91cc122fd78da8b7076b73331c426d275b20e4fe Mon Sep 17 00:00:00 2001 From: dummyx <40601688+dummyx@users.noreply.github.com> Date: Mon, 22 Aug 2022 21:05:50 +0900 Subject: [PATCH 4/4] Add description for socket mode --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 42ef839..71fa0eb 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ further back than 10,000 messages. 1. Permission to install new apps to your Slack workspace. 2. python3 -3. A publicly accessible URL to serve the bot from. (Slack recommends using [ngrok](https://ngrok.com/) to get around this.) +3. A publicly accessible URL to serve the bot from. (Slack recommends using [ngrok](https://ngrok.com/) to get around this.) Not needed when using socket mode. ## Installation @@ -36,6 +36,8 @@ on the directory. For example: - `im:history` - `users:read` +- For socket mode, skip to [socket mode](#socket-mode) + 5. Start slack-archive-bot with: SLACK_BOT_TOKEN= SLACK_SIGNING_SECRET= python archivebot.py @@ -102,6 +104,12 @@ to the query. The full usage is: - Follow the installation steps above to create a new slack app with all of the required permissions and event subscriptions. - The biggest change in requirements with the new version is the move from the [Real Time Messaging API](https://api.slack.com/rtm) to the [Events API](https://api.slack.com/apis/connections/events-api) which necessitates having a publicly-accessible url that Slack can send events to. If you are unable to serve a public endpoint, you can use [ngrok](https://ngrok.com/). +## Socket mode + +To run the bot in socket mode, go to the app's "Socket Mode" page and enable it. Then add the app level token you got to environment variables. + +Finally, run the bot with "-s" or "--socket" option. + ## Contributing Contributions are more than welcome. From bugs to new features. I threw this