Ad Copy Generation Template
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.
Features
- 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
Quick Start
-
Install dependencies:
pnpm install -
Set up environment variables: Create a
.envfile with:1OPENAI_API_KEY=your_openai_api_key 2 3# For web content extraction (optional - only needed for URL input type) 4BROWSERBASE_API_KEY=your_browserbase_api_key 5BROWSERBASE_PROJECT_ID=your_browserbase_project_id 6 7# For AWS S3 cloud storage (required for image generation) 8AWS_REGION=us-east-1 9AWS_ACCESS_KEY_ID=your_aws_access_key_id 10AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key 11S3_BUCKET_NAME=mastra-generated-images 12S3_PUBLIC_URL_BASE=https://your-bucket-name.s3.amazonaws.com -
Run the application:
pnpm dev
Usage Examples
Using the Workflow
1import { mastra } from './src/mastra';
2
3// Generate ad copy from text content
4const result = await mastra.runWorkflow('ad-copy-generation-workflow', {
5 contentInput: 'Your product description or marketing content here...',
6 inputType: 'text',
7 platform: 'facebook',
8 campaignType: 'conversion',
9 targetAudience: 'Small business owners aged 25-45',
10 tone: 'professional',
11 generateImages: true,
12 imageStyle: 'modern',
13});
14
15// Generate ad copy from PDF
16const pdfResult = await mastra.runWorkflow('ad-copy-generation-workflow', {
17 contentInput: 'https://example.com/product-brochure.pdf',
18 inputType: 'pdf',
19 platform: 'linkedin',
20 campaignType: 'awareness',
21 tone: 'authoritative',
22});
23
24// Generate ad copy from website URL
25const urlResult = await mastra.runWorkflow('ad-copy-generation-workflow', {
26 contentInput: 'https://techcrunch.com/example-startup-article',
27 inputType: 'url',
28 platform: 'instagram',
29 campaignType: 'consideration',
30 targetAudience: 'Tech enthusiasts and early adopters',
31 tone: 'playful',
32 generateImages: true,
33 imageStyle: 'digital_art',
34});
Using Individual Agents
1// Generate ad copy directly
2const adCopy = await mastra.getAgent('adCopyAgent').generate([
3 {
4 role: 'user',
5 content: 'Create Facebook ad copy for a new productivity app targeting remote workers',
6 },
7]);
8
9// Extract content from PDF
10const pdfContent = await mastra.getTool('pdf-content-extractor').execute({
11 context: { pdfUrl: 'https://example.com/whitepaper.pdf' },
12 mastra,
13});
Components
Agents
- 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
Tools
- 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
Workflows
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
Platform Support
- 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
Campaign Types
- Awareness: Brand awareness and reach campaigns
- Consideration: Lead generation and engagement
- Conversion: Sales and action-driven campaigns
- Retention: Customer retention and loyalty
Output Examples
The workflow generates:
Ad Copy
- Single optimized headline
- Compelling body copy
- Effective call-to-action
Image
- One promotional image uploaded to S3
- Platform-optimized dimensions
- Style-consistent visual design
Advanced Configuration
Expected Output Structure
1const result = await mastra.runWorkflow('ad-copy-generation-workflow', {
2 // ... input params
3});
4
5// Result structure:
6{
7 adCopy: {
8 headline: "Your optimized headline",
9 body: "Compelling body copy for your ad",
10 cta: "Call to action"
11 },
12 imageUrl: "https://your-bucket.s3.amazonaws.com/generated-images/uuid.jpg" // Optional
13}
Specific Focus Areas
1const result = await mastra.getTool('pdf-content-extractor').execute({
2 context: {
3 pdfUrl: 'https://example.com/content.pdf',
4 focusAreas: ['benefits', 'pricing', 'testimonials'],
5 },
6 mastra,
7});
Development
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
Environment Variables
Required
OPENAI_API_KEY: Required for AI generation (OpenAI GPT-4)
Optional (based on features used)
BROWSERBASE_API_KEY: Required for web content extraction (BrowserBase)BROWSERBASE_PROJECT_ID: Required for web content extraction (BrowserBase)
AWS S3 Cloud Storage (required for image generation)
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 S3 Setup Example
1AWS_REGION=us-east-1
2AWS_ACCESS_KEY_ID=your_aws_access_key_id
3AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
4S3_BUCKET_NAME=mastra-generated-images
5S3_PUBLIC_URL_BASE=https://mastra-generated-images.s3.amazonaws.com
Note: Make sure your S3 bucket is configured for public read access for the generated images to be accessible via the public URLs.
Dependencies
@mastra/core: Core Mastra framework@ai-sdk/openai: OpenAI integration@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
