Content Services
The Content Services provide comprehensive content management capabilities including social media content creation, synchronization, analytics, and bio link management for the VChata platform.Overview
The Content Services layer includes:- 📝 Content Service - Core content creation and management
- 🔄 Content Sync Service - Social media synchronization and live data fetching
- 🔗 Bio Link Service - Bio link creation and management
- 📊 Content Analytics - Performance tracking and insights
- 🎯 Content Attribution - Track content performance and lead generation
Content Service
Core Content Management
The Content Service handles all content-related operations including creation, updates, and retrieval.Create Content Post
// Create a new content post
const contentPost = await contentService.createContentPost(
organizationId,
{
socialAccountId: "social_123",
platform: "FACEBOOK",
content: "Check out our new product!",
scheduledAt: "2024-01-20T10:00:00Z",
tags: ["product", "launch"],
keyword: "new-product-2024",
utmSource: "social_media",
utmMedium: "post",
utmCampaign: "product_launch"
}
);
Get Content Posts
// Get content posts with filtering
const posts = await contentService.getContentPosts(
organizationId,
{
socialAccountId: "social_123",
platform: "FACEBOOK",
tags: ["product"],
dateFrom: "2024-01-01",
dateTo: "2024-01-31",
includeLiveData: true
}
);
Update Content Post
// Update content post
const updatedPost = await contentService.updateContentPost(
postId,
{
content: "Updated content with new information",
tags: ["product", "updated"],
scheduledAt: "2024-01-21T10:00:00Z"
}
);
Content Operations
Show createContentPost(organizationId, postData)
Show createContentPost(organizationId, postData)
organizationId: Organization IDpostData: Post configuration and content
Promise<ContentPost> - Created content postShow getContentPosts(organizationId, filters)
Show getContentPosts(organizationId, filters)
organizationId: Organization IDfilters: Filtering options (platform, tags, date range, etc.)
Promise<ContentPost[]> - List of content postsShow updateContentPost(postId, updates)
Show updateContentPost(postId, updates)
postId: Content post IDupdates: Update data
Promise<ContentPost> - Updated content postShow deleteContentPost(postId)
Show deleteContentPost(postId)
postId: Content post ID
Promise<void>Show getContentAnalytics(organizationId, dateRange)
Show getContentAnalytics(organizationId, dateRange)
organizationId: Organization IDdateRange: Date range for analytics
Promise<ContentAnalytics> - Analytics dataContent Sync Service
Social Media Synchronization
The Content Sync Service handles synchronization with social media platforms and live data fetching.Sync Content
// Sync content from social media platform
const syncResult = await contentSyncService.syncContent(
organizationId,
{
socialAccountId: "social_123",
platform: "FACEBOOK",
syncType: "posts",
dateRange: {
start: "2024-01-01",
end: "2024-01-31"
}
}
);
Fetch Live Data
// Fetch live data for existing posts
const liveData = await contentSyncService.fetchLiveData(
organizationId,
{
postIds: ["post_123", "post_456"],
includeMetrics: true,
includeComments: true,
includeReactions: true
}
);
Auto-Sync New Posts
// Automatically sync new posts from platform
const newPosts = await contentSyncService.autoSyncNewPosts(
organizationId,
{
socialAccountId: "social_123",
platform: "FACEBOOK",
batchSize: 20,
createTrackingRecords: true
}
);
Sync Operations
Show syncContent(organizationId, syncOptions)
Show syncContent(organizationId, syncOptions)
organizationId: Organization IDsyncOptions: Synchronization configuration
Promise<SyncResult> - Synchronization resultsShow fetchLiveData(organizationId, options)
Show fetchLiveData(organizationId, options)
organizationId: Organization IDoptions: Live data fetching options
Promise<LiveDataResult> - Live data resultsShow autoSyncNewPosts(organizationId, options)
Show autoSyncNewPosts(organizationId, options)
organizationId: Organization IDoptions: Auto-sync configuration
Promise<ContentPost[]> - Newly synced postsShow mergeLiveData(posts, liveData)
Show mergeLiveData(posts, liveData)
posts: Existing content postsliveData: Live data from platforms
Promise<ContentPost[]> - Merged posts with live dataBio Link Service
Bio Link Management
The Bio Link Service handles creation and management of bio links for social media profiles.Create Bio Link
// Create a new bio link
const bioLink = await bioLinkService.createBioLink(
organizationId,
{
title: "Summer Sale 2024",
description: "Check out our amazing summer deals!",
url: "https://acme.com/summer-sale",
imageUrl: "https://acme.com/images/summer-banner.jpg",
buttonText: "Shop Now",
utmSource: "bio_link",
utmMedium: "social",
utmCampaign: "summer_2024",
isActive: true
}
);
Get Bio Links
// Get bio links for organization
const bioLinks = await bioLinkService.getBioLinks(
organizationId,
{
isActive: true,
sortBy: "createdAt",
sortOrder: "desc"
}
);
Update Bio Link
// Update bio link
const updatedBioLink = await bioLinkService.updateBioLink(
bioLinkId,
{
title: "Updated Summer Sale 2024",
description: "New and improved summer deals!",
url: "https://acme.com/summer-sale-v2"
}
);
Bio Link Operations
Show createBioLink(organizationId, linkData)
Show createBioLink(organizationId, linkData)
organizationId: Organization IDlinkData: Bio link configuration
Promise<BioLink> - Created bio linkShow getBioLinks(organizationId, filters)
Show getBioLinks(organizationId, filters)
organizationId: Organization IDfilters: Filtering options
Promise<BioLink[]> - List of bio linksShow updateBioLink(bioLinkId, updates)
Show updateBioLink(bioLinkId, updates)
bioLinkId: Bio link IDupdates: Update data
Promise<BioLink> - Updated bio linkShow deleteBioLink(bioLinkId)
Show deleteBioLink(bioLinkId)
bioLinkId: Bio link ID
Promise<void>Show trackBioLinkClick(bioLinkId, clickData)
Show trackBioLinkClick(bioLinkId, clickData)
bioLinkId: Bio link IDclickData: Click tracking data
Promise<void>Content Analytics
Performance Tracking
Content analytics provide insights into content performance and engagement.Get Content Performance
// Get content performance metrics
const performance = await contentService.getContentPerformance(
organizationId,
{
dateRange: {
start: "2024-01-01",
end: "2024-01-31"
},
platforms: ["FACEBOOK", "INSTAGRAM"],
metrics: ["reach", "engagement", "clicks", "conversions"]
}
);
Get Top Performing Content
// Get top performing content
const topContent = await contentService.getTopPerformingContent(
organizationId,
{
metric: "engagement_rate",
limit: 10,
dateRange: {
start: "2024-01-01",
end: "2024-01-31"
}
}
);
Get Content Insights
// Get detailed content insights
const insights = await contentService.getContentInsights(
organizationId,
{
postId: "post_123",
includeAudience: true,
includeTiming: true,
includeKeywords: true
}
);
Analytics Operations
Show getContentPerformance(organizationId, options)
Show getContentPerformance(organizationId, options)
organizationId: Organization IDoptions: Performance analysis options
Promise<ContentPerformance> - Performance metricsShow getTopPerformingContent(organizationId, options)
Show getTopPerformingContent(organizationId, options)
organizationId: Organization IDoptions: Top content filtering options
Promise<ContentPost[]> - Top performing contentShow getContentInsights(organizationId, options)
Show getContentInsights(organizationId, options)
organizationId: Organization IDoptions: Insights configuration
Promise<ContentInsights> - Detailed insightsShow getContentTrends(organizationId, options)
Show getContentTrends(organizationId, options)
organizationId: Organization IDoptions: Trend analysis options
Promise<ContentTrends> - Trend analysisContent Attribution
Lead Generation Tracking
Content attribution tracks how content generates leads and conversions.Track Content Interaction
// Track content interaction for attribution
await contentService.trackContentInteraction(
organizationId,
{
contentPostId: "post_123",
interactionType: "click",
userId: "user_456",
utmData: {
source: "social_media",
medium: "post",
campaign: "summer_sale"
}
}
);
Get Content Attribution
// Get content attribution data
const attribution = await contentService.getContentAttribution(
organizationId,
{
contentPostId: "post_123",
dateRange: {
start: "2024-01-01",
end: "2024-01-31"
},
includeConversions: true
}
);
Link Content to Lead
// Link content to lead for attribution
await contentService.linkContentToLead(
organizationId,
{
contentPostId: "post_123",
leadId: "lead_456",
attributionType: "first_touch",
attributionWeight: 1.0
}
);
Attribution Operations
Show trackContentInteraction(organizationId, interactionData)
Show trackContentInteraction(organizationId, interactionData)
organizationId: Organization IDinteractionData: Interaction tracking data
Promise<void>Show getContentAttribution(organizationId, options)
Show getContentAttribution(organizationId, options)
organizationId: Organization IDoptions: Attribution analysis options
Promise<ContentAttribution> - Attribution dataShow linkContentToLead(organizationId, linkData)
Show linkContentToLead(organizationId, linkData)
organizationId: Organization IDlinkData: Content-lead link data
Promise<void>Show getAttributionReport(organizationId, options)
Show getAttributionReport(organizationId, options)
organizationId: Organization IDoptions: Report configuration
Promise<AttributionReport> - Attribution reportIntegration Examples
Complete Content Creation Flow
// Complete content creation and publishing workflow
async function createAndPublishContent(
organizationId: string,
contentData: any
) {
try {
// 1. Create content post
const contentPost = await contentService.createContentPost(
organizationId,
contentData
);
// 2. Sync with social media platform
const syncResult = await contentSyncService.syncContent(
organizationId,
{
socialAccountId: contentData.socialAccountId,
platform: contentData.platform,
syncType: "posts",
createTrackingRecords: true
}
);
// 3. Track for attribution
await contentService.trackContentInteraction(
organizationId,
{
contentPostId: contentPost.id,
interactionType: "created",
userId: contentData.userId
}
);
// 4. Set up analytics tracking
await contentService.setupAnalyticsTracking(
contentPost.id,
{
trackClicks: true,
trackEngagement: true,
trackConversions: true
}
);
return {
contentPost,
syncResult,
success: true
};
} catch (error) {
// Handle content creation errors
throw error;
}
}
Live Data Synchronization Flow
// Live data synchronization workflow
async function syncLiveData(organizationId: string, options: any) {
try {
// 1. Get existing posts
const existingPosts = await contentService.getContentPosts(
organizationId,
{
socialAccountId: options.socialAccountId,
platform: options.platform,
includeLiveData: false
}
);
// 2. Fetch live data from platform
const liveData = await contentSyncService.fetchLiveData(
organizationId,
{
postIds: existingPosts.map(p => p.id),
includeMetrics: true,
includeComments: true,
includeReactions: true
}
);
// 3. Merge live data with existing posts
const mergedPosts = await contentSyncService.mergeLiveData(
existingPosts,
liveData
);
// 4. Update posts with live data
for (const post of mergedPosts) {
await contentService.updateContentPost(post.id, {
liveMetrics: post.liveMetrics,
lastSyncedAt: new Date().toISOString()
});
}
// 5. Check for new posts and sync them
const newPosts = await contentSyncService.autoSyncNewPosts(
organizationId,
{
socialAccountId: options.socialAccountId,
platform: options.platform,
batchSize: 20,
createTrackingRecords: true
}
);
return {
updatedPosts: mergedPosts,
newPosts,
success: true
};
} catch (error) {
// Handle sync errors
throw error;
}
}
Content Performance Analysis Flow
// Content performance analysis workflow
async function analyzeContentPerformance(
organizationId: string,
analysisOptions: any
) {
try {
// 1. Get performance metrics
const performance = await contentService.getContentPerformance(
organizationId,
analysisOptions
);
// 2. Get top performing content
const topContent = await contentService.getTopPerformingContent(
organizationId,
{
metric: "engagement_rate",
limit: 10,
dateRange: analysisOptions.dateRange
}
);
// 3. Get content insights
const insights = await Promise.all(
topContent.map(post =>
contentService.getContentInsights(organizationId, {
postId: post.id,
includeAudience: true,
includeTiming: true,
includeKeywords: true
})
)
);
// 4. Get attribution data
const attribution = await contentService.getAttributionReport(
organizationId,
{
dateRange: analysisOptions.dateRange,
includeConversions: true,
includeRevenue: true
}
);
// 5. Generate recommendations
const recommendations = await contentService.generateRecommendations(
organizationId,
{
performance,
topContent,
insights,
attribution
}
);
return {
performance,
topContent,
insights,
attribution,
recommendations,
success: true
};
} catch (error) {
// Handle analysis errors
throw error;
}
}
Error Handling
Common Error Scenarios
Show Sync Failures
Show Sync Failures
try {
const syncResult = await contentSyncService.syncContent(orgId, options);
} catch (error) {
if (error.code === 'PLATFORM_API_ERROR') {
// Handle platform API errors
await retrySyncWithBackoff(orgId, options);
} else if (error.code === 'RATE_LIMIT_EXCEEDED') {
// Handle rate limiting
await delaySync(orgId, options, 60000); // Wait 1 minute
}
}
Show Content Creation Errors
Show Content Creation Errors
try {
const contentPost = await contentService.createContentPost(orgId, data);
} catch (error) {
if (error.code === 'INVALID_CONTENT') {
throw new BadRequestError('Invalid content format');
} else if (error.code === 'DUPLICATE_CONTENT') {
throw new ConflictError('Content already exists');
}
}
Show Analytics Errors
Show Analytics Errors
try {
const analytics = await contentService.getContentAnalytics(orgId, options);
} catch (error) {
if (error.code === 'INSUFFICIENT_DATA') {
return { analytics: null, message: 'Insufficient data for analysis' };
} else if (error.code === 'ANALYTICS_UNAVAILABLE') {
// Fallback to basic metrics
return await contentService.getBasicMetrics(orgId, options);
}
}
Performance Optimization
Caching Strategy
// Implement caching for content data
const cachedContent = await contentCache.get(`content:${organizationId}:${postId}`);
if (!cachedContent) {
const content = await contentService.getContentPost(postId);
await contentCache.set(`content:${organizationId}:${postId}`, content, 3600); // 1 hour
}
Batch Operations
// Batch content operations for better performance
const batchResults = await Promise.allSettled(
contentPosts.map(post =>
contentService.updateContentPost(post.id, updateData)
)
);
Rate Limiting
// Implement rate limiting for platform APIs
const rateLimiter = new RateLimiter({
windowMs: 60000, // 1 minute
max: 60 // 60 requests per minute
});
const syncWithRateLimit = rateLimiter.wrap(contentSyncService.syncContent);
Monitoring and Analytics
Content Metrics
// Track content metrics
const contentMetrics = {
totalPosts: await contentService.getTotalPosts(organizationId),
averageEngagement: await contentService.getAverageEngagement(organizationId),
topPlatform: await contentService.getTopPlatform(organizationId),
contentVelocity: await contentService.getContentVelocity(organizationId)
};
await analyticsService.track('content_metrics_updated', contentMetrics);
Sync Metrics
// Track sync performance
const syncMetrics = {
syncSuccessRate: await contentSyncService.getSyncSuccessRate(organizationId),
averageSyncTime: await contentSyncService.getAverageSyncTime(organizationId),
failedSyncs: await contentSyncService.getFailedSyncs(organizationId),
newPostsDiscovered: await contentSyncService.getNewPostsCount(organizationId)
};
await analyticsService.track('sync_metrics_updated', syncMetrics);