Base code
This commit is contained in:
213
backend/services/persona/facebook/facebook_persona_prompts.py
Normal file
213
backend/services/persona/facebook/facebook_persona_prompts.py
Normal file
@@ -0,0 +1,213 @@
|
||||
"""
|
||||
Facebook Persona Prompts
|
||||
Contains Facebook-specific persona prompt generation logic.
|
||||
"""
|
||||
|
||||
from typing import Dict, Any
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class FacebookPersonaPrompts:
|
||||
"""Facebook-specific persona prompt generation."""
|
||||
|
||||
@staticmethod
|
||||
def build_facebook_system_prompt(core_persona: Dict[str, Any]) -> str:
|
||||
"""
|
||||
Build optimized system prompt with core persona for Facebook generation.
|
||||
This moves the core persona to system prompt to free up context window.
|
||||
"""
|
||||
import json
|
||||
|
||||
return f"""You are an expert Facebook content strategist specializing in community engagement and social sharing optimization.
|
||||
|
||||
CORE PERSONA FOUNDATION:
|
||||
{json.dumps(core_persona, indent=2)}
|
||||
|
||||
TASK: Create Facebook-optimized persona adaptations that maintain core identity while maximizing community engagement and Facebook algorithm performance.
|
||||
|
||||
FOCUS AREAS:
|
||||
- Community-focused tone and engagement strategies
|
||||
- Facebook algorithm optimization (engagement, reach, timing)
|
||||
- Social sharing and viral content potential
|
||||
- Facebook-specific features (Stories, Reels, Live, Groups, Events)
|
||||
- Audience interaction and community building"""
|
||||
|
||||
@staticmethod
|
||||
def build_focused_facebook_prompt(onboarding_data: Dict[str, Any]) -> str:
|
||||
"""
|
||||
Build focused Facebook prompt without core persona JSON to optimize context usage.
|
||||
"""
|
||||
# Extract audience context
|
||||
audience_context = FacebookPersonaPrompts._extract_audience_context(onboarding_data)
|
||||
|
||||
target_audience = audience_context.get("target_audience", "general")
|
||||
content_goals = audience_context.get("content_goals", "engagement")
|
||||
business_type = audience_context.get("business_type", "general")
|
||||
|
||||
return f"""FACEBOOK OPTIMIZATION TASK: Create Facebook-specific adaptations for the core persona.
|
||||
|
||||
AUDIENCE CONTEXT:
|
||||
- Target: {target_audience} | Goals: {content_goals} | Business: {business_type}
|
||||
- Demographics: {audience_context.get('demographics', [])}
|
||||
- Interests: {audience_context.get('interests', [])}
|
||||
- Behaviors: {audience_context.get('behaviors', [])}
|
||||
|
||||
FACEBOOK SPECS:
|
||||
- Character Limit: 63,206 | Optimal Length: 40-80 words
|
||||
- Algorithm Priority: Engagement, meaningful interactions, community building
|
||||
- Content Types: Posts, Stories, Reels, Live, Events, Groups, Carousels, Polls
|
||||
- Hashtag Strategy: 1-2 recommended (max 30)
|
||||
- Link Strategy: Native content performs better
|
||||
|
||||
OPTIMIZATION REQUIREMENTS:
|
||||
|
||||
1. COMMUNITY-FOCUSED TONE:
|
||||
- Authentic, conversational, approachable language
|
||||
- Balance professionalism with relatability
|
||||
- Incorporate storytelling and personal anecdotes
|
||||
- Community-building elements
|
||||
|
||||
2. CONTENT STRATEGY FOR {business_type.upper()}:
|
||||
- Community engagement content for {target_audience}
|
||||
- Social sharing optimization for {content_goals}
|
||||
- Facebook-specific content formats
|
||||
- Audience interaction strategies
|
||||
- Viral content potential
|
||||
|
||||
3. FACEBOOK-SPECIFIC ADAPTATIONS:
|
||||
- Algorithm optimization (engagement, reach, timing)
|
||||
- Platform-specific vocabulary and terminology
|
||||
- Engagement patterns for Facebook audience
|
||||
- Community interaction strategies
|
||||
- Facebook feature optimization (Stories, Reels, Live, Events, Groups)
|
||||
|
||||
4. AUDIENCE TARGETING:
|
||||
- Demographic-specific positioning
|
||||
- Interest-based content adaptation
|
||||
- Behavioral targeting considerations
|
||||
- Community building strategies
|
||||
- Engagement optimization tactics
|
||||
|
||||
Generate comprehensive Facebook-optimized persona maintaining core identity while maximizing community engagement and social sharing potential."""
|
||||
|
||||
@staticmethod
|
||||
def _extract_audience_context(onboarding_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Extract audience context from onboarding data."""
|
||||
try:
|
||||
# Get enhanced analysis data
|
||||
enhanced_analysis = onboarding_data.get("enhanced_analysis", {})
|
||||
website_analysis = onboarding_data.get("website_analysis", {}) or {}
|
||||
research_prefs = onboarding_data.get("research_preferences", {}) or {}
|
||||
|
||||
# Extract audience intelligence
|
||||
audience_intel = enhanced_analysis.get("audience_intelligence", {})
|
||||
|
||||
# Extract target audience from website analysis
|
||||
target_audience_data = website_analysis.get("target_audience", {}) or {}
|
||||
|
||||
# Build audience context
|
||||
audience_context = {
|
||||
"target_audience": target_audience_data.get("primary_audience", "general"),
|
||||
"content_goals": research_prefs.get("content_goals", "engagement"),
|
||||
"business_type": website_analysis.get("business_type", "general"),
|
||||
"demographics": audience_intel.get("demographics", []),
|
||||
"interests": audience_intel.get("interests", []),
|
||||
"behaviors": audience_intel.get("behaviors", []),
|
||||
"psychographic_profile": audience_intel.get("psychographic_profile", "general"),
|
||||
"pain_points": audience_intel.get("pain_points", []),
|
||||
"engagement_level": audience_intel.get("engagement_level", "moderate")
|
||||
}
|
||||
|
||||
return audience_context
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Error extracting audience context: {str(e)}")
|
||||
return {
|
||||
"target_audience": "general",
|
||||
"content_goals": "engagement",
|
||||
"business_type": "general",
|
||||
"demographics": [],
|
||||
"interests": [],
|
||||
"behaviors": [],
|
||||
"psychographic_profile": "general",
|
||||
"pain_points": [],
|
||||
"engagement_level": "moderate"
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def build_facebook_validation_prompt(persona_data: Dict[str, Any]) -> str:
|
||||
"""Build optimized prompt for validating Facebook persona data."""
|
||||
return f"""FACEBOOK PERSONA VALIDATION TASK: Validate Facebook persona data for completeness and quality.
|
||||
|
||||
PERSONA DATA:
|
||||
{persona_data}
|
||||
|
||||
VALIDATION REQUIREMENTS:
|
||||
|
||||
1. COMPLETENESS CHECK:
|
||||
- Verify all required Facebook-specific fields are present
|
||||
- Check for missing algorithm optimization strategies
|
||||
- Validate engagement strategy completeness
|
||||
- Ensure content format rules are defined
|
||||
|
||||
2. QUALITY ASSESSMENT:
|
||||
- Evaluate Facebook algorithm optimization quality
|
||||
- Assess engagement strategy effectiveness
|
||||
- Check content format optimization
|
||||
- Validate audience targeting strategies
|
||||
|
||||
3. FACEBOOK-SPECIFIC VALIDATION:
|
||||
- Verify Facebook platform constraints are respected
|
||||
- Check for Facebook-specific best practices
|
||||
- Validate community building strategies
|
||||
- Ensure Facebook feature optimization
|
||||
|
||||
4. RECOMMENDATIONS:
|
||||
- Provide specific improvement suggestions
|
||||
- Identify missing optimization opportunities
|
||||
- Suggest Facebook-specific enhancements
|
||||
- Recommend engagement strategy improvements
|
||||
|
||||
Generate comprehensive validation report with scores, recommendations, and specific improvement suggestions for Facebook optimization."""
|
||||
|
||||
@staticmethod
|
||||
def build_facebook_optimization_prompt(persona_data: Dict[str, Any]) -> str:
|
||||
"""Build optimized prompt for optimizing Facebook persona data."""
|
||||
return f"""FACEBOOK PERSONA OPTIMIZATION TASK: Optimize Facebook persona data for maximum algorithm performance and community engagement.
|
||||
|
||||
CURRENT PERSONA DATA:
|
||||
{persona_data}
|
||||
|
||||
OPTIMIZATION REQUIREMENTS:
|
||||
|
||||
1. ALGORITHM OPTIMIZATION:
|
||||
- Enhance Facebook algorithm performance strategies
|
||||
- Optimize for Facebook's engagement metrics
|
||||
- Improve content timing and frequency
|
||||
- Enhance audience targeting precision
|
||||
|
||||
2. ENGAGEMENT OPTIMIZATION:
|
||||
- Strengthen community building strategies
|
||||
- Enhance social sharing potential
|
||||
- Improve audience interaction tactics
|
||||
- Optimize content for viral potential
|
||||
|
||||
3. CONTENT FORMAT OPTIMIZATION:
|
||||
- Optimize for Facebook's content formats
|
||||
- Enhance visual content strategies
|
||||
- Improve video content optimization
|
||||
- Optimize for Facebook Stories and Reels
|
||||
|
||||
4. AUDIENCE TARGETING OPTIMIZATION:
|
||||
- Refine demographic targeting
|
||||
- Enhance interest-based targeting
|
||||
- Improve behavioral targeting
|
||||
- Optimize for Facebook's audience insights
|
||||
|
||||
5. COMMUNITY BUILDING OPTIMIZATION:
|
||||
- Enhance group management strategies
|
||||
- Improve event management tactics
|
||||
- Optimize live streaming strategies
|
||||
- Enhance community interaction methods
|
||||
|
||||
Generate optimized Facebook persona data with enhanced algorithm performance, engagement strategies, and community building tactics."""
|
||||
239
backend/services/persona/facebook/facebook_persona_scheduler.py
Normal file
239
backend/services/persona/facebook/facebook_persona_scheduler.py
Normal file
@@ -0,0 +1,239 @@
|
||||
"""
|
||||
Facebook Persona Scheduler
|
||||
Handles scheduled generation of Facebook personas after onboarding.
|
||||
"""
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Dict, Any
|
||||
from loguru import logger
|
||||
|
||||
from services.database import get_db_session
|
||||
from services.persona_data_service import PersonaDataService
|
||||
from services.persona.facebook.facebook_persona_service import FacebookPersonaService
|
||||
from services.onboarding.database_service import OnboardingDatabaseService
|
||||
from models.scheduler_models import SchedulerEventLog
|
||||
|
||||
|
||||
async def generate_facebook_persona_task(user_id: str):
|
||||
"""
|
||||
Async task function to generate Facebook persona for a user.
|
||||
|
||||
This function is called by the scheduler 20 minutes after onboarding completion.
|
||||
|
||||
Args:
|
||||
user_id: User ID (Clerk string)
|
||||
"""
|
||||
db = None
|
||||
try:
|
||||
logger.info(f"Scheduled Facebook persona generation started for user {user_id}")
|
||||
|
||||
db = get_db_session()
|
||||
if not db:
|
||||
logger.error(f"Failed to get database session for Facebook persona generation (user: {user_id})")
|
||||
return
|
||||
|
||||
# Get persona data service
|
||||
persona_data_service = PersonaDataService(db_session=db)
|
||||
onboarding_service = OnboardingDatabaseService(db=db)
|
||||
|
||||
# Get core persona (required for Facebook persona)
|
||||
persona_data = persona_data_service.get_user_persona_data(user_id)
|
||||
if not persona_data or not persona_data.get('core_persona'):
|
||||
logger.warning(f"No core persona found for user {user_id}, cannot generate Facebook persona")
|
||||
return
|
||||
|
||||
core_persona = persona_data.get('core_persona', {})
|
||||
|
||||
# Get onboarding data for context
|
||||
website_analysis = onboarding_service.get_website_analysis(user_id, db)
|
||||
research_prefs = onboarding_service.get_research_preferences(user_id, db)
|
||||
|
||||
onboarding_data = {
|
||||
"website_url": website_analysis.get('website_url', '') if website_analysis else '',
|
||||
"writing_style": website_analysis.get('writing_style', {}) if website_analysis else {},
|
||||
"content_characteristics": website_analysis.get('content_characteristics', {}) if website_analysis else {},
|
||||
"target_audience": website_analysis.get('target_audience', '') if website_analysis else '',
|
||||
"research_preferences": research_prefs or {}
|
||||
}
|
||||
|
||||
# Check if persona already exists to avoid unnecessary API calls
|
||||
platform_personas = persona_data.get('platform_personas', {}) if persona_data else {}
|
||||
if platform_personas.get('facebook'):
|
||||
logger.info(f"Facebook persona already exists for user {user_id}, skipping generation")
|
||||
return
|
||||
|
||||
start_time = datetime.utcnow()
|
||||
# Generate Facebook persona
|
||||
facebook_service = FacebookPersonaService()
|
||||
try:
|
||||
generated_persona = facebook_service.generate_facebook_persona(
|
||||
core_persona,
|
||||
onboarding_data
|
||||
)
|
||||
execution_time = (datetime.utcnow() - start_time).total_seconds()
|
||||
|
||||
if generated_persona and "error" not in generated_persona:
|
||||
# Save to database
|
||||
success = persona_data_service.save_platform_persona(user_id, 'facebook', generated_persona)
|
||||
if success:
|
||||
logger.info(f"✅ Scheduled Facebook persona generation completed for user {user_id}")
|
||||
|
||||
# Log success to scheduler event log for dashboard
|
||||
try:
|
||||
event_log = SchedulerEventLog(
|
||||
event_type='job_completed',
|
||||
event_date=start_time,
|
||||
job_id=f"facebook_persona_{user_id}",
|
||||
job_type='one_time',
|
||||
user_id=user_id,
|
||||
event_data={
|
||||
'job_function': 'generate_facebook_persona_task',
|
||||
'execution_time_seconds': execution_time,
|
||||
'status': 'success'
|
||||
}
|
||||
)
|
||||
db.add(event_log)
|
||||
db.commit()
|
||||
except Exception as log_error:
|
||||
logger.warning(f"Failed to log Facebook persona generation success to scheduler event log: {log_error}")
|
||||
if db:
|
||||
db.rollback()
|
||||
else:
|
||||
error_msg = f"Failed to save Facebook persona for user {user_id}"
|
||||
logger.warning(f"⚠️ {error_msg}")
|
||||
|
||||
# Log failure to scheduler event log
|
||||
try:
|
||||
event_log = SchedulerEventLog(
|
||||
event_type='job_failed',
|
||||
event_date=start_time,
|
||||
job_id=f"facebook_persona_{user_id}",
|
||||
job_type='one_time',
|
||||
user_id=user_id,
|
||||
error_message=error_msg,
|
||||
event_data={
|
||||
'job_function': 'generate_facebook_persona_task',
|
||||
'execution_time_seconds': execution_time,
|
||||
'status': 'failed',
|
||||
'failure_reason': 'save_failed',
|
||||
'expensive_api_call': True
|
||||
}
|
||||
)
|
||||
db.add(event_log)
|
||||
db.commit()
|
||||
except Exception as log_error:
|
||||
logger.warning(f"Failed to log Facebook persona save failure to scheduler event log: {log_error}")
|
||||
if db:
|
||||
db.rollback()
|
||||
else:
|
||||
error_msg = f"Scheduled Facebook persona generation failed for user {user_id}: {generated_persona}"
|
||||
logger.error(f"❌ {error_msg}")
|
||||
|
||||
# Log failure to scheduler event log for dashboard visibility
|
||||
try:
|
||||
event_log = SchedulerEventLog(
|
||||
event_type='job_failed',
|
||||
event_date=start_time,
|
||||
job_id=f"facebook_persona_{user_id}", # Match scheduled job ID format
|
||||
job_type='one_time',
|
||||
user_id=user_id,
|
||||
error_message=error_msg,
|
||||
event_data={
|
||||
'job_function': 'generate_facebook_persona_task',
|
||||
'execution_time_seconds': execution_time,
|
||||
'status': 'failed',
|
||||
'failure_reason': 'generation_returned_error',
|
||||
'expensive_api_call': True
|
||||
}
|
||||
)
|
||||
db.add(event_log)
|
||||
db.commit()
|
||||
except Exception as log_error:
|
||||
logger.warning(f"Failed to log Facebook persona generation failure to scheduler event log: {log_error}")
|
||||
if db:
|
||||
db.rollback()
|
||||
except Exception as gen_error:
|
||||
execution_time = (datetime.utcnow() - start_time).total_seconds()
|
||||
error_msg = f"Exception during scheduled Facebook persona generation for user {user_id}: {str(gen_error)}. Expensive API call may have been made."
|
||||
logger.error(f"❌ {error_msg}")
|
||||
|
||||
# Log exception to scheduler event log for dashboard visibility
|
||||
try:
|
||||
event_log = SchedulerEventLog(
|
||||
event_type='job_failed',
|
||||
event_date=start_time,
|
||||
job_id=f"facebook_persona_{user_id}", # Match scheduled job ID format
|
||||
job_type='one_time',
|
||||
user_id=user_id,
|
||||
error_message=error_msg,
|
||||
event_data={
|
||||
'job_function': 'generate_facebook_persona_task',
|
||||
'execution_time_seconds': execution_time,
|
||||
'status': 'failed',
|
||||
'failure_reason': 'exception',
|
||||
'exception_type': type(gen_error).__name__,
|
||||
'exception_message': str(gen_error),
|
||||
'expensive_api_call': True
|
||||
}
|
||||
)
|
||||
db.add(event_log)
|
||||
db.commit()
|
||||
except Exception as log_error:
|
||||
logger.warning(f"Failed to log Facebook persona generation exception to scheduler event log: {log_error}")
|
||||
if db:
|
||||
db.rollback()
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in scheduled Facebook persona generation for user {user_id}: {e}")
|
||||
finally:
|
||||
if db:
|
||||
try:
|
||||
db.close()
|
||||
except Exception as e:
|
||||
logger.error(f"Error closing database session: {e}")
|
||||
|
||||
|
||||
def schedule_facebook_persona_generation(user_id: str, delay_minutes: int = 20) -> str:
|
||||
"""
|
||||
Schedule Facebook persona generation for a user after a delay.
|
||||
|
||||
Args:
|
||||
user_id: User ID (Clerk string)
|
||||
delay_minutes: Delay in minutes before generating persona (default: 20)
|
||||
|
||||
Returns:
|
||||
Job ID
|
||||
"""
|
||||
try:
|
||||
from services.scheduler import get_scheduler
|
||||
|
||||
scheduler = get_scheduler()
|
||||
|
||||
# Calculate run date (current time + delay) - ensure UTC timezone-aware
|
||||
run_date = datetime.now(timezone.utc) + timedelta(minutes=delay_minutes)
|
||||
|
||||
# Generate consistent job ID (without timestamp) for proper restoration
|
||||
# This allows restoration to find and restore the job with original scheduled time
|
||||
# Note: Clerk user_id already includes "user_" prefix, so we don't add it again
|
||||
job_id = f"facebook_persona_{user_id}"
|
||||
|
||||
# Schedule the task
|
||||
scheduled_job_id = scheduler.schedule_one_time_task(
|
||||
func=generate_facebook_persona_task,
|
||||
run_date=run_date,
|
||||
job_id=job_id,
|
||||
kwargs={"user_id": user_id},
|
||||
replace_existing=True
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Scheduled Facebook persona generation for user {user_id} "
|
||||
f"at {run_date} (job_id: {scheduled_job_id})"
|
||||
)
|
||||
|
||||
return scheduled_job_id
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to schedule Facebook persona generation for user {user_id}: {e}")
|
||||
raise
|
||||
|
||||
364
backend/services/persona/facebook/facebook_persona_schemas.py
Normal file
364
backend/services/persona/facebook/facebook_persona_schemas.py
Normal file
@@ -0,0 +1,364 @@
|
||||
"""
|
||||
Facebook Persona Schemas
|
||||
Defines Facebook-specific persona data structures and validation schemas.
|
||||
"""
|
||||
|
||||
from typing import Dict, Any, List, Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class FacebookPersonaSchema(BaseModel):
|
||||
"""Facebook-specific persona schema with platform optimizations."""
|
||||
|
||||
# Core persona fields (inherited from base persona)
|
||||
persona_name: str = Field(..., description="Name of the persona")
|
||||
archetype: str = Field(..., description="Persona archetype")
|
||||
core_belief: str = Field(..., description="Core belief driving the persona")
|
||||
|
||||
# Facebook-specific optimizations
|
||||
facebook_algorithm_optimization: Dict[str, Any] = Field(
|
||||
default_factory=dict,
|
||||
description="Facebook algorithm optimization strategies"
|
||||
)
|
||||
|
||||
facebook_engagement_strategies: Dict[str, Any] = Field(
|
||||
default_factory=dict,
|
||||
description="Facebook-specific engagement strategies"
|
||||
)
|
||||
|
||||
facebook_content_formats: Dict[str, Any] = Field(
|
||||
default_factory=dict,
|
||||
description="Facebook content format optimizations"
|
||||
)
|
||||
|
||||
facebook_audience_targeting: Dict[str, Any] = Field(
|
||||
default_factory=dict,
|
||||
description="Facebook audience targeting strategies"
|
||||
)
|
||||
|
||||
facebook_community_building: Dict[str, Any] = Field(
|
||||
default_factory=dict,
|
||||
description="Facebook community building strategies"
|
||||
)
|
||||
|
||||
|
||||
class FacebookPersonaConstraints:
|
||||
"""Facebook platform constraints and best practices."""
|
||||
|
||||
@staticmethod
|
||||
def get_facebook_constraints() -> Dict[str, Any]:
|
||||
"""Get Facebook-specific platform constraints."""
|
||||
return {
|
||||
"character_limit": 63206,
|
||||
"optimal_length": "40-80 words",
|
||||
"hashtag_limit": 30,
|
||||
"image_support": True,
|
||||
"video_support": True,
|
||||
"link_preview": True,
|
||||
"event_support": True,
|
||||
"group_sharing": True,
|
||||
"story_support": True,
|
||||
"reel_support": True,
|
||||
"carousel_support": True,
|
||||
"poll_support": True,
|
||||
"live_support": True,
|
||||
"algorithm_favors": [
|
||||
"engagement",
|
||||
"meaningful_interactions",
|
||||
"video_content",
|
||||
"community_posts",
|
||||
"authentic_content"
|
||||
],
|
||||
"content_types": [
|
||||
"text_posts",
|
||||
"image_posts",
|
||||
"video_posts",
|
||||
"carousel_posts",
|
||||
"story_posts",
|
||||
"reel_posts",
|
||||
"event_posts",
|
||||
"poll_posts",
|
||||
"live_posts"
|
||||
],
|
||||
"engagement_metrics": [
|
||||
"likes",
|
||||
"comments",
|
||||
"shares",
|
||||
"saves",
|
||||
"clicks",
|
||||
"reactions",
|
||||
"video_views",
|
||||
"story_views"
|
||||
],
|
||||
"posting_frequency": {
|
||||
"optimal": "1-2 times per day",
|
||||
"maximum": "3-4 times per day",
|
||||
"minimum": "3-4 times per week"
|
||||
},
|
||||
"best_posting_times": [
|
||||
"9:00 AM - 11:00 AM",
|
||||
"1:00 PM - 3:00 PM",
|
||||
"5:00 PM - 7:00 PM"
|
||||
],
|
||||
"content_guidelines": {
|
||||
"authenticity": "High priority - Facebook favors authentic content",
|
||||
"community_focus": "Build community and meaningful connections",
|
||||
"visual_content": "Images and videos perform better than text-only",
|
||||
"engagement_bait": "Avoid engagement bait - Facebook penalizes it",
|
||||
"clickbait": "Avoid clickbait headlines and misleading content"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class FacebookPersonaValidation:
|
||||
"""Facebook persona validation rules and scoring."""
|
||||
|
||||
@staticmethod
|
||||
def validate_facebook_persona(persona_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Validate Facebook persona data for completeness and quality."""
|
||||
|
||||
validation_results = {
|
||||
"is_valid": True,
|
||||
"quality_score": 0.0,
|
||||
"completeness_score": 0.0,
|
||||
"facebook_optimization_score": 0.0,
|
||||
"engagement_strategy_score": 0.0,
|
||||
"missing_fields": [],
|
||||
"incomplete_fields": [],
|
||||
"recommendations": [],
|
||||
"quality_issues": [],
|
||||
"strengths": [],
|
||||
"validation_details": {}
|
||||
}
|
||||
|
||||
# Check required fields
|
||||
required_fields = [
|
||||
"persona_name", "archetype", "core_belief",
|
||||
"facebook_algorithm_optimization", "facebook_engagement_strategies"
|
||||
]
|
||||
|
||||
for field in required_fields:
|
||||
if not persona_data.get(field):
|
||||
validation_results["missing_fields"].append(field)
|
||||
validation_results["is_valid"] = False
|
||||
|
||||
# Calculate completeness score
|
||||
total_fields = len(required_fields)
|
||||
present_fields = total_fields - len(validation_results["missing_fields"])
|
||||
validation_results["completeness_score"] = (present_fields / total_fields) * 100
|
||||
|
||||
# Validate Facebook-specific optimizations
|
||||
facebook_opt = persona_data.get("facebook_algorithm_optimization", {})
|
||||
if facebook_opt:
|
||||
validation_results["facebook_optimization_score"] = 85.0
|
||||
validation_results["strengths"].append("Facebook algorithm optimization present")
|
||||
else:
|
||||
validation_results["quality_issues"].append("Missing Facebook algorithm optimization")
|
||||
validation_results["recommendations"].append("Add Facebook-specific algorithm strategies")
|
||||
|
||||
# Validate engagement strategies
|
||||
engagement_strategies = persona_data.get("facebook_engagement_strategies", {})
|
||||
if engagement_strategies:
|
||||
validation_results["engagement_strategy_score"] = 80.0
|
||||
validation_results["strengths"].append("Facebook engagement strategies defined")
|
||||
else:
|
||||
validation_results["quality_issues"].append("Missing Facebook engagement strategies")
|
||||
validation_results["recommendations"].append("Define Facebook-specific engagement tactics")
|
||||
|
||||
# Calculate overall quality score
|
||||
validation_results["quality_score"] = (
|
||||
validation_results["completeness_score"] * 0.4 +
|
||||
validation_results["facebook_optimization_score"] * 0.3 +
|
||||
validation_results["engagement_strategy_score"] * 0.3
|
||||
)
|
||||
|
||||
# Add validation details
|
||||
validation_results["validation_details"] = {
|
||||
"total_fields_checked": total_fields,
|
||||
"present_fields": present_fields,
|
||||
"facebook_optimization_present": bool(facebook_opt),
|
||||
"engagement_strategies_present": bool(engagement_strategies),
|
||||
"validation_timestamp": "2024-01-01T00:00:00Z" # Will be updated with actual timestamp
|
||||
}
|
||||
|
||||
return validation_results
|
||||
|
||||
|
||||
class FacebookPersonaOptimization:
|
||||
"""Facebook persona optimization strategies and techniques."""
|
||||
|
||||
@staticmethod
|
||||
def get_facebook_optimization_strategies() -> Dict[str, Any]:
|
||||
"""Get comprehensive Facebook optimization strategies."""
|
||||
return {
|
||||
"algorithm_optimization": {
|
||||
"engagement_optimization": [
|
||||
"Post when your audience is most active",
|
||||
"Use Facebook's native video uploads instead of external links",
|
||||
"Encourage meaningful comments and discussions",
|
||||
"Respond to comments within 2 hours",
|
||||
"Use Facebook Live for real-time engagement",
|
||||
"Create shareable, valuable content",
|
||||
"Use Facebook Stories for behind-the-scenes content",
|
||||
"Leverage Facebook Groups for community building"
|
||||
],
|
||||
"content_quality_optimization": [
|
||||
"Create authentic, original content",
|
||||
"Use high-quality images and videos",
|
||||
"Write compelling captions that encourage engagement",
|
||||
"Use Facebook's built-in editing tools",
|
||||
"Create content that sparks conversations",
|
||||
"Share user-generated content",
|
||||
"Use Facebook's trending topics and hashtags",
|
||||
"Create content that provides value to your audience"
|
||||
],
|
||||
"timing_optimization": [
|
||||
"Post during peak engagement hours (9-11 AM, 1-3 PM, 5-7 PM)",
|
||||
"Use Facebook Insights to find your best posting times",
|
||||
"Post consistently but not too frequently",
|
||||
"Schedule posts for different time zones if global audience",
|
||||
"Use Facebook's scheduling feature for optimal timing",
|
||||
"Post when your competitors are less active",
|
||||
"Consider your audience's daily routines and habits"
|
||||
],
|
||||
"audience_targeting_optimization": [
|
||||
"Use Facebook's audience insights for targeting",
|
||||
"Create content for specific audience segments",
|
||||
"Use Facebook's lookalike audiences",
|
||||
"Target based on interests and behaviors",
|
||||
"Use Facebook's custom audiences",
|
||||
"Create content that resonates with your core audience",
|
||||
"Use Facebook's demographic targeting",
|
||||
"Leverage Facebook's psychographic targeting"
|
||||
]
|
||||
},
|
||||
"engagement_strategies": {
|
||||
"community_building": [
|
||||
"Create and moderate Facebook Groups",
|
||||
"Host Facebook Live sessions regularly",
|
||||
"Respond to all comments and messages",
|
||||
"Share user-generated content",
|
||||
"Create Facebook Events for community gatherings",
|
||||
"Use Facebook's community features",
|
||||
"Encourage user participation and feedback",
|
||||
"Build relationships with your audience"
|
||||
],
|
||||
"content_engagement": [
|
||||
"Ask questions in your posts",
|
||||
"Use polls and surveys to engage audience",
|
||||
"Create interactive content like quizzes",
|
||||
"Use Facebook's reaction buttons strategically",
|
||||
"Create content that encourages sharing",
|
||||
"Use Facebook's tagging feature appropriately",
|
||||
"Create content that sparks discussions",
|
||||
"Use Facebook's story features for engagement"
|
||||
],
|
||||
"conversion_optimization": [
|
||||
"Use clear call-to-actions in posts",
|
||||
"Create Facebook-specific landing pages",
|
||||
"Use Facebook's conversion tracking",
|
||||
"Create content that drives traffic to your website",
|
||||
"Use Facebook's lead generation features",
|
||||
"Create content that builds trust and credibility",
|
||||
"Use Facebook's retargeting capabilities",
|
||||
"Create content that showcases your products/services"
|
||||
]
|
||||
},
|
||||
"content_formats": {
|
||||
"text_posts": {
|
||||
"optimal_length": "40-80 words",
|
||||
"best_practices": [
|
||||
"Use compelling headlines",
|
||||
"Include relevant hashtags (1-2)",
|
||||
"Ask questions to encourage engagement",
|
||||
"Use emojis sparingly but effectively",
|
||||
"Include clear call-to-actions"
|
||||
]
|
||||
},
|
||||
"image_posts": {
|
||||
"optimal_specs": "1200x630 pixels",
|
||||
"best_practices": [
|
||||
"Use high-quality, original images",
|
||||
"Include text overlay for key messages",
|
||||
"Use consistent branding and colors",
|
||||
"Create visually appealing graphics",
|
||||
"Use Facebook's image editing tools"
|
||||
]
|
||||
},
|
||||
"video_posts": {
|
||||
"optimal_length": "15-60 seconds for feed, 2-3 minutes for longer content",
|
||||
"best_practices": [
|
||||
"Upload videos directly to Facebook",
|
||||
"Create engaging thumbnails",
|
||||
"Add captions for accessibility",
|
||||
"Use Facebook's video editing tools",
|
||||
"Create videos that work without sound"
|
||||
]
|
||||
},
|
||||
"carousel_posts": {
|
||||
"optimal_slides": "3-5 slides",
|
||||
"best_practices": [
|
||||
"Tell a story across slides",
|
||||
"Use consistent design elements",
|
||||
"Include clear navigation",
|
||||
"Create slides that work individually",
|
||||
"Use carousels for product showcases"
|
||||
]
|
||||
}
|
||||
},
|
||||
"audience_targeting": {
|
||||
"demographic_targeting": [
|
||||
"Age and gender targeting",
|
||||
"Location-based targeting",
|
||||
"Education and work targeting",
|
||||
"Relationship status targeting",
|
||||
"Language targeting"
|
||||
],
|
||||
"interest_targeting": [
|
||||
"Hobbies and interests",
|
||||
"Brand and product interests",
|
||||
"Entertainment preferences",
|
||||
"Lifestyle and behavior targeting",
|
||||
"Purchase behavior targeting"
|
||||
],
|
||||
"behavioral_targeting": [
|
||||
"Device usage patterns",
|
||||
"Travel behavior",
|
||||
"Purchase behavior",
|
||||
"Digital activity patterns",
|
||||
"Life events targeting"
|
||||
]
|
||||
},
|
||||
"community_building": {
|
||||
"group_management": [
|
||||
"Create and moderate relevant Facebook Groups",
|
||||
"Set clear group rules and guidelines",
|
||||
"Encourage member participation",
|
||||
"Share valuable content in groups",
|
||||
"Use groups for customer support",
|
||||
"Create group events and activities",
|
||||
"Recognize and reward active members",
|
||||
"Use groups for market research"
|
||||
],
|
||||
"event_management": [
|
||||
"Create Facebook Events for promotions",
|
||||
"Use events for product launches",
|
||||
"Host virtual events and webinars",
|
||||
"Create recurring events for consistency",
|
||||
"Use events for community building",
|
||||
"Promote events across all channels",
|
||||
"Follow up with event attendees",
|
||||
"Use events for lead generation"
|
||||
],
|
||||
"live_streaming": [
|
||||
"Host regular Facebook Live sessions",
|
||||
"Use live streaming for Q&A sessions",
|
||||
"Create behind-the-scenes content",
|
||||
"Use live streaming for product demos",
|
||||
"Engage with viewers in real-time",
|
||||
"Use live streaming for announcements",
|
||||
"Create interactive live content",
|
||||
"Use live streaming for customer support"
|
||||
]
|
||||
}
|
||||
}
|
||||
449
backend/services/persona/facebook/facebook_persona_service.py
Normal file
449
backend/services/persona/facebook/facebook_persona_service.py
Normal file
@@ -0,0 +1,449 @@
|
||||
"""
|
||||
Facebook Persona Service
|
||||
Encapsulates Facebook-specific persona generation logic.
|
||||
"""
|
||||
|
||||
from typing import Dict, Any, Optional
|
||||
from loguru import logger
|
||||
from datetime import datetime
|
||||
|
||||
from .facebook_persona_schemas import (
|
||||
FacebookPersonaSchema,
|
||||
FacebookPersonaConstraints,
|
||||
FacebookPersonaValidation,
|
||||
FacebookPersonaOptimization
|
||||
)
|
||||
from .facebook_persona_prompts import FacebookPersonaPrompts
|
||||
from services.llm_providers.gemini_provider import gemini_structured_json_response
|
||||
|
||||
|
||||
class FacebookPersonaService:
|
||||
"""Facebook-specific persona generation and optimization service."""
|
||||
|
||||
_instance = None
|
||||
_initialized = False
|
||||
|
||||
def __new__(cls):
|
||||
"""Implement singleton pattern to prevent multiple initializations."""
|
||||
if cls._instance is None:
|
||||
cls._instance = super(FacebookPersonaService, cls).__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize the Facebook persona service (only once)."""
|
||||
if not self._initialized:
|
||||
self.schemas = FacebookPersonaSchema
|
||||
self.constraints = FacebookPersonaConstraints()
|
||||
self.validation = FacebookPersonaValidation()
|
||||
self.optimization = FacebookPersonaOptimization()
|
||||
self.prompts = FacebookPersonaPrompts()
|
||||
logger.debug("FacebookPersonaService initialized")
|
||||
self._initialized = True
|
||||
|
||||
def generate_facebook_persona(self, core_persona: Dict[str, Any], onboarding_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Generate Facebook-specific persona adaptation using optimized chained prompts.
|
||||
|
||||
Args:
|
||||
core_persona: The core persona data
|
||||
onboarding_data: User onboarding data
|
||||
|
||||
Returns:
|
||||
Facebook-optimized persona data
|
||||
"""
|
||||
try:
|
||||
logger.info("Generating Facebook-specific persona with optimized prompts")
|
||||
|
||||
# Build focused Facebook prompt (without core persona JSON)
|
||||
prompt = self.prompts.build_focused_facebook_prompt(onboarding_data)
|
||||
|
||||
# Create system prompt with core persona
|
||||
system_prompt = self.prompts.build_facebook_system_prompt(core_persona)
|
||||
|
||||
# Get Facebook-specific schema
|
||||
schema = self._get_enhanced_facebook_schema()
|
||||
|
||||
# Generate structured response using Gemini with optimized prompts
|
||||
response = gemini_structured_json_response(
|
||||
prompt=prompt,
|
||||
schema=schema,
|
||||
temperature=0.2,
|
||||
max_tokens=4096,
|
||||
system_prompt=system_prompt
|
||||
)
|
||||
|
||||
if not response or "error" in response:
|
||||
logger.error(f"Failed to generate Facebook persona: {response}")
|
||||
return {"error": f"Failed to generate Facebook persona: {response}"}
|
||||
|
||||
# Validate the generated persona
|
||||
validation_results = self.validate_facebook_persona(response)
|
||||
|
||||
# Apply algorithm optimization
|
||||
optimized_persona = self.optimize_for_facebook_algorithm(response)
|
||||
|
||||
# Add validation results to the persona
|
||||
optimized_persona["validation_results"] = validation_results
|
||||
|
||||
logger.info(f"✅ Facebook persona generated successfully with {validation_results['quality_score']:.1f}% quality score")
|
||||
|
||||
return optimized_persona
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error generating Facebook persona: {str(e)}")
|
||||
return {"error": f"Failed to generate Facebook persona: {str(e)}"}
|
||||
|
||||
def get_facebook_constraints(self) -> Dict[str, Any]:
|
||||
"""Get Facebook-specific platform constraints."""
|
||||
return self.constraints.get_facebook_constraints()
|
||||
|
||||
def validate_facebook_persona(self, persona_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Validate Facebook persona data for completeness and quality.
|
||||
|
||||
Args:
|
||||
persona_data: Facebook persona data to validate
|
||||
|
||||
Returns:
|
||||
Validation results with scores and recommendations
|
||||
"""
|
||||
try:
|
||||
logger.info("Validating Facebook persona data")
|
||||
|
||||
# Use the validation class
|
||||
validation_results = self.validation.validate_facebook_persona(persona_data)
|
||||
|
||||
# Initialize missing fields if they don't exist
|
||||
if "content_format_score" not in validation_results:
|
||||
validation_results["content_format_score"] = 0.0
|
||||
if "audience_targeting_score" not in validation_results:
|
||||
validation_results["audience_targeting_score"] = 0.0
|
||||
if "community_building_score" not in validation_results:
|
||||
validation_results["community_building_score"] = 0.0
|
||||
|
||||
# Add Facebook-specific validation
|
||||
facebook_opt = persona_data.get("facebook_algorithm_optimization", {})
|
||||
if facebook_opt:
|
||||
validation_results["facebook_optimization_score"] = 90.0
|
||||
validation_results["strengths"].append("Facebook algorithm optimization present")
|
||||
else:
|
||||
validation_results["quality_issues"].append("Missing Facebook algorithm optimization")
|
||||
validation_results["recommendations"].append("Add Facebook-specific algorithm strategies")
|
||||
|
||||
# Validate engagement strategies
|
||||
engagement_strategies = persona_data.get("facebook_engagement_strategies", {})
|
||||
if engagement_strategies:
|
||||
validation_results["engagement_strategy_score"] = 85.0
|
||||
validation_results["strengths"].append("Facebook engagement strategies defined")
|
||||
else:
|
||||
validation_results["quality_issues"].append("Missing Facebook engagement strategies")
|
||||
validation_results["recommendations"].append("Define Facebook-specific engagement tactics")
|
||||
|
||||
# Validate content formats
|
||||
content_formats = persona_data.get("facebook_content_formats", {})
|
||||
if content_formats:
|
||||
validation_results["content_format_score"] = 80.0
|
||||
validation_results["strengths"].append("Facebook content formats optimized")
|
||||
else:
|
||||
validation_results["quality_issues"].append("Missing Facebook content format optimization")
|
||||
validation_results["recommendations"].append("Add Facebook-specific content format strategies")
|
||||
|
||||
# Validate audience targeting
|
||||
audience_targeting = persona_data.get("facebook_audience_targeting", {})
|
||||
if audience_targeting:
|
||||
validation_results["audience_targeting_score"] = 75.0
|
||||
validation_results["strengths"].append("Facebook audience targeting strategies present")
|
||||
else:
|
||||
validation_results["quality_issues"].append("Missing Facebook audience targeting")
|
||||
validation_results["recommendations"].append("Add Facebook-specific audience targeting strategies")
|
||||
|
||||
# Validate community building
|
||||
community_building = persona_data.get("facebook_community_building", {})
|
||||
if community_building:
|
||||
validation_results["community_building_score"] = 85.0
|
||||
validation_results["strengths"].append("Facebook community building strategies defined")
|
||||
else:
|
||||
validation_results["quality_issues"].append("Missing Facebook community building strategies")
|
||||
validation_results["recommendations"].append("Add Facebook-specific community building tactics")
|
||||
|
||||
# Recalculate overall quality score
|
||||
validation_results["quality_score"] = (
|
||||
validation_results["completeness_score"] * 0.2 +
|
||||
validation_results["facebook_optimization_score"] * 0.25 +
|
||||
validation_results["engagement_strategy_score"] * 0.2 +
|
||||
validation_results["content_format_score"] * 0.15 +
|
||||
validation_results["audience_targeting_score"] * 0.1 +
|
||||
validation_results["community_building_score"] * 0.1
|
||||
)
|
||||
|
||||
# Add validation timestamp
|
||||
validation_results["validation_timestamp"] = datetime.utcnow().isoformat()
|
||||
|
||||
logger.info(f"Facebook persona validation completed: Quality Score: {validation_results['quality_score']:.1f}%")
|
||||
|
||||
return validation_results
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error validating Facebook persona: {str(e)}")
|
||||
return {
|
||||
"is_valid": False,
|
||||
"quality_score": 0.0,
|
||||
"error": f"Validation failed: {str(e)}"
|
||||
}
|
||||
|
||||
def optimize_for_facebook_algorithm(self, persona_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Optimize Facebook persona data for maximum algorithm performance.
|
||||
|
||||
Args:
|
||||
persona_data: Facebook persona data to optimize
|
||||
|
||||
Returns:
|
||||
Optimized Facebook persona data
|
||||
"""
|
||||
try:
|
||||
logger.info("Optimizing Facebook persona for algorithm performance")
|
||||
|
||||
# Get optimization strategies
|
||||
optimization_strategies = self.optimization.get_facebook_optimization_strategies()
|
||||
|
||||
# Apply algorithm optimization
|
||||
optimized_persona = persona_data.copy()
|
||||
|
||||
# Add comprehensive algorithm optimization
|
||||
optimized_persona["algorithm_optimization"] = {
|
||||
"engagement_optimization": optimization_strategies["algorithm_optimization"]["engagement_optimization"],
|
||||
"content_quality_optimization": optimization_strategies["algorithm_optimization"]["content_quality_optimization"],
|
||||
"timing_optimization": optimization_strategies["algorithm_optimization"]["timing_optimization"],
|
||||
"audience_targeting_optimization": optimization_strategies["algorithm_optimization"]["audience_targeting_optimization"]
|
||||
}
|
||||
|
||||
# Add engagement strategies
|
||||
optimized_persona["engagement_strategies"] = {
|
||||
"community_building": optimization_strategies["engagement_strategies"]["community_building"],
|
||||
"content_engagement": optimization_strategies["engagement_strategies"]["content_engagement"],
|
||||
"conversion_optimization": optimization_strategies["engagement_strategies"]["conversion_optimization"]
|
||||
}
|
||||
|
||||
# Add content format optimization
|
||||
optimized_persona["content_formats"] = optimization_strategies["content_formats"]
|
||||
|
||||
# Add audience targeting optimization
|
||||
optimized_persona["audience_targeting"] = optimization_strategies["audience_targeting"]
|
||||
|
||||
# Add community building optimization
|
||||
optimized_persona["community_building"] = optimization_strategies["community_building"]
|
||||
|
||||
# Add optimization metadata
|
||||
total_strategies = 0
|
||||
for category_name, category_data in optimization_strategies.items():
|
||||
if isinstance(category_data, dict):
|
||||
for strategy_name, strategies in category_data.items():
|
||||
if isinstance(strategies, list):
|
||||
total_strategies += len(strategies)
|
||||
elif isinstance(strategies, dict):
|
||||
# Handle nested dictionaries
|
||||
for sub_strategy_name, sub_strategies in strategies.items():
|
||||
if isinstance(sub_strategies, list):
|
||||
total_strategies += len(sub_strategies)
|
||||
else:
|
||||
total_strategies += 1
|
||||
else:
|
||||
total_strategies += 1
|
||||
elif isinstance(category_data, list):
|
||||
total_strategies += len(category_data)
|
||||
else:
|
||||
total_strategies += 1
|
||||
|
||||
optimized_persona["optimization_metadata"] = {
|
||||
"optimization_applied": True,
|
||||
"optimization_timestamp": datetime.utcnow().isoformat(),
|
||||
"optimization_categories": list(optimization_strategies.keys()),
|
||||
"total_optimization_strategies": total_strategies
|
||||
}
|
||||
|
||||
logger.info("✅ Facebook persona algorithm optimization completed successfully")
|
||||
|
||||
return optimized_persona
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error optimizing Facebook persona: {str(e)}")
|
||||
return persona_data # Return original data if optimization fails
|
||||
|
||||
def _get_enhanced_facebook_schema(self) -> Dict[str, Any]:
|
||||
"""Get enhanced Facebook persona schema for Gemini structured response with improved JSON parsing reliability."""
|
||||
return {
|
||||
"type": "object",
|
||||
"description": "Facebook-optimized persona data structure for community engagement and algorithm optimization",
|
||||
"properties": {
|
||||
"persona_name": {
|
||||
"type": "string",
|
||||
"description": "Name of the Facebook-optimized persona (e.g., 'Community Builder', 'Social Connector')",
|
||||
"minLength": 3,
|
||||
"maxLength": 50
|
||||
},
|
||||
"archetype": {
|
||||
"type": "string",
|
||||
"description": "Persona archetype for Facebook (e.g., 'The Community Catalyst', 'The Social Storyteller')",
|
||||
"minLength": 5,
|
||||
"maxLength": 50
|
||||
},
|
||||
"core_belief": {
|
||||
"type": "string",
|
||||
"description": "Core belief driving the Facebook persona (e.g., 'Building authentic connections through shared experiences')",
|
||||
"minLength": 10,
|
||||
"maxLength": 200
|
||||
},
|
||||
"facebook_algorithm_optimization": {
|
||||
"type": "object",
|
||||
"description": "Facebook algorithm optimization strategies",
|
||||
"properties": {
|
||||
"engagement_optimization": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Strategies for optimizing Facebook engagement (3-8 strategies)",
|
||||
"minItems": 3,
|
||||
"maxItems": 8
|
||||
},
|
||||
"content_quality_optimization": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Strategies for optimizing content quality on Facebook (3-8 strategies)",
|
||||
"minItems": 3,
|
||||
"maxItems": 8
|
||||
},
|
||||
"timing_optimization": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Strategies for optimizing posting timing on Facebook (3-8 strategies)",
|
||||
"minItems": 3,
|
||||
"maxItems": 8
|
||||
},
|
||||
"audience_targeting_optimization": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Strategies for optimizing audience targeting on Facebook (3-8 strategies)",
|
||||
"minItems": 3,
|
||||
"maxItems": 8
|
||||
}
|
||||
}
|
||||
},
|
||||
"facebook_engagement_strategies": {
|
||||
"type": "object",
|
||||
"description": "Facebook-specific engagement strategies",
|
||||
"properties": {
|
||||
"community_building": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Community building strategies for Facebook"
|
||||
},
|
||||
"content_engagement": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Content engagement strategies for Facebook"
|
||||
},
|
||||
"conversion_optimization": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Conversion optimization strategies for Facebook"
|
||||
}
|
||||
}
|
||||
},
|
||||
"facebook_content_formats": {
|
||||
"type": "object",
|
||||
"description": "Facebook content format optimizations",
|
||||
"properties": {
|
||||
"text_posts": {
|
||||
"type": "object",
|
||||
"description": "Text post optimization for Facebook",
|
||||
"properties": {
|
||||
"optimal_length": {"type": "string"},
|
||||
"structure_guidelines": {"type": "array", "items": {"type": "string"}},
|
||||
"hook_strategies": {"type": "array", "items": {"type": "string"}}
|
||||
}
|
||||
},
|
||||
"image_posts": {
|
||||
"type": "object",
|
||||
"description": "Image post optimization for Facebook",
|
||||
"properties": {
|
||||
"image_guidelines": {"type": "array", "items": {"type": "string"}},
|
||||
"caption_strategies": {"type": "array", "items": {"type": "string"}}
|
||||
}
|
||||
},
|
||||
"video_posts": {
|
||||
"type": "object",
|
||||
"description": "Video post optimization for Facebook",
|
||||
"properties": {
|
||||
"video_length_guidelines": {"type": "array", "items": {"type": "string"}},
|
||||
"engagement_hooks": {"type": "array", "items": {"type": "string"}}
|
||||
}
|
||||
},
|
||||
"carousel_posts": {
|
||||
"type": "object",
|
||||
"description": "Carousel post optimization for Facebook",
|
||||
"properties": {
|
||||
"slide_structure": {"type": "array", "items": {"type": "string"}},
|
||||
"storytelling_flow": {"type": "array", "items": {"type": "string"}}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"facebook_audience_targeting": {
|
||||
"type": "object",
|
||||
"description": "Facebook audience targeting strategies",
|
||||
"properties": {
|
||||
"demographic_targeting": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Demographic targeting strategies for Facebook"
|
||||
},
|
||||
"interest_targeting": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Interest targeting strategies for Facebook"
|
||||
},
|
||||
"behavioral_targeting": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Behavioral targeting strategies for Facebook"
|
||||
}
|
||||
}
|
||||
},
|
||||
"facebook_community_building": {
|
||||
"type": "object",
|
||||
"description": "Facebook community building strategies",
|
||||
"properties": {
|
||||
"group_management": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Facebook Group management strategies"
|
||||
},
|
||||
"event_management": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Facebook Event management strategies"
|
||||
},
|
||||
"live_streaming": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Facebook Live streaming strategies"
|
||||
}
|
||||
}
|
||||
},
|
||||
"confidence_score": {
|
||||
"type": "number",
|
||||
"description": "Confidence score for the Facebook persona (0-100)",
|
||||
"minimum": 0,
|
||||
"maximum": 100
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"persona_name",
|
||||
"archetype",
|
||||
"core_belief",
|
||||
"facebook_algorithm_optimization",
|
||||
"facebook_engagement_strategies",
|
||||
"confidence_score"
|
||||
],
|
||||
"additionalProperties": False
|
||||
}
|
||||
Reference in New Issue
Block a user