Social Media Post Generator

Transform blog posts and announcements into platform-optimized social content.

This workflow adapts content for Twitter, LinkedIn, Facebook, and Instagram with platform-specific best practices.

Implementation

1import { relay } from "@relayplane/workflows";
2
3const result = await relay
4 .workflow("social-post-generator")
5
6 // Step 1: Extract key messages
7 .step("extract-key-messages")
8 .with("anthropic:claude-3.5-sonnet")
9 .prompt(`Extract the most compelling points from this content:
10
11{{sourceContent}}
12
13Identify:
14- Main headline/hook (most attention-grabbing angle)
15- 3 supporting points
16- Call-to-action
17- Relevant hashtags (trending + niche)
18- Target audience pain point addressed
19
20This will be adapted for social media.`)
21
22 // Step 2: Generate Twitter/X thread
23 .step("twitter-thread")
24 .with("openai:gpt-4o")
25 .depends("extract-key-messages")
26 .prompt(`Create a Twitter/X thread (5 tweets max):
27
28Key Messages: {{extract-key-messages.output}}
29
30Tweet 1: Hook (stop the scroll)
31Tweets 2-4: Value/insights
32Tweet 5: CTA + link
33
34Each tweet:
35- Under 280 characters
36- One clear idea per tweet
37- Use line breaks for readability
38- End with question or CTA
39- Include 2-3 relevant hashtags
40
41Engaging, conversational tone.`)
42
43 // Step 3: Generate LinkedIn post
44 .step("linkedin-post")
45 .with("anthropic:claude-3.5-sonnet")
46 .depends("extract-key-messages")
47 .prompt(`Create a LinkedIn post:
48
49Key Messages: {{extract-key-messages.output}}
50
51Structure:
52- Hook (first 2 lines visible in feed)
53- Personal angle or story (200 words)
54- Insights/lessons
55- CTA
56
57Style:
58- Professional but approachable
59- Use "I/we" for authenticity
60- Break into short paragraphs
61- Strategic emoji use (3-4 max)
62- End with thought-provoking question
63
641000-1300 characters.`)
65
66 // Step 4: Generate Instagram caption
67 .step("instagram-caption")
68 .with("openai:gpt-4o")
69 .depends("extract-key-messages")
70 .prompt(`Create Instagram caption:
71
72Key Messages: {{extract-key-messages.output}}
73
74Requirements:
75- Casual, authentic voice
76- Front-load value in first line
77- Use emoji strategically
78- Include storytelling element
79- 10-15 hashtags (mix of popular and niche)
80- CTA in last line
81- "Link in bio" if applicable
82
83Target length: 150-200 words`)
84
85 // Step 5: Suggest visual concepts
86 .step("visual-concepts")
87 .with("anthropic:claude-3.5-sonnet")
88 .depends("extract-key-messages")
89 .prompt(`Suggest visual concepts for each platform:
90
91Content: {{extract-key-messages.output}}
92
93For each platform (Twitter, LinkedIn, Instagram):
94- Image style (photo, graphic, screenshot, etc.)
95- Key text overlay (if any)
96- Color scheme
97- Composition notes
98- DALL-E prompt for generation
99
100Make visuals platform-appropriate.`)
101
102 .run({
103 sourceContent: blogPost,
104 });
105
106console.log("Twitter Thread:", result.steps["twitter-thread"].output);
107console.log("LinkedIn:", result.steps["linkedin-post"].output);
108console.log("Instagram:", result.steps["instagram-caption"].output);
109console.log("Visuals:", result.steps["visual-concepts"].output);

Automated Publishing

1import { relay } from "@relayplane/workflows";
2import { TwitterApi } from 'twitter-api-v2';
3import { LinkedInApi } from 'linkedin-api-client';
4
5async function publishToSocial(blogUrl: string, content: string) {
6 // Generate posts
7 const result = await relay
8 .workflow("social-post-generator")
9 .run({ sourceContent: content });
10
11 // Parse outputs
12 const twitterThread = result.steps["twitter-thread"].output.split("\n\n");
13 const linkedInPost = result.steps["linkedin-post"].output;
14
15 // Publish to Twitter
16 const twitter = new TwitterApi(process.env.TWITTER_TOKEN);
17 let lastTweetId;
18 for (const tweet of twitterThread) {
19 const posted = await twitter.v2.tweet({
20 text: tweet,
21 reply: lastTweetId ? { in_reply_to_tweet_id: lastTweetId } : undefined,
22 });
23 lastTweetId = posted.data.id;
24 }
25
26 // Publish to LinkedIn
27 const linkedin = new LinkedInApi(process.env.LINKEDIN_TOKEN);
28 await linkedin.posts.create({
29 author: `urn:li:person:${PERSON_ID}`,
30 commentary: linkedInPost,
31 visibility: 'PUBLIC',
32 distribution: {
33 linkedInDistributionTarget: {},
34 },
35 });
36
37 console.log("Published to all platforms!");
38}

Content Calendar Integration

1// Generate week's worth of posts
2const contentCalendar = [
3 { topic: "New feature announcement", date: "2024-11-18" },
4 { topic: "Customer success story", date: "2024-11-20" },
5 { topic: "Industry trends analysis", date: "2024-11-22" },
6];
7
8for (const item of contentCalendar) {
9 const posts = await relay
10 .workflow("social-post-generator")
11 .run({ sourceContent: item.topic });
12
13 // Schedule for future publishing
14 await schedulePost({
15 platform: "all",
16 content: posts,
17 publishAt: item.date,
18 });
19}

Sample Output

**Twitter Thread:** 1/ Just shipped a feature that saves our users 10+ hours/week The problem? Manual data entry across 5 different tools. Here's how we automated it (and why you can too) 2/ Traditional integration tools require code for every edge case. We flipped it: AI agents handle the "fuzzy logic" parts, deterministic code handles the critical paths. Result: 90% less code to maintain. 3/ The secret? Multi-model workflows... [continues]

Best Practices

  • Always review AI-generated posts before publishing
  • A/B test different hooks and CTAs
  • Adjust tone based on platform (LinkedIn more formal than Twitter)
  • Use platform analytics to refine prompts over time