Dual AI Caption Agents & Meta Graph API Distribution

Consumes yesterday’s Vertex AI photorealistic asset to orchestrate parallel caption generation via specialized OpenAI agents and automates multi-platform publishing to Instagram and Facebook through Meta's Graph API.

πŸ’‘
The Architectural Clue: "Think authentication first, tokens, permissions, and page connections matter more than the post itself." Posting fails unless you resolve the Facebook Page Connection, derive the permanent Page Access Token, and bridge to the linked Instagram Business Account.
βš™οΈ n8n Multi-Channel Distribution Canvas
Ready for execution
Upstream #37
⏱️ Trigger
Schedule Trigger1
Daily cron or manual
β†’
πŸ€– LangChain
AI Agent3
Creative Prompt Director
β†’
{ } Transform
Code6
Parse JSON Prompt
β†’
🌐 Predict
Generate Image1
Vertex AI Imagen 3
β†’
⚑ Database
Create a row
Supabase creative row
β†’
⚑ Database
Get a row1
Feeds Asset to Branches
Instagram Path
↳ Branch A
β†’
πŸ“Έ AI Agent
AI Agent4
OpenAI GPT-4o (IG Copy)
β†’
{ } Transform
Code8
Format IG Container
β†’
πŸ“¦ Meta Graph
IG Container image1
POST /{ig_id}/media
β†’
πŸš€ Publish
IG Image Post1
POST /media_publish
Facebook Path
↳ Branch B
β†’
πŸ’¬ AI Agent
AI Agent5
OpenAI GPT-4o (FB Copy)
β†’
{ } Transform
Code9
Format FB Photo Data
β†’
🌐 Meta Graph
FB IMAGE POST1
POST /{page_id}/photos
[13:30:00] SYSTEM Pipeline initialized. Ingested creative asset from Puzzle #37 (s37-generated-creative.png). Click "Run Pipeline Simulation" to execute dual branches.

πŸ”‘ Meta OAuth Token Hierarchy

The core challenge clue stresses authentication: posting to Page & IG feeds requires exchanging ephemeral user tokens for a permanent Page Access Token.

1. Short-Lived User Token 1–2 Hours
Granted via OAuth login dialog. Bootstrap token only.
EAABw...short_89a1
2. Long-Lived User Token 60 Days
Exchanged via GET /oauth/access_token?grant_type=fb_exchange_token
EAABw...long_60day
3. Permanent Page Access Token Never Expires
Retrieved from GET /me/accounts using the 60-day token. Required for n8n cron!
EAABw...page_perm

πŸ”— Page Connections & Instagram ID

Instagram Professional accounts cannot post directly. They must be linked to a Facebook Page to expose their Graph API user ID.

// GET https://graph.facebook.com/v20.0/{page-id} // ?fields=id,name,access_token,instagram_business_account { "id": "104928374829102", "name": "PulseCreative Agency", "access_token": "EAABw...[PERMANENT_PAGE_TOKEN]", "instagram_business_account": { "id": "17841405309210987", "username": "pulsecreative.ai" } }
Mandatory Permissions Check:
pages_manage_posts βœ“ Granted
instagram_content_publish βœ“ Granted
pages_show_list βœ“ Granted
instagram_basic βœ“ Granted
πŸ“Έ
AI Agent 4: Instagram Specialist
OpenAI GPT-4o Β· Temp 0.65 Β· High Whitespace
πŸ’¬
AI Agent 5: Facebook Specialist
OpenAI GPT-4o Β· Temp 0.70 Β· Direct Response

πŸš€ Meta Graph API Multi-Step Publishing Pipeline

Live simulation of Meta Graph API v20.0 publishing requests, showcasing Instagram's mandatory 2-step container lifecycle vs Facebook's direct photo endpoint.

Instagram Step 1: Create Container HTTP 200 OK
POST https://graph.facebook.com/v20.0/17841405309210987/media Parameters: image_url: "https://pulsecreative-prod.supabase.co/storage/v1/object/public/.../s37-generated-creative.png" caption: "STILL DOING IT ALL BY HAND?..." access_token: "EAABw...[PAGE_TOKEN]" Response: { "id": "17992837461928374" // Asynchronous container ID }
Instagram Step 2: Publish Container HTTP 200 OK
POST https://graph.facebook.com/v20.0/17841405309210987/media_publish Parameters: creation_id: "17992837461928374" access_token: "EAABw...[PAGE_TOKEN]" Response: { "id": "18039281729384712" // Final Instagram Published Post ID }
Facebook: Page Photo Upload HTTP 200 OK
POST https://graph.facebook.com/v20.0/104928374829102/photos Parameters: url: "https://pulsecreative-prod.supabase.co/storage/v1/object/public/.../s37-generated-creative.png" caption: "Still doing it all by hand?..." published: true access_token: "EAABw...[PAGE_TOKEN]" Response: { "id": "928374619283746", "post_id": "104928374829102_928374619283746" }

Live Supabase Persistence: social_distributions Table

Platform Status Remote Media / Post ID Container ID Target Account Permalink
Instagram PUBLISHED 18039281729384712 17992837461928374 pulsecreative.ai (178414...) instagram.com/p/C_18039281729/
Facebook PUBLISHED 104928374829102_928374619283746 N/A (Direct) PulseCreative Page (104928...) facebook.com/104928374829102/posts/928374619

🎯 Benchmark Creative & Text Parity

Visual breakdown of the benchmark copy and asset from the challenge prompt:

  • Headline Match: Both agents center around "STILL DOING IT ALL BY HAND?", matching the bold white typography of the Vertex image.
  • Sensory Agitation: Explicit inclusion of "17 missed calls" (matching the phone LED) and "Stacks/piles of paperwork".
  • Reframing Philosophy: Transforms raw exhaustion into a structured systems diagnosis ("That's not hustle β€” that's overload" / "burnout waiting to happen").
  • Platform Optimization: Facebook triggers comment engagement ("Drop FREE DEMO below"), while Instagram commands bio navigation ("πŸ‘‰ Link in bio.").

🧩 Upstream & Downstream Integration

How Puzzle #37 and #38 complete an enterprise AI marketing automation loop:

[Puzzle #37] Upstream Creative Generation: 1. AI Agent 3 crafts photorealistic prompt 2. Vertex AI Imagen 3 synthesizes 1:1 image 3. Binary stored in Supabase 'generated-images' 4. PostgreSQL row inserted with status 'ready_for_distribution' [Puzzle #38] Downstream Multi-Channel Distribution: 1. Get a row1 fetches creative record 2. AI Agent 4 crafts high-hook Instagram copy 3. AI Agent 5 crafts storytelling Facebook copy 4. Meta Graph API authenticates via Page Access Token 5. Asynchronous IG container publish + FB photo upload 6. Supabase status upgraded to 'published'

🩺 8-Point Automated Diagnostic Suite

Verifies token hierarchy exchange, permissions validity, account discovery, and Graph API request contracts.