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

Support socket mode #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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=<BOT_TOKEN> SLACK_SIGNING_SECRET=<SIGNING_SECRET> python archivebot.py
Expand Down Expand Up @@ -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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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 under the name `SLACK_APP_TOKEN`.


Finally, run the bot with "-s" or "--socket" option.

## Contributing

Contributions are more than welcome. From bugs to new features. I threw this
Expand Down
14 changes: 12 additions & 2 deletions archivebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -352,9 +359,12 @@ 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:
app.start(port=port)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
six>=1.10.0
slack-bolt==1.2.1
slack-bolt==1.14.3