11# Slack OAuth App
22
3- A Deco app for integrating with Slack using OAuth 2.0 authentication. This app allows you to send messages, interact with channels, and manage Slack workspaces through a secure OAuth flow.
3+ A Deco app for integrating with Slack using OAuth 2.0 authentication. This app allows you to send messages, interact with channels, and manage Slack workspaces through a secure OAuth flow with flexible bot configuration options .
44
55## Features
66
77- 🔐 ** OAuth 2.0 Authentication** - Secure token-based authentication
8- - 🤖 ** Custom Bot Support ** - Support for private/custom Slack apps instead of just deco.chat
8+ - 🤖 ** Flexible Bot Configuration ** - Choose between deco.chat bot or custom Slack apps
99- 💬 ** Message Management** - Send messages and replies to channels
1010- 📋 ** Channel Operations** - List and interact with workspace channels
1111- 👥 ** User Management** - Get user information and profiles
1212- 🎯 ** Reactions** - Add emoji reactions to messages
1313- 📁 ** File Upload V2** - Upload files using the new Slack API (files.upload sunset Nov 12, 2025)
1414- 🔄 ** Automatic Token Refresh** - Handles token expiration automatically
15+ - 🎨 ** Custom Bot Selection UI** - Interactive interface for choosing integration type
16+
17+ ## Integration Options
18+
19+ ### 1. deco.chat Bot (Recommended)
20+
21+ Use the official deco.chat bot for seamless integration:
22+
23+ - ✅ ** Pre-configured** - All necessary permissions included
24+ - ✅ ** Zero setup** - No Slack app creation required
25+ - ✅ ** Maintained by Deco** - Automatic updates and security patches
26+ - ✅ ** Best for most users** - Quick setup and reliable operation
27+
28+ ### 2. Custom Bot
29+
30+ Configure your own Slack app for advanced use cases:
31+
32+ - 🎯 ** Full control** - Use your own Slack app credentials
33+ - 🎨 ** Custom branding** - Customize bot name and appearance
34+ - 🔒 ** Enterprise ready** - Full control over permissions and scopes
35+ - 🏢 ** Private deployments** - Use your own Slack app infrastructure
1536
1637## ⚠️ IMPORTANT: File Upload API Migration
1738
@@ -25,14 +46,23 @@ A Deco app for integrating with Slack using OAuth 2.0 authentication. This app a
2546
2647## Setup Instructions
2748
28- ### 1. Create a Slack App
49+ ### Option 1: Using deco.chat Bot (Recommended)
50+
51+ 1 . ** Start OAuth Flow** - No preliminary setup needed
52+ 2 . ** Select Integration Type** - Choose "deco.chat Bot" in the selection interface
53+ 3 . ** Authorize** - Complete OAuth authorization in your Slack workspace
54+ 4 . ** Ready to use** - Integration is immediately available
55+
56+ ### Option 2: Setting Up Custom Bot
57+
58+ #### Step 1: Create a Slack App
2959
30601 . Go to [ api.slack.com/apps] ( https://api.slack.com/apps )
31612 . Click "Create New App" → "From scratch"
32623 . Enter your app name and select a workspace
33634 . Navigate to "OAuth & Permissions" in the sidebar
3464
35- ### 2. Configure OAuth Settings
65+ #### Step 2: Configure OAuth Settings
3666
37671 . Add your redirect URL under "Redirect URLs":
3868 - Development: ` https://your-dev-domain.com/oauth/callback `
@@ -46,50 +76,185 @@ A Deco app for integrating with Slack using OAuth 2.0 authentication. This app a
4676 - ` users:read ` - View people in the workspace
4777 - ` users:read.email ` - View email addresses of people in the workspace
4878
49- ### 3. Environment Variables
79+ #### Step 3: Use Custom Bot in OAuth Flow
5080
51- Set the following environment variables:
81+ 1 . ** Start OAuth Flow** - Begin the standard OAuth process
82+ 2 . ** Select Integration Type** - Choose "Custom Bot" in the selection interface
83+ 3 . ** Enter Credentials** :
84+ - ** Client ID** : Your Slack app's Client ID
85+ - ** Client Secret** : Your Slack app's Client Secret
86+ - ** Bot Name** (optional): Custom identifier for your bot
87+ 4 . ** Complete Authorization** - Finish OAuth flow with your custom app
5288
53- ``` bash
54- SLACK_CLIENT_ID=your_slack_client_id
55- SLACK_CLIENT_SECRET=your_slack_client_secret
89+ ## Bot Selection Interface
90+
91+ The app now features an interactive selection interface that appears during OAuth flow:
92+
93+ ### Selection Options
94+
95+ - ** deco.chat Bot** : Official bot with pre-configured settings
96+ - ** Custom Bot** : Your own Slack app with custom configuration
97+
98+ ### Custom Bot Configuration
99+
100+ When selecting "Custom Bot", you'll need to provide:
101+
102+ - ** Client ID** (required): From your Slack app's "Basic Information" page
103+ - ** Client Secret** (required): From your Slack app's "Basic Information" page
104+ - ** Bot Name** (optional): Custom identifier for branding purposes
105+
106+ ### Interface Features
107+
108+ - 🎨 ** Dark/Light theme** toggle
109+ - 📱 ** Responsive design** for mobile and desktop
110+ - ✨ ** Interactive selection** with visual feedback
111+ - 🔒 ** Secure credential handling** with masked secrets
112+
113+ ## OAuth Flow
114+
115+ The app provides these endpoints for OAuth:
116+
117+ - ** Start OAuth** : ` /loaders/oauth/start ` - Shows selection interface or redirects to Slack
118+ - ** OAuth Callback** : ` /actions/oauth/callback ` - Handles authorization response and token exchange
119+
120+ ### Flow Diagram
121+
122+ ```
123+ User → Start OAuth → Selection UI → [Choose Option] → Slack Authorization → Callback → Complete
124+ ↓ ↓
125+ [deco.chat bot] [Custom bot + credentials]
56126```
57127
58- You can find these values in your Slack app's "Basic Information" page under "App Credentials".
128+ ## Environment Variables
59129
60- ### 4. OAuth Flow
130+ For custom bot configurations, you may optionally set:
61131
62- The app provides two endpoints for OAuth:
132+ ``` bash
133+ SLACK_CLIENT_ID=your_slack_client_id # Optional: Default custom bot
134+ SLACK_CLIENT_SECRET=your_slack_client_secret # Optional: Default custom bot
135+ ```
63136
64- - ** Start OAuth** : ` /loaders/oauth/start ` - Redirects users to Slack for authorization
65- - ** OAuth Callback** : ` /actions/oauth/callback ` - Handles the authorization response
137+ ## API Methods
66138
67- #### Custom Bot Configuration
139+ ### Channels
140+ - ` getChannels(teamId, limit?, cursor?) ` - List workspace channels
141+ - ` getChannelHistory(channelId, limit?) ` - Get channel message history
142+
143+ ### Messages
144+ - ` postMessage(channelId, text) ` - Send a message to a channel
145+ - ` postReply(channelId, threadTs, text) ` - Reply to a thread
146+ - ` getThreadReplies(channelId, threadTs) ` - Get thread replies
68147
69- The app supports custom/private Slack bots. You can configure:
148+ ### Users
149+ - ` getUsers(teamId, limit?, cursor?) ` - List workspace users
150+ - ` getUserProfile(userId) ` - Get user profile information
70151
71- - ** Bot Name** : Set a custom identifier for your bot (used in channel messages)
152+ ### Reactions
153+ - ` addReaction(channelId, timestamp, reaction) ` - Add emoji reaction
72154
73- ** Example OAuth Start with Custom Bot:**
155+ ### File Upload
156+ - ` uploadFileV2(options) ` - Upload files using new V2 API (recommended)
157+ - ` uploadFile(options) ` - Upload files using legacy API (deprecated, shows warning)
158+
159+ ** New V2 Upload Example:**
74160``` typescript
75- // Start OAuth with custom bot configuration
76- const startProps = {
77- clientId: " your_custom_bot_client_id" ,
78- redirectUri: " https://your-domain.com/oauth/callback" ,
79- state: " your_state_parameter" ,
80- botName: " my-custom-bot" // Custom bot name
81- };
161+ const response = await slack .uploadFileV2 ({
162+ channels: " C1234567890" , // Optional
163+ file: fileBlob , // Supports Uint8Array, Blob, File, base64, data URL
164+ filename: " document.pdf" ,
165+ title: " Important Document" ,
166+ thread_ts: " 1234567890.123456" , // Optional - upload to thread
167+ initial_comment: " Here's the document"
168+ });
82169```
83170
84- The app uses the standard set of scopes defined in ` SCOPES ` for all bots, ensuring consistent functionality across different bot configurations.
171+ ## Custom Bot Configuration Details
172+
173+ ### Bot Name Usage
174+
175+ The bot name is used in:
176+ - Channel welcome messages: ` "To interact with me, just mention @your-bot-name in your messages!" `
177+ - Channel listings: Shows ` @your-bot-name ` instead of ` @deco.chat `
178+ - App configuration: Stored as ` customBotName ` for future reference
179+
180+ ### Bot Name Preservation
181+
182+ During re-authentication or token refresh:
183+ - ** With botName parameter** : Updates to the new custom name
184+ - ** Without botName parameter** : Preserves the existing custom bot name
185+ - ** First install** : Uses "deco.chat" as default if no botName provided
186+
187+ ### Multiple Bot Support
188+
189+ The system supports multiple custom bots by:
190+ - Storing bot-specific information in app configuration
191+ - Dynamic bot name resolution in channel operations
192+ - Preserving custom bot names across re-authentications
193+
194+ ## Migration from Bot Token
195+
196+ If you're migrating from the previous bot token approach:
197+
198+ 1 . The app maintains backward compatibility with ` botToken ` prop
199+ 2 . OAuth tokens take precedence over bot tokens when both are present
200+ 3 . Update your app configuration to use OAuth instead of direct bot tokens
201+ 4 . The ` teamId ` is now automatically obtained during OAuth flow
202+ 5 . Custom bot information is preserved across OAuth flows
203+
204+ ## Security
205+
206+ - 🔒 Tokens are stored securely in the app configuration
207+ - 🔄 Automatic token refresh prevents expired token issues
208+ - 🛡️ OAuth scopes limit app permissions to only what's needed
209+ - 🌐 HTTPS is required for redirect URLs in production
210+ - 🔐 Client secrets are handled securely and never exposed in frontend
211+
212+ ## Troubleshooting
213+
214+ ### Selection Interface Issues
215+
216+ 1 . ** Selection page not showing** : Ensure OAuth start URL doesn't include bot type parameters
217+ 2 . ** Custom credentials not working** : Verify Client ID and Secret are correct
218+ 3 . ** Theme not persisting** : Check browser localStorage support
219+
220+ ### Common OAuth Issues
221+
222+ 1 . ** "Team ID is required" error** : Ensure OAuth flow completed successfully and ` teamId ` is set
223+ 2 . ** "Invalid redirect URI" error** : Check that redirect URL matches exactly in Slack app settings
224+ 3 . ** "Invalid scope" error** : Verify all required scopes are added to your Slack app
225+ 4 . ** Token refresh failures** : Check that ` client_secret ` is correctly configured
226+
227+ ### Custom Bot Issues
228+
229+ 1 . ** Invalid Client Credentials** : Ensure your Client ID and Client Secret are correct
230+ 2 . ** Insufficient Permissions** : Make sure your Slack app has all required OAuth scopes
231+ 3 . ** Redirect URI Mismatch** : Verify the redirect URI in your Slack app settings matches
232+
233+ ### Debug Mode
234+
235+ Enable debug logging by checking the browser developer tools or server logs for OAuth-related errors.
236+
237+ ## Development
238+
239+ The app uses the MCP (Multi-Channel Platform) OAuth utilities for token management and HTTP client creation. The main components are:
240+
241+ - ` mod.ts ` - Main app configuration with OAuth setup
242+ - ` client.ts ` - Slack API client with OAuth support
243+ - ` utils/constants.ts ` - OAuth URLs and scopes
244+ - ` utils/client.ts ` - TypeScript interfaces for API endpoints
245+ - ` utils/ui-templates/page-generator.ts ` - Bot selection interface HTML generation
246+ - ` loaders/oauth/start.ts ` - OAuth initiation with selection interface
247+ - ` actions/oauth/callback.ts ` - OAuth completion with custom bot support
248+
249+ ## Contributing
85250
86- ### 5. Usage
251+ When contributing to this app:
87252
88- After OAuth setup, the app will automatically:
89- - Exchange authorization codes for access tokens
90- - Store tokens securely in the app configuration
91- - Refresh tokens automatically when they expire
92- - Provide a ` SlackClient ` instance for API operations
253+ 1 . Test both deco.chat bot and custom bot flows
254+ 2 . Ensure the selection interface works on both light and dark themes
255+ 3 . Verify mobile responsiveness of the selection page
256+ 4 . Test credential validation and error handling
257+ 5 . Maintain backward compatibility with existing bot token approach
93258
94259## API Methods
95260
0 commit comments