-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Add] Implement Slack Socket Mode support #1436
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
base: main
Are you sure you want to change the base?
Conversation
- Add Slack Socket Mode handler in server.py - Create start_socket_mode function in slack/app.py - Add example script for testing Slack websocket handler Introduce Slack Socket Mode support alongside existing HTTP handler. This allows for real-time message processing using websockets when SLACK_WEBSOCKET_TOKEN is set. The HTTP handler remains active when only SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET are provided.
- Update comment to mention "SLACK_WEBSOCKET_TOKEN" instead of "SLACK_APP_TOKEN" Fix a typo in the comment describing the environment variable check for the Slack socket handler. This change aligns the comment with the actual code implementation, improving code readability and preventing potential confusion.
- Update docstring to mention "SLACK_WEBSOCKET_TOKEN" instead of "SLACK_APP_TOKEN" Correct the documentation in the `start_socket_mode` function to accurately reflect the environment variable used for Slack authentication. This change aligns the docstring with the actual code implementation, improving clarity and preventing potential confusion for developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JCMarques15 This is a great feature, thanks for the contrib!
I would really like to have at least basic unit test coverage here. That way, we can ensure that Slack integration stays stable going forward. Please let me know whether you're willing to give that a try! I recommend using Claude Sonnet to help along if you get stuck (but I'm happy to offer support as well!).
Hi @dokterbob, sorry for the late reply—it’s been a hectic few weeks! Thanks for the detailed suggestions; they’re super helpful. I’ll give the unit testing a try and work on monkeypatching AsyncSocketModeHandler and AsyncApp to cover both legacy and websocket behavior. I’m still getting familiar with this kind of setup, so it might take me a bit of time, but I’m happy to dive in. If I hit any roadblocks or it ends up taking longer than expected, I’ll focus on submitting a PR for the cookbook and documentation instead. Let me know if there’s anything else I should keep in mind as I get started! |
What is the status on this? |
@JCMarques15 Friendly poke. :) |
My apologies for the delay. The end and beginning of the year have been quite demanding work-wise, and I wasn’t able to find the time to address this earlier. I’ve now picked it up and am actively working on it. You can expect an update by the end of next week. Thank you for your patience! |
- Add `node_modules` to ignored files - Add `.pnpm-store` to ignored files Update .gitignore to exclude node package manager related directories to keep repository clean and prevent committing dependencies.
- Remove `slack_websocket_test.py` from backend/chainlit directory - Relocate example to Cookbook repository with other test examples Consolidated example files by moving Slack websocket test to the Cookbook repository where other test examples are located for better organization and discoverability.
- Create test file `test_slack_socket_mode.py` with integration tests - Add test for socket mode handler initialization and startup - Add test for HTTP route registration with classic tokens Adds comprehensive tests for Slack integration modes, covering both WebSocket and HTTP endpoints. Tests verify proper handler initialization, token usage, and route registration.
Hi @dokterbob I have made the changes you had requested. I’ve moved the testing script to the cookbook as a minimal Slack bot integration example and added documentation for the new behaviour in the docs repo. Additionally, I’ve added unit tests for both the legacy and websocket Slack behaviours using I believe I’ve covered everything you outlined, but I’d really appreciate it if you could take a quick look to confirm whether this aligns with your expectations or if anything still needs to be adjusted. The relevant PRs are: |
Description
This PR introduces support for Slack Socket Mode, enabling real-time message processing using websockets. This feature enhances the Slack integration by allowing for more efficient and responsive communication, and a way to bypass ingress restrictive networks.
Changes
server.py
start_socket_mode
function inslack/app.py
SLACK_WEBSOCKET_TOKEN
is setslack_websocket_test.py
for testing the Slack websocket handlerHow to Test
SLACK_BOT_TOKEN
SLACK_SIGNING_SECRET
SLACK_WEBSOCKET_TOKEN
Additional Notes
SLACK_BOT_TOKEN
andSLACK_SIGNING_SECRET
are providedSLACK_WEBSOCKET_TOKEN
is set, the application will prioritize Socket Mode over the HTTP handler