A robust system that automatically generates and publishes social media content for your blog posts. ✨
This project automates the process of generating and publishing social media content for blog posts. When blog posts are added, edited, or deleted in your repository, the system automatically:
The system operates in a two-step workflow:
Content Generation 📝:
_posts
directory (either from a push to main or a PR)Content Publishing 📢:
You can check the posting results by revisiting the PR after it’s merged - the results will be visible in the comments section.
Create an X Developer Account:
Create a Project and App:
Generate Authentication Tokens 🔑:
Create a .env
file in the root directory with the following variables:
OPENAI_API_KEY=your_openai_api_key
X_API_KEY=your_twitter_api_key
X_API_SECRET=your_twitter_api_secret
X_ACCESS_TOKEN=your_twitter_access_token
X_ACCESS_SECRET=your_twitter_access_secret
Add Environment Variables to GitHub:
OPENAI_API_KEY
TWITTER_API_KEY
TWITTER_API_SECRET
TWITTER_ACCESS_TOKEN
TWITTER_ACCESS_SECRET
GH_PAT
(GitHub Personal Access Token)Creating a GitHub Personal Access Token (GH_PAT):
repo
(Full control of private repositories)workflow
(Update GitHub Action workflows)GH_PAT
secret in your repository settingsConfigure GitHub Actions:
Prompts control how the AI generates content for each platform. They are located in the prompts/
directory.
To adjust a prompt:
prompts/X.txt
for Twitter){content}
as a placeholder for the blog post contentExample prompt structure:
Summarize the following blog post into an engaging X post.
Use a direct, thoughtful style. Include a hook and end with a question.
It SHOULD NOT be more than 200 chars.
Blog Post:
{content}
X post:
The system now supports versioning for social media content:
Content is stored in a versioned structure:
social_media/your-page-name/X/v1/content.txt
social_media/your-page-name/X/v2/content.txt
To include media with your social media posts:
Add image or video files to the platform directory:
social_media/your-page-name/X/image.jpg
Or in the version-specific directory:
social_media/your-page-name/X/v1/image.jpg
Supported formats:
The system will automatically detect and attach these media files when posting.
Note about media files 📌: When adding media files for posts, ensure they are in the same branch as the content for the publish workflow to detect them properly.
After a PR with social media content is merged:
The system includes an email newsletter integration that sends blog posts to subscribers using Resend for email delivery and Supabase for subscriber management. For detailed setup and usage instructions, see Email Subscription System.
Key features:
To add support for a new social media platform:
Create a Platform Class:
scripts/posting/platforms/
(e.g., linkedin.py
)SocialMediaPlatform
post_content()
Example:
from ..platforms import SocialMediaPlatform
class LinkedInPlatform(SocialMediaPlatform):
def __init__(self):
super().__init__("LinkedIn")
self._verify_credentials()
def _verify_credentials(self):
# Check for required environment variables
pass
def post_content(self, content, page_name, platform_folder=None):
# Implement posting logic
pass
Register the Platform:
scripts/posting/poster.py
to include the new platform:supported_platforms = {
"X": TwitterPlatform,
"LinkedIn": LinkedInPlatform,
"Resend": ResendPlatform,
}
Create a Prompt:
prompts/
directory (e.g., LinkedIn.txt
)Update Environment Variables:
.env
fileCurrent limitations of the system:
detect_new_pages.py
: Detects new, edited, and deleted posts in the repositoryextract_social_media_content.py
: Generates versioned social media content using OpenAIpost_social_media.py
: Posts content to social media platformsposting/
: Module containing platform implementations
poster.py
: Main class for posting content with versioning supportplatforms/
: Directory containing platform-specific implementations
twitter.py
: X platform implementation with support for versioned contentTo set up the project for development:
Clone the repository:
git clone <repository-url>
cd <repository-name>
Add environment variables:
.env
file based on the variables listed aboveAdd environment variables to GitHub:
Working with posts:
_posts
directoryThe system handles different types of file changes:
The system includes several features for handling branch names:
{page_name}_{version}_{date}_social_media
)_social_media
suffix for compatibility with other workflows