Social Media Integration
This document describes the comprehensive social media integration system that automatically distributes updates across multiple platforms when new data is processed or blog posts are published.Social Media Integration Sequence Diagram
Architecture Overview
Social Media Manager
TheSocialMediaManager
class serves as the central orchestrator for all social media integrations, providing:
Unified Interface: Single point of entry for publishing across all platforms
Parallel Execution: Simultaneous posting to all configured platforms
Error Handling: Graceful degradation when individual platforms fail
Result Aggregation: Comprehensive reporting of success/failure statistics
Platform Handler Interface
Each social media platform implements thePlatformHandler
interface, ensuring consistency and interoperability:
Platform Integrations
Discord Integration
Purpose: Community notifications and error reporting Integration Type: Webhook-based messaging Configuration:DISCORD_WEBHOOK_URL
: Primary webhook for community updatesDISCORD_WORKFLOW_WEBHOOK_URL
: Dedicated webhook for error notifications
- Instant Notifications: Real-time updates to Discord servers
- Rich Formatting: Markdown support for formatted messages
- Error Reporting: Dedicated channel for system errors and alerts
- Community Engagement: Direct interaction with user community
LinkedIn Integration
Purpose: Professional business updates and market insights Integration Type: LinkedIn API with OAuth 2.0 Configuration:LINKEDIN_CLIENT_ID
: Application client identifierLINKEDIN_CLIENT_SECRET
: Application secretLINKEDIN_ACCESS_TOKEN
: User access tokenLINKEDIN_REFRESH_TOKEN
: Token refresh capabilityLINKEDIN_ORGANISATION_ID
: Target organisation pageLINKEDIN_USER_ID
: Authenticated user identifier
- Professional Content: Business-focused content formatting
- Token Management: Automatic access token refresh
- Organisation Posting: Post to company pages
- Rich Media: Support for links and formatted text
- Initial Authentication: Manual OAuth flow to obtain tokens
- Token Storage: Secure storage of access and refresh tokens
- Automatic Refresh: Token refresh before expiration
- Error Recovery: Re-authentication flow for invalid tokens
Telegram Integration
Purpose: Channel-based broadcasting to subscribers Integration Type: Telegram Bot API Configuration:TELEGRAM_BOT_TOKEN
: Bot authentication tokenTELEGRAM_CHANNEL_ID
: Target channel identifier
- Channel Broadcasting: Direct posting to Telegram channels
- Markdown Support: Rich text formatting with Telegram markdown
- Instant Delivery: Real-time message delivery to subscribers
- Bot Management: Administrative capabilities through bot interface
- Create Bot: Use @BotFather to create new bot
- Obtain Token: Receive bot token from BotFather
- Channel Setup: Add bot as administrator to target channel
- Get Channel ID: Use bot API to identify channel ID
Twitter Integration
Purpose: Social media engagement and public updates Integration Type: Twitter API v2 with OAuth 1.0a Configuration:TWITTER_APP_KEY
: Application API keyTWITTER_APP_SECRET
: Application secretTWITTER_ACCESS_TOKEN
: User access tokenTWITTER_ACCESS_SECRET
: User access token secret
- Tweet Publishing: Direct posting to Twitter timeline
- Character Optimization: Automatic message truncation for 280-character limit
- Link Handling: Automatic URL shortening with t.co
- Engagement Tracking: Tweet performance metrics
- OAuth 1.0a: Twitter’s authentication protocol
- Application Credentials: API key and secret for app identification
- User Tokens: Access token and secret for user authorization
- Signature Generation: Automatic request signing
Publishing Workflow
Message Structure
All social media messages follow a consistent structure:Publishing Process
- Trigger: Data processing workflow completes successfully
- Message Creation: Generate platform-agnostic message and link
- Manager Invocation: Call
SocialMediaManager.publishToAll()
- Platform Detection: Identify enabled platforms with valid configuration
- Parallel Execution: Simultaneously post to all valid platforms
- Result Aggregation: Collect success/failure results from all platforms
- Error Handling: Report failures to Discord error channel
- Response: Return comprehensive results to calling workflow
Content Formatting
Each platform handler applies platform-specific formatting: Discord: Emoji-rich formatting with Discord markdown LinkedIn: Professional tone with structured content Telegram: Telegram markdown with clickable links Twitter: Hashtag optimization and character limit complianceError Handling
Graceful Degradation: Failed platforms don’t prevent successful publishing to others Error Notification: Discord receives notifications about failed platforms Retry Logic: Configurable retry mechanisms for transient failures Health Monitoring: Regular platform connectivity checksConfiguration Management
Environment-Based Configuration
Development: Disabled or test webhooks Staging: Test channels/accounts for validation Production: Live channels and official accountsPlatform Enablement
Platforms are enabled based on configuration availability:- Check for required environment variables
- Validate token/credential format
- Test connectivity during startup
- Graceful handling of missing configuration