Skip to content

Conversation

@smurching
Copy link
Collaborator

@smurching smurching commented Nov 3, 2025

Add Slack Bot with OAuth Authentication

Overview

This PR introduces a Slack bot that provides personalized, authenticated access to Databricks AI agents. The bot implements a UX featuring ephemeral messages, sharing capabilities, and multi-user support.

Key Features

  • Data privacy-respecting UX: Bot responds privately to users via ephemeral messages, with options to share responses publicly or dismiss them
  • OAuth Authentication: Seamless Databricks OAuth flow with automatic response after authentication completes
  • Multi-user Support: Each user authenticates independently and receives personalized responses
  • Thread-based Conversations: All interactions happen in threads for clean channel organization
  • Interactive Buttons:
    • "Post in thread" - Share private response publicly
    • "Dismiss" - Remove ephemeral message
    • "Generate my own answer" - Allow other users to get their own personalized responses
  • Visual Feedback: Eyes emoji reaction on message receipt, white checkmark when shared
  • Auto-respond After Auth: Bot stores pending messages and automatically responds after OAuth completes

Architecture

The bot uses Socket Mode for development and consists of:

  • app_socket.py: Main Slack app with event handlers and button actions
  • oauth_server.py: OAuth callback handler running on port 8000
  • handlers/: Message processing and authentication logic
  • state/: In-memory state management (can be replaced with Redis/DynamoDB for production)
  • client/: Databricks API client for agent calls

User Flow

  1. User mentions bot: @DatabricksBot hello
  2. Bot reacts with 👀 emoji for immediate acknowledgment
  3. First-time users: Bot sends ephemeral OAuth prompt in thread
  4. After OAuth or for returning users: Bot sends "Working on it..." status message
  5. Bot sends ephemeral response with "Post in thread" and "Dismiss" buttons (visible only to requesting user)
  6. Bot posts public message with "Generate my own answer" button for other users
  7. When shared: Ephemeral message disappears, response posted publicly, ✅ reaction added to original message

Technical Highlights

  • Ephemeral Messages: Uses chat_postEphemeral for private responses
  • Response URL Pattern: Uses respond(delete_original=True) for dismissing ephemeral messages
  • Event Deduplication: Properly handles both app_mention and message events without duplication
  • PKCE OAuth Flow: Secure OAuth implementation with proper state management
  • Conversation History: Per-thread history for context-aware responses
  • Regex Action Patterns: Dynamic action_id matching for button interactions

Testing

Run the bot locally:

cd slack-bot
python app_socket.py

The bot will:

  • Connect to Slack via Socket Mode
  • Start OAuth callback server on port 8000
  • Log all events and interactions to console

Future Enhancements

  • Support better parsing and rendering of agent output, especially of tool-calling agents (if a user query triggers an agent tool call e.g "What is the 1000th fibonacci number?", the Slack bot currently fails to parse the agent output)
  • Support deploying as a Databricks app (add app.yaml, make the choice of serving endpoint parametrizable, add deployment instructions, etc)
  • Replace in-memory state storage (of user oauth tokens) with something durable and secure (e.g. lakebase?) for production. Needs some discussion with security

Related Documentation

See slack-bot/README.md for:

  • Complete setup instructions
  • Slack app configuration
  • Environment variables
  • Development guide
  • Troubleshooting tips

manfredcalvo and others added 25 commits September 2, 2025 12:45
…h databricks agent endpoint using authentication on behalf of the user.
Updating appManifest for teams app
Signed-off-by: Sid Murching <[email protected]>
…r OAuth

Major features:
- Ephemeral messages: Bot responses appear privately to user with share button
- Auto-respond after OAuth: Bot stores pending messages and automatically processes them after authentication
- Share to channel: Users can click button to post response publicly in thread
- Socket mode: Refactored to use Socket Mode for local development

Technical changes:
- Added oauth_server.py: Standalone OAuth callback handler with auto-respond logic
- Updated app_socket.py: Socket Mode implementation with share button handler
- Enhanced message_handler.py: Send ephemeral messages, store pending messages before OAuth
- Fixed PKCE issues: Deduplicated event handlers to prevent double processing
- Fixed token exchange: Skip unnecessary exchange for direct Databricks OAuth tokens
- Fixed WorkspaceClient conflicts: Temporarily unset OAuth env vars

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…buttons

Features:
- Eyes emoji reaction on message receipt for instant acknowledgment
- Public "working on it" status message after authentication
- Ephemeral responses with Share to channel button
- Public "Generate my own answer" button for other users
- Auto-hide buttons after use

UX improvements:
- Share posts raw content without user attribution prefix
- Generate button creates personalized answer for each user
- Both buttons hide and show completion status after use

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…utton updates

Improvements:
- Remove duplicate OAuth success message in channel
- Auto-delete "working on it" message after response is sent
- Instant button removal on Share click using response_action="update"
- Cleaner, less cluttered message flow

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Sid Murching <[email protected]>
- Add thread_ts parameter to ephemeral OAuth message
- Ensures login button appears in thread view, not main channel
- Improves UX by keeping authentication flow in context

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Changes:
- Rename "Share to channel" button to "Post in thread" for clarity
- Add "Dismiss" button to allow users to dismiss ephemeral messages
- Add white_check_mark reaction when posting to thread
- Update status message from "Shared to channel" to "Posted in thread"
- Add debug logging for button click handlers

Note: Ephemeral message dismissal needs further investigation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Changes:
- Use respond(delete_original=True) instead of ack(response_action="clear")
- Both "Post in thread" and "Dismiss" buttons now properly delete ephemeral messages
- Add white_check_mark reaction to original user message when posting
- Store message_ts in response_data for reaction targeting
- Add extensive logging for debugging button interactions

Fixes the issue where ephemeral messages weren't being hidden when buttons were clicked.
According to Slack docs, ephemeral messages must be deleted via response_url, not response_action.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Sid Murching <[email protected]>
- Remove app.py and http_mode.py (non-socket mode files)
- Update README to focus on Socket Mode only
- Add PR_DESCRIPTION.md with high-level context
- Update environment variables to include SLACK_APP_TOKEN
- Simplify setup instructions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Merging main branch history to prepare for PR.
- Resolved .gitignore conflict by combining both versions
- Added *conf*.json pattern from main to comprehensive .gitignore

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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.

3 participants