Skip to content

Support socket mode slack bot#117

Merged
ranlu merged 4 commits intomainfrom
slack-socket-mode
Apr 18, 2026
Merged

Support socket mode slack bot#117
ranlu merged 4 commits intomainfrom
slack-socket-mode

Conversation

@ranlu
Copy link
Copy Markdown

@ranlu ranlu commented Apr 17, 2026

Add support of socket mode slack bot, slack no longer allow user to create new RTM bots.

@ranlu
Copy link
Copy Markdown
Author

ranlu commented Apr 17, 2026

@gemini-cli /review

@github-actions
Copy link
Copy Markdown

🤖 Hi @ranlu, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

## 📋 Review Summary

The pull request introduces support for Slack Socket Mode, which is a modern and recommended way to connect Slack bots without requiring public endpoints. The implementation correctly adds SocketModeClient support while maintaining backward compatibility with the legacy RTM mode.

🔍 General Feedback

  • Great Documentation: The updates to the README.md and the inclusion of slack_manifest.json make it very easy for users to set up the new Socket Mode bot.
  • Clean Integration: The use of a shared WebClient and routing Socket Mode events to existing handlers minimizes code duplication.
  • Reliability: The addition of logging and proper exception handling in the bot's main loop improves maintainability and debuggability.

Comment thread slackbot/seuronbot.py
logger.info("Socket Mode client connected")
self.process_hello(self.socket_client, {})
Event().wait()
else:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 The manual call to `self.process_hello` here is likely redundant because `_handle_socket_mode_request` already handles the `hello` event type sent by Slack upon connection. This could lead to the hello listeners being executed twice.
Suggested change
else:
self.socket_client.connect()
logger.info("Socket Mode client connected")
Event().wait()

Comment thread slackbot/seuronbot.py
logger.info("Initializing bot in Socket Mode")
self.socket_client = SocketModeClient(
app_token=self.app_token,
web_client=self.web_client,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 You can simplify the attachment of the listener by using the bound method directly instead of `functools.partial`.
Suggested change
web_client=self.web_client,
self.socket_client.socket_mode_request_listeners.append(self._handle_socket_mode_request)

Comment thread slackbot/bot_info.py Outdated
botid = get_botid()
workerid = "seuron-worker-"+environ["DEPLOYMENT"]
broker_url = environ['AIRFLOW__CELERY__BROKER_URL']
use_socket_mode = slack_app_token is not None
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 The variable `use_socket_mode` appears to be unused in the current PR. Also, if intended for checking if Socket Mode is active, `bool(slack_app_token)` would be more robust as it handles empty strings correctly.

@ranlu ranlu force-pushed the slack-socket-mode branch from 44f0583 to 060f3e3 Compare April 18, 2026 01:38
@ranlu
Copy link
Copy Markdown
Author

ranlu commented Apr 18, 2026

@gemini-cli /review

@github-actions
Copy link
Copy Markdown

🤖 Hi @ranlu, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

## 📋 Review Summary

This Pull Request introduces support for Slack's Socket Mode, which is the recommended connection method for modern Slack apps. It maintains backward compatibility with the legacy RTM Mode, allowing existing deployments to continue functioning.

🔍 General Feedback

  • Well-structured integration: The implementation correctly refactors the SeuronBot class to handle both SocketModeClient and RTMClient based on the presence of an app-level token.
  • Improved Observability: The addition of logging and proper exception handling in the bot's main loop is a positive improvement over the previous pass.
  • Comprehensive Documentation: The updates to README.md and the inclusion of a Slack app manifest make it easy for users to migrate to the new connection mode.
  • Robust Configuration: The setup script and cloud deployment configurations have been correctly updated to support the new token.

Comment thread slackbot/seuronbot.py
Comment on lines 181 to 182
for listener in self.hello_listeners:
listener()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 It's better to use the logger for debugging information instead of print statements, as it allows for better control over log levels and formatting.

Suggested change
for listener in self.hello_listeners:
listener()
def process_reaction(self, client, event: dict):
logger.debug("reaction added")
logger.debug(json.dumps(event, indent=4))

Comment thread slackbot/seuronbot.py
self.socket_client.connect()
logger.info("Socket Mode client connected")
self.process_hello(self.socket_client, {})
Event().wait()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Consider adding a brief comment here to clarify that this blocks the main thread to keep the Socket Mode connection alive while background tasks continue in their threads.

Suggested change
Event().wait()
# Block the main thread to keep the process alive
Event().wait()

@ranlu ranlu merged commit e92f8bd into main Apr 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant