slack-client-fundamentals
Slack Go SDK Client Fundamentals
Client Initialization
Initialize the Slack API client with your bot token:
import "github.com/slack-go/slack"
api := slack.New("xoxb-your-bot-token")
Enable debug mode for development:
api := slack.New(
"xoxb-your-bot-token",
slack.OptionDebug(true),
)
When to Use Which Approach
Web API (synchronous operations)
Use for direct API calls where you initiate the action:
- Sending messages, creating channels
- Retrieving user information
- Uploading files
- Any request-response operation
Socket Mode (WebSocket - behind firewall)
Use when your app runs behind a firewall and can't receive HTTP requests:
- Real-time event handling without public URL
- Apps running on local machines or private networks
- Development and testing environments
Events API (HTTP webhooks - public URL)
Use when you have a publicly accessible endpoint:
- Production apps with HTTPS endpoints
- Event-driven architectures with webhooks
- Apps hosted on cloud platforms
Error Handling Patterns
Always handle errors from API calls:
_, _, err := api.PostMessage(channelID, slack.MsgOptionText(text, false))
if err != nil {
// Handle specific error types
if rateLimitedError, ok := err.(*slack.RateLimitedError); ok {
// Wait and retry
time.Sleep(rateLimitedError.RetryAfter)
}
return fmt.Errorf("failed to post message: %w", err)
}
Use context for cancellation and timeouts:
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Pass context to API methods that support it
Project Structure Recommendation
slack-bot/
├── cmd/
│ └── bot/
│ └── main.go # Entry point
├── internal/
│ ├── handlers/
│ │ ├── messages.go # Message handlers
│ │ ├── events.go # Event handlers
│ │ └── commands.go # Slash command handlers
│ ├── slack/
│ │ ├── client.go # Slack client wrapper
│ │ └── middleware.go # Authentication, rate limiting
│ └── config/
│ └── config.go # Configuration management
├── pkg/
│ └── models/ # Shared data models
├── go.mod
└── go.sum
Testing Strategies
See testing-patterns.md for comprehensive testing guidance including:
- Mocking the Slack API client
- Integration testing patterns
- Test fixtures for events and messages
- CI/CD testing recommendations
Configuration Best Practices
For advanced configuration including custom HTTP clients, retry strategies, and rate limiting:
Next Steps
Based on your use case, explore these skills:
- Web API operations → Use the
slack-web-apiskill for messaging, channels, users, files - Real-time events → Use the
slack-realtime-eventsskill for Socket Mode or Events API - OAuth setup → Use the
slack-auth-securityskill for multi-workspace authentication
Common Pitfalls
- Hardcoding tokens in code (use environment variables)
- Not handling rate limits (implement exponential backoff)
- Forgetting to validate incoming webhook signatures
- Using blocking operations in event handlers (use goroutines)
- Not implementing proper context cancellation
More from linehaul-ai/linehaulai-claude-marketplace
geospatial-postgis-patterns
Implement geofences, spatial queries, real-time tracking, and mapping features in laneweaverTMS using PostGIS and PGRouting. Use when building location-based features, distance calculations, ETA predictions, or fleet visualization.
83quickbooks-online-api
Expert guide for QuickBooks Online API integration covering authentication, CRUD operations, batch processing, and best practices for invoicing, payments, and customer management.
61rbac-authorization-patterns
Provide patterns for implementing Role-Based Access Control and multi-tenant authorization in laneweaverTMS. Use when implementing user roles, permissions, tenant isolation, Echo authorization middleware, RLS policies for multi-tenant access, or JWT claims structure for freight brokerage applications.
61slack-block-kit
Build Slack Block Kit UIs for messages, modals, and Home tabs. Use when creating Slack notifications, interactive forms, bot responses, app dashboards, or any Slack UI. Covers blocks (Section, Actions, Input, Header), elements (Buttons, Selects, Date pickers), composition objects, and the slack-block-builder library.
44testcontainers-go
Use this skill when writing Go integration tests with Docker containers, using testcontainers-go modules (postgres, redis, kafka, etc.), setting up container-based test infrastructure, or configuring container networking and wait strategies. Covers 62+ pre-configured modules, cleanup patterns, and multi-container setups.
34svelte-flow
Build node-based editors, interactive diagrams, and flow visualizations using Svelte Flow. Use when creating workflow editors, data flow diagrams, organizational charts, mindmaps, process visualizations, DAG editors, or any interactive node-graph UI. Supports custom nodes/edges, layouts (dagre, hierarchical), animations, and advanced features like proximity connect, floating edges, and contextual zoom.
33