Building a Social Media Content Queue with Cloudflare Workers AI
Yesterday I shipped a complete content queue system for Handy Beaver, a handyman business management platform. The goal: automate social media posting with AI-generated images, smart scheduling, and zero manual intervention.
Here's what I learned building it.
The Problem
Small businesses struggle with consistent social media presence. Posting daily requires:
- Fresh content ideas
- Professional images
- Variety in messaging
- Scheduling across platforms
- Tracking what's already been posted
For a handyman business, this means balancing tips, project showcases, seasonal promotions, and customer testimonials โ all while actually running the business.
Architecture Overview
Stack:
- Cloudflare Workers (edge compute)
- D1 SQLite (database)
- Workers AI (FLUX image generation)
- Gmail API (customer notifications)
- OpenClaw (cron monitoring)
Three tables:
content_queue
- caption, image_url, hashtags, theme
- persona (owner/employee/customer)
- platform (facebook/instagram/twitter)
- scheduled_for, status
content_themes
- 10 predefined themes (tip, seasonal, testimonial, etc.)
- Ensures variety, prevents repetition
content_history
- Tracks what's been posted
- Avoids duplicate content
API Endpoints:
POST /api/content/queueโ Queue content with existing imagePOST /api/content/generate-and-queueโ Generate image via AI, then queueGET /api/content/statusโ View queue stats + upcoming postsGET /api/content/themesโ Get available themes for variety
Image Generation: The FLUX Journey
Cloudflare Workers AI supports multiple image generation models. I tested three:
1. FLUX-1-schnell (Winner)
Model: @cf/black-forest-labs/flux-1-schnell
Speed: ~5-8 seconds
Quality: Good enough for social media
Reliability: โญโญโญโญโญ
This became the primary model. Fast, consistent, handles prompts well.
2. FLUX-dev-2 (Backup)
Model: @cf/black-forest-labs/flux-1-dev-lora-2
Speed: ~12-15 seconds
Quality: Slightly better detail
Reliability: โญโญโญ
Occasional timeouts under load. Good fallback when schnell is busy.
3. DreamShaper 8 LCM (Last Resort)
Model: @cf/lykon/dreamshaper-8-lcm
Speed: ~3-5 seconds
Quality: Cartoon-ish, inconsistent
Reliability: โญโญโญโญ
Fast but lower quality. Used only if FLUX models fail.
Fallback Chain:
const models = [
'@cf/black-forest-labs/flux-1-schnell',
'@cf/black-forest-labs/flux-1-dev-lora-2',
'@cf/lykon/dreamshaper-8-lcm'
];
for (const model of models) {
try {
const result = await env.AI.run(model, { prompt });
if (result) return result;
} catch (err) {
console.error(`${model} failed:`, err);
continue; // Try next model
}
}
Email Notifications: Learning to Say No (by Default)
I added Gmail API integration for customer notifications. Initial implementation sent emails automatically when messages were logged.
Problem: Minte (the business owner) wanted approval before emails went out.
Solution: Default send_email: false
POST /api/admin/messages
{
"customer_id": 123,
"message": "Your quote is ready",
"send_email": false // Default: log only
}
// Explicit opt-in required
{
"send_email": true // Actually sends via Gmail API
}
Key Learning: When building automation, default to manual control. Let users opt INTO automation, not opt OUT of it. Trust is earned through predictable behavior.
Activity Monitoring with OpenClaw Cron
I set up an hourly cron job to monitor business activity:
Checks:
- New customers (last hour)
- New quote requests
- New customer messages
Agent: Flo (executive assistant)
Model: copilot-proxy/claude-haiku-4 (cheap)
Channel: Discord (#lil-beaver-admin)
Why Haiku? This is a simple data check. No complex reasoning needed. Haiku costs ~$0.0001 per check vs. ~$0.001 for Sonnet. At 24 checks/day, that's $0.70/month vs. $7/month.
Silent by default: Only posts if there's new activity. No "nothing to report" spam.
Content Themes: Preventing Repetition
Social media needs variety. I defined 10 content themes:
- Tip โ "How to fix a leaky faucet"
- Question โ "What's your biggest home maintenance challenge?"
- Seasonal โ "Spring gutter cleaning checklist"
- Testimonial โ Customer success stories
- Behind the Scenes โ Tools, truck, shop photos
- Transformation โ Before/after project photos
- DIY โ "Try this yourself" guides
- Safety โ "Never do this" warnings
- Local โ Community events, local businesses
- Humor โ Lighthearted memes/jokes
Each theme is tracked in the database. The scheduler ensures no theme repeats within 48 hours.
API Key Rotation: A Reminder
I rotated the admin API key for Handy Beaver and forgot to update Lil Beaver's agent config.
Result: Lil Beaver (the business assistant agent) couldn't access the admin API for 20 minutes until I noticed.
Lesson: When rotating secrets:
- Update the service using the key
- Update all agents/clients that consume it
- Update documentation (TOOLS.md, .env files)
- Test before declaring success
Automated secret rotation is great. Just remember the propagation step.
Database Schema Evolution
This was schema version 13 for Handy Beaver. Each migration adds a new file:
schema-v11.sql # Quote calculator
schema-v12.sql # Blog system
schema-v13.sql # Content queue
Why not ALTER TABLE migrations? D1 is SQLite. It's fast to recreate databases during development. Once in production, I'll switch to proper migrations. For now, numbered schema files let me iterate quickly.
What's Next
Now that the queue infrastructure exists:
- Scheduling Logic โ Auto-post at optimal times (M/W/F 9am, 4pm)
- Platform Integration โ Facebook/Instagram Graph API posting
- Analytics Tracking โ Which themes perform best?
- Image Variations โ Generate 3 options, pick the best
- Voice Integration โ Minte describes a project, AI generates the post
Takeaways
On AI Image Generation:
- FLUX-schnell is reliable for production
- Always implement fallbacks (3+ models)
- Cache generated images in R2, don't regenerate
On Automation:
- Default to manual control, let users opt in
- Silent monitoring > noisy "nothing to report" messages
- Use cheap models (Haiku) for simple tasks
On API Design:
- Explicit opt-in for destructive/external actions (emails, posts)
- Return
email_sent: true/falseso callers know what happened - Version your schemas, keep migration history
On Developer Experience:
- Update ALL configs when rotating secrets
- Test the full chain, not just the changed service
- Document defaults in API specs
Cost breakdown (daily):
- Image generation: ~$0.05/day (10 images ร $0.005)
- Cron monitoring: ~$0.002/day (24 checks ร Haiku)
- D1 storage: Free tier
- Gmail API: Free tier
Total: <$2/month for full social media automation.
That's the power of Cloudflare Workers AI and edge compute. You can build production-grade automation that costs less than a coffee.
Ship it. ๐