Social Media Automation
Build a social media management system with content calendars, scheduled posting, cross-platform publishing, and engagement analytics — automate your social presence.
Social media management architecture
Managing social media across multiple platforms without a system leads to inconsistency, missed posting days, and wasted time context-switching between apps. A social media management system centralises content creation, scheduling, and analytics in one place. The core objects are: posts (content to be published), schedules (when and where to publish), accounts (connected social media profiles), and metrics (engagement data after publishing). Ask Claude Code: Create a new Node.js project with TypeScript for a social media management tool. Define types at src/types.ts for SocialAccount (id, platform as twitter or linkedin or instagram or threads, username, display_name, connected_at), Post (id, content with text, images array, link optional, hashtags array, platform_specific as a map of platform to platform-specific content, schedule with date, time, timezone, status as draft or scheduled or published or failed, platforms as array of target platforms, performance with impressions, engagements, clicks, shares optional), ContentCalendar (month, year, posts grouped by week), and ContentTheme (id, name, description, colour, posting_frequency like twice per week). Create a configuration file with your content themes: Educational (share knowledge and tips), Behind the Scenes (show the process), Customer Stories (social proof), Industry News (commentary on trends), and Promotional (product features and offers). Define a weekly content mix: 40 percent educational, 20 percent behind the scenes, 15 percent customer stories, 15 percent industry news, 10 percent promotional.
Content calendar and batch creation
The most efficient social media strategy creates content in batches, not one post at a time. Ask Claude Code: Create a content calendar generator at src/calendar.ts. The function takes a month and year and generates a content calendar based on the weekly content mix. For each posting slot (for example, Monday, Wednesday, and Friday at 9 AM), assign a content theme according to the mix percentages. Generate the calendar as a JSON structure and as a visual HTML view showing a monthly grid with each day's planned posts colour-coded by theme. Ask Claude Code: Create a batch content creation system at src/content-generator.ts. Given a content theme and a topic, generate content variations for each platform. For Twitter/X: under 280 characters, punchy and conversational, with 2 to 3 relevant hashtags. For LinkedIn: 150 to 300 words, professional tone, opens with a hook or question, ends with a call to engage. For Instagram: caption with emojis, 5 to 10 niche hashtags, optimised for the platform's algorithm. For Threads: casual, conversational, 1 to 3 short paragraphs. The generator should accept a single core message and adapt it for each platform — never post identical content across platforms. Run it: npx ts-node src/generate-batch.ts "educational" "5 ways AI is changing small business operations". Review the output for each platform. Ask Claude Code: Create a week-of-content generator that takes the calendar for a given week and generates draft posts for every scheduled slot. Save drafts in a content/ directory organised by date. Include a review checklist for each post: is the tone right for the platform, is the length appropriate, are hashtags relevant and not overused, and does the content provide value. This batch approach lets you create a full week of content in about an hour instead of scrambling for ideas daily.
Scheduling and queue management
Consistent posting at optimal times drives engagement. Ask Claude Code: Create a post scheduling system at src/scheduler.ts. Build a queue that stores scheduled posts with their target datetime and platforms. The queue should support: adding a post to the schedule, rescheduling a post to a different time, removing a post from the schedule, viewing all upcoming posts in chronological order, and checking for scheduling conflicts (two posts on the same platform within 2 hours). Define optimal posting times per platform based on general B2B engagement data: Twitter at 9 AM, 12 PM, and 5 PM on weekdays, LinkedIn at 8 AM and 12 PM Tuesday through Thursday, Instagram at 11 AM and 7 PM on weekdays, and Threads at 10 AM and 6 PM on weekdays. All times in the account's configured timezone. Ask Claude Code: Create a posting queue manager at src/queue.ts. The queue has three states: upcoming (scheduled for the future), ready (within 5 minutes of the scheduled time), and published (successfully posted). A polling function runs every minute, checks for ready posts, and moves them to published after sending to the platform API. For this guide, simulate the API call with a function that logs the post details and returns a success or failure randomly 95 percent of the time. Ask Claude Code: Add failure handling. When a post fails to publish, retry 3 times with 5-minute intervals. If all retries fail, move the post to a failed state and send an email notification. Add a retry-all-failed command that requeues all failed posts. Create an undo feature: within 5 minutes of a post being published, allow it to be marked for deletion (for platforms that support programmatic deletion). Show the posting queue as an HTML page with a timeline view — each day shows the scheduled posts with their platform icons, times, and status badges.
Cross-platform content adaptation
Each platform has different content requirements, character limits, image sizes, and audience expectations. Ask Claude Code: Create a platform adapter system at src/adapters/. Build adapters for each platform that transform a generic post into platform-specific content. The Twitter adapter should: enforce the 280-character limit (truncate with an ellipsis if needed), convert long URLs to a placeholder (Twitter auto-shortens), limit hashtags to 3 to 5, and validate image dimensions (recommended 1200x675 for link cards, 1080x1080 for photos). The LinkedIn adapter should: format with proper paragraph breaks for readability, add a hook question in the first line (this appears before the See more fold), strip hashtags from the body and add them at the end, and validate image dimensions (1200x627 for link shares, 1080x1080 for photos). The Instagram adapter should: prepend relevant emojis to the caption, add 15 to 20 hashtags in a separate block at the end (hidden by a line of dots), ensure an image is attached (Instagram requires visual content), and validate image dimensions (1080x1080 for feed, 1080x1350 for portrait). Ask Claude Code: Create a content preview system. Before scheduling, show a visual mockup of how the post will look on each platform. Create HTML templates that approximate the layout of a tweet, a LinkedIn post, an Instagram post, and a Threads post. Render the adapted content into these templates so you can review the appearance before scheduling. Ask Claude Code: Add a character count and validation indicator. Show real-time feedback as content is edited: Twitter shows remaining characters with the count turning red when over 260, LinkedIn shows word count and readability score, and Instagram shows hashtag count with a recommendation range.
Engagement analytics and reporting
Publishing without measuring is flying blind. Ask Claude Code: Create an analytics system at src/analytics.ts. Define metrics for each post: impressions (how many saw it), engagements (likes, comments, shares, clicks), engagement rate (engagements divided by impressions), clicks (link clicks), and reach (unique users who saw it). Create a mock data generator that produces realistic engagement data for 30 days of posts across all platforms, with LinkedIn posts getting higher engagement rates but lower impressions than Twitter, Instagram getting the most impressions on visual content, and engagement varying by content theme and time of posting. Build five analytics reports. Best Performing Posts: rank all posts by engagement rate. Show the top 10 with the post content preview, platform, time, and metrics. Identify patterns — which themes, times, and content types get the most engagement. Platform Comparison: side-by-side metrics for each platform showing total impressions, average engagement rate, follower growth, and best performing post. This reveals which platforms are worth your time. Content Theme Performance: average engagement per theme. Is educational content outperforming promotional? Should you adjust the content mix? Optimal Posting Times: create a heatmap showing average engagement by day of week and hour. This data-driven approach replaces generic best time to post advice with your specific audience's behaviour. Weekly Summary: total posts published, total impressions, total engagements, top post, follower count change, and comparison to the previous week. Ask Claude Code: Generate all five reports as an HTML dashboard with interactive charts.
Hashtag research and content ideas
Relevant hashtags increase discoverability. The wrong hashtags waste potential reach. Ask Claude Code: Create a hashtag research tool at src/hashtags.ts. Build a hashtag database with categories matching your content themes. For each hashtag, store: the tag text, the category, estimated reach (broad, medium, niche), and a relevance score for your content. Create a recommendation engine that takes a post's text content and suggests hashtags. The recommendation should mix reach levels: 2 to 3 broad hashtags for maximum exposure (over 1 million posts), 3 to 5 medium hashtags for targeted reach (10K to 1 million posts), and 2 to 3 niche hashtags for engaged communities (under 10K posts). This mix strategy balances discoverability with the chance of being seen in the feed. Ask Claude Code: Create a content ideas generator at src/ideas.ts. Given a content theme and a topic area, generate 10 post ideas with: a working title, a one-sentence hook, the target platform (which platform this idea works best on), and a suggested content format (text, image with text overlay, carousel, thread, or video script). Organise ideas into an ideas backlog stored as a JSON file. Add a status field: idea, in-progress, drafted, published. When you are stuck for content, run the generator for inspiration. Ask Claude Code: Add a trending topics scanner. Create a function that takes a list of industry keywords and searches for recent popular posts about those topics (simulated with sample data for this guide). Identify trending conversations you could join with relevant content. For each trend, suggest a post that adds your unique perspective. This turns reactive social media (posting into the void) into proactive social media (joining conversations where your audience is already engaged).
Deploying as a web application
Convert the social media management system into a web application for daily use. Ask Claude Code: Build a Next.js web application for the social media manager. Create these pages. Dashboard: overview with upcoming scheduled posts, today's publishing queue, this week's engagement summary, and any failed posts needing attention. Calendar view: monthly calendar showing all posts colour-coded by theme and platform. Click a day to see posts or add new ones. Content editor: create and edit posts with the platform preview, character count, hashtag suggestions, and scheduling controls. All platforms visible side by side so you can adapt the content for each. Analytics: the full analytics dashboard with all five reports, date range filtering, and export functionality. Settings: manage connected accounts, posting schedules, content themes, and notification preferences. Ask Claude Code: Add a content approval workflow for teams. Posts can have a status of draft, pending_approval, approved, or rejected. When a team member creates a post, it goes to pending_approval. An approver can preview it on all platforms and approve, reject with comments, or edit and approve. Only approved posts can be scheduled. Add email notifications for approval requests and rejections. Deploy the application to Vercel with a PostgreSQL database on Railway for storing posts, schedules, and analytics data. Set up the scheduler as a cron job that runs every minute to process the posting queue. Add the weekly analytics email report as a scheduled task. The complete system replaces tools like Buffer, Hootsuite, or Later — which typically cost 15 to 100 dollars per month. You have full control over the features, your data stays in your infrastructure, and you can customise the content generation to your exact brand voice and strategy.
AI for Marketing
This guide is hands-on and practical. The full curriculum covers the conceptual foundations in depth with structured lessons and quizzes.
Go to lesson