@bernierllc/ai-social-generator
v1.2.0
Published
AI-powered social media post generation service with platform-specific optimization and validation
Readme
@bernierllc/ai-social-generator
AI-powered social media post generation service with platform-specific optimization and validation.
Overview
The @bernierllc/ai-social-generator package provides a specialized service for generating social media posts from source content (blog posts, articles, etc.) with platform-specific optimization, character limits, hashtag generation, and content validation using social media content type validators.
Features
- Multi-Platform Generation: Generate posts for Twitter, LinkedIn, Facebook, Instagram, Mastodon, and BlueSky
- Platform-Specific Optimization: Character limits, tone, and formatting optimized for each platform
- Content Validation: Validates generated content against platform constraints
- Hashtag & Mention Extraction: Automatically extracts hashtags and mentions from generated content
- Thread Generation: Automatically splits long Twitter content into threads
- Multi-Platform Batch: Generate posts for multiple platforms in parallel
- Uses AI Content Generator: Leverages
@bernierllc/ai-content-generatorfor actual generation
Installation
npm install @bernierllc/ai-social-generatorUsage
import { AISocialGenerator, createAISocialGenerator } from '@bernierllc/ai-social-generator';
import { OpenAIProvider } from '@bernierllc/ai-provider-openai';
// Create AI provider
const provider = new OpenAIProvider({
providerName: 'openai',
apiKey: process.env.OPENAI_API_KEY!
});
// Create social generator
const generator = createAISocialGenerator({
contentGenerator: {
provider
},
enableValidation: true
});
// Generate a single post
const result = await generator.generatePost(
'Excited to announce our new TypeScript features that improve developer productivity by 50%!',
'twitter',
{
tone: 'professional',
includeHashtags: true,
maxHashtags: 3,
includeEmojis: true,
includeCTA: true,
generateThread: false
}
);
if (result.success) {
console.log('Generated:', result.content);
console.log('Hashtags:', result.hashtags);
console.log('Mentions:', result.mentions);
if (result.thread) {
console.log('Thread:', result.thread);
}
}
// Generate for multiple platforms
const multiResult = await generator.generateMultiPlatform(
'Source content for social posts',
['twitter', 'linkedin', 'facebook'],
{
tone: 'professional',
includeHashtags: true
}
);
console.log(`Generated ${multiResult.successCount} of ${multiResult.totalGenerated} posts`);
for (const [platform, post] of multiResult.results) {
if (post.success) {
console.log(`${platform}: ${post.content}`);
}
}API
AISocialGenerator
Constructor
new AISocialGenerator(config: AISocialGeneratorConfig)Config Options:
contentGenerator(required) - AI Content Generator configurationprovider(required) - AI provider instancefallbackProvider(optional) - Fallback provider for failover
enableValidation(optional) - Enable content validation (default: true)enableNeverHub(optional) - Enable NeverHub integration (default: false)
Methods
generatePost(sourceContent: string, platform: SocialPlatform, options?: SocialGenerationOptions): Promise<GeneratedSocialPost>- Generate a single social postgenerateMultiPlatform(sourceContent: string, platforms: SocialPlatform[], options?: SocialGenerationOptions): Promise<MultiPlatformResult>- Generate posts for multiple platformsshutdown(): void- Shutdown the generator gracefully
Social Generation Options
interface SocialGenerationOptions {
tone?: 'professional' | 'casual' | 'humorous' | 'informative' | 'promotional';
includeHashtags?: boolean;
maxHashtags?: number;
includeCTA?: boolean;
generateThread?: boolean; // For Twitter
includeEmojis?: boolean;
audience?: string;
customPrompt?: string;
}Generated Social Post
interface GeneratedSocialPost {
success: boolean;
content: string;
platform: SocialPlatform;
characterCount: number;
hashtags?: string[];
mentions?: string[];
thread?: string[]; // For Twitter threads
metadata: {
generatedAt: Date;
model: string;
tokensUsed: number;
costUsd: number;
durationMs: number;
};
error?: string;
}Platform Specifications
| Platform | Max Length | Default Tone | |----------|-----------|--------------| | Twitter | 280 | Concise and engaging | | LinkedIn | 3000 | Professional | | Facebook | 5000 | Conversational | | Instagram | 2200 | Visual and engaging | | Mastodon | 500 | Community-focused | | BlueSky | 300 | Authentic |
Thread Generation
For Twitter, when content exceeds 280 characters and generateThread: true is set, the generator automatically splits the content into a thread:
const result = await generator.generatePost(
'Very long content that exceeds 280 characters...',
'twitter',
{ generateThread: true }
);
if (result.thread) {
// result.thread is an array of tweets
console.log(`Thread has ${result.thread.length} tweets`);
}Content Validation
When enableValidation is true, generated content is validated against platform constraints:
- Character Limits: Content is checked against platform-specific limits
- Twitter Validation: Uses
@bernierllc/social-media-content-type-twittervalidator - Auto-Truncation: Content exceeding limits is automatically truncated (unless thread generation is enabled)
Integration Status
- Logger: ✅ Integrated - Uses
@bernierllc/loggerfor all logging operations - Docs-Suite: ✅ Ready - Full TypeDoc API documentation available
- NeverHub: ⚠️ Optional - Can emit social generation events to NeverHub event bus for distributed observability
Dependencies
@bernierllc/ai-content-generator- Content generation service@bernierllc/content-type-registry- Content type management@bernierllc/social-media-content-type-*- Platform validators (6 packages)@bernierllc/logger- Logging@bernierllc/retry-policy- Retry logic@bernierllc/neverhub-adapter- Service discovery (optional)
Testing
Run tests with:
npm test
npm run test:coverageTarget coverage: 85%+ (service package standard)
License
Copyright (c) 2025 Bernier LLC
This file is licensed to the client under a limited-use license. The client may use and modify this code only within the scope of the project it was delivered for. Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
