A Mastra template that generates compelling ad copy and promotional images from content provided as plain text, PDF links, or website URLs. Features AI-powered copywriting with web content extraction and image generation capabilities.
- Content Processing: Extract and analyze content from PDFs, plain text, or website URLs
- Web Content Extraction: Extract blog posts and articles from websites using AI-powered web browsing
- Ad Copy Generation: Create headlines, body copy, and CTAs for multiple platforms
- Image Generation: Generate promotional images using DALL-E 3 via the AI package
- Platform Optimization: Tailored content for Facebook, Instagram, Google Ads, LinkedIn, and more
- A/B Testing: Multiple variations for testing and optimization
-
Install dependencies:
pnpm install
-
Set up environment variables: Create a
.envfile with:OPENAI_API_KEY=your_openai_api_key # For web content extraction (optional - only needed for URL input type) BROWSERBASE_API_KEY=your_browserbase_api_key BROWSERBASE_PROJECT_ID=your_browserbase_project_id # For AWS S3 cloud storage (required for image generation) AWS_REGION=us-east-1 AWS_ACCESS_KEY_ID=your_aws_access_key_id AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key S3_BUCKET_NAME=mastra-generated-images S3_PUBLIC_URL_BASE=https://your-bucket-name.s3.amazonaws.com -
Run the application:
pnpm dev
import { mastra } from './src/mastra';
// Generate ad copy from text content
const result = await mastra.runWorkflow('ad-copy-generation-workflow', {
contentInput: 'Your product description or marketing content here...',
inputType: 'text',
platform: 'facebook',
campaignType: 'conversion',
targetAudience: 'Small business owners aged 25-45',
tone: 'professional',
generateImages: true,
imageStyle: 'modern',
});
// Generate ad copy from PDF
const pdfResult = await mastra.runWorkflow('ad-copy-generation-workflow', {
contentInput: 'https://example.com/product-brochure.pdf',
inputType: 'pdf',
platform: 'linkedin',
campaignType: 'awareness',
tone: 'authoritative',
});
// Generate ad copy from website URL
const urlResult = await mastra.runWorkflow('ad-copy-generation-workflow', {
contentInput: 'https://techcrunch.com/example-startup-article',
inputType: 'url',
platform: 'instagram',
campaignType: 'consideration',
targetAudience: 'Tech enthusiasts and early adopters',
tone: 'playful',
generateImages: true,
imageStyle: 'digital_art',
});// Generate ad copy directly
const adCopy = await mastra.getAgent('adCopyAgent').generate([
{
role: 'user',
content: 'Create Facebook ad copy for a new productivity app targeting remote workers',
},
]);
// Extract content from PDF
const pdfContent = await mastra.getTool('pdf-content-extractor').execute({
context: { pdfUrl: 'https://example.com/whitepaper.pdf' },
mastra,
});- Ad Copy Agent - Main agent that orchestrates the ad copy generation process
- Content Summarizer Agent - Creates marketing-focused summaries from content
- Copywriting Agent - Expert copywriter for creating high-converting ad copy
- Web Content Agent - Extracts content from websites and blog posts for ad copy generation
- PDF Content Extractor - Downloads and extracts marketing insights from PDFs
- Web Content Extractor - Extracts blog posts and articles from websites using AI-powered browsing
- Page Navigate Tool - Navigates to web URLs for content extraction
- Ad Copy Generator - Creates multiple ad copy variations for different platforms
- Image Generator - Generates promotional images using DALL-E 3
Ad Copy Generation Workflow: Simplified end-to-end process that:
- Extracts content (from PDF, website URL, or text)
- Generates optimized ad copy (headline, body, CTA)
- Creates a promotional image and uploads to S3
- Facebook/Instagram: Optimized for social media advertising
- Google Ads: Search-intent focused copy
- LinkedIn: Professional, B2B-oriented content
- Twitter: Concise, trending-aware copy
- TikTok: Engaging, video-focused copy
- Generic: Platform-agnostic advertising copy
- Awareness: Brand awareness and reach campaigns
- Consideration: Lead generation and engagement
- Conversion: Sales and action-driven campaigns
- Retention: Customer retention and loyalty
The workflow generates:
- Single optimized headline
- Compelling body copy
- Effective call-to-action
- One promotional image uploaded to S3
- Platform-optimized dimensions
- Style-consistent visual design
const result = await mastra.runWorkflow('ad-copy-generation-workflow', {
// ... input params
});
// Result structure:
{
adCopy: {
headline: "Your optimized headline",
body: "Compelling body copy for your ad",
cta: "Call to action"
},
imageUrl: "https://your-bucket.s3.amazonaws.com/generated-images/uuid.jpg" // Optional
}const result = await mastra.getTool('pdf-content-extractor').execute({
context: {
pdfUrl: 'https://example.com/content.pdf',
focusAreas: ['benefits', 'pricing', 'testimonials'],
},
mastra,
});To modify or extend this template:
- Add new platforms: Update the platform enums in the schemas
- Customize copy styles: Modify the copywriting agent instructions
- Add new image styles: Extend the image generation tool
- Create new workflows: Combine tools and agents in different ways
OPENAI_API_KEY: Required for AI generation (OpenAI GPT-4)
BROWSERBASE_API_KEY: Required for web content extraction (BrowserBase)BROWSERBASE_PROJECT_ID: Required for web content extraction (BrowserBase)
AWS_REGION: AWS region (default: 'us-east-1')AWS_ACCESS_KEY_ID: AWS access key IDAWS_SECRET_ACCESS_KEY: AWS secret access keyS3_BUCKET_NAME: S3 bucket name for storing generated images (default: 'mastra-generated-images')S3_PUBLIC_URL_BASE: Public URL base for accessing uploaded images
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_aws_access_key_id
AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
S3_BUCKET_NAME=mastra-generated-images
S3_PUBLIC_URL_BASE=https://mastra-generated-images.s3.amazonaws.comNote: Make sure your S3 bucket is configured for public read access for the generated images to be accessible via the public URLs.
@mastra/core: Core Mastra framework@ai-sdk/openai: OpenAI integration for image generation@aws-sdk/client-s3: S3-compatible cloud storage (for image uploads)@browserbasehq/stagehand: Web browsing and content extractionpdf2json: PDF text extractionai: AI SDK for image generationzod: Schema validation