Docsity

Rampage document safe, Transcriptions of Business

Toggle sidebar
bg1
CampaignFlow — Engineering Reference
CampaignFlow
End-to-End Content Approval & Social Publishing Workflow
Engineering Reference · Approval Chain, Email Automation & Instagram Graph API Integration
1. Overview
CampaignFlow takes a piece of marketing content from creation through a multi-level approval chain (Creator →
Automated Compliance Check → Approver L1 → Approver L2 → Client) and finally to scheduling or live publishing
on social platforms. Campaign and Content records share a single unified status field so the Dashboard, Approval
Flow screen, and email actions always stay in sync.
This revision documents the working Instagram publishing pipeline (Section 5) built on the Meta Graph API,
including the media-hosting problem it had to solve, the tenant-routing fix required to make the public callback
reachable, and image vs. video handling — in addition to the original approval workflow.
2. Workflow Stages
Step 1 — Create Campaign
Screen: Create Campaign page
•Marketing manager enters Campaign Name, Type, Start/End Date, Description.
•Selects Target Platforms (e.g. Instagram, Facebook) from the platform lookup.
•Assigns team: Content Creator, Approver L1, Approver L2, Client Approver, plus optional additional members.
•A live workflow preview shows the approval chain that will apply to this campaign.
•“Create Campaign” → POST /save-campaign/ creates the Campaign row with status = draft, then opens Upload
Content.
Step 2 — Upload Content
Screen: Upload Content page
•Creator uploads a Reel, Photo, or Video, writes Caption, Disclaimer, Hashtags, and Platform Notes.
•Campaign and Approver L1 are shown as read-only context if arriving from Step 1.
•“Save Draft” keeps status = draft. “Submit for Review” → POST /save-content/ sets status =
submitted_for_approval on both Campaign and Content, then opens Compliance Check.
Step 3 — Automated Compliance Check
Screen: Compliance Check page
•System runs 9 automated checks: Brand Guidelines, Duplicate Content, File Uploaded, Caption, Disclaimer,
Restricted Keywords, Copyright Check, Restricted Content, Hashtags.
Page 1 of 6
pf3
pf4
pf5

Partial preview of the text

Download Rampage document safe and more Transcriptions Business in PDF only on Docsity!

CampaignFlow

End-to-End Content Approval & Social Publishing Workflow

Engineering Reference · Approval Chain, Email Automation & Instagram Graph API Integration

1. Overview

CampaignFlow takes a piece of marketing content from creation through a multi-level approval chain (Creator →

Automated Compliance Check → Approver L1 → Approver L2 → Client) and finally to scheduling or live publishing

on social platforms. Campaign and Content records share a single unified status field so the Dashboard, Approval

Flow screen, and email actions always stay in sync.

This revision documents the working Instagram publishing pipeline (Section 5) built on the Meta Graph API,

including the media-hosting problem it had to solve, the tenant-routing fix required to make the public callback

reachable, and image vs. video handling — in addition to the original approval workflow.

2. Workflow Stages

Step 1 — Create Campaign

Screen: Create Campaign page

  • Marketing manager enters Campaign Name, Type, Start/End Date, Description.
  • Selects Target Platforms (e.g. Instagram, Facebook) from the platform lookup.
  • Assigns team: Content Creator, Approver L1, Approver L2, Client Approver, plus optional additional members.
  • A live workflow preview shows the approval chain that will apply to this campaign.
  • “Create Campaign” → POST /save-campaign/ creates the Campaign row with status = draft, then opens Upload

Content.

Step 2 — Upload Content

Screen: Upload Content page

  • Creator uploads a Reel, Photo, or Video, writes Caption, Disclaimer, Hashtags, and Platform Notes.
  • Campaign and Approver L1 are shown as read-only context if arriving from Step 1.
  • “Save Draft” keeps status = draft. “Submit for Review” → POST /save-content/ sets status =

submitted_for_approval on both Campaign and Content, then opens Compliance Check.

Step 3 — Automated Compliance Check

Screen: Compliance Check page

  • System runs 9 automated checks: Brand Guidelines, Duplicate Content, File Uploaded, Caption, Disclaimer,

Restricted Keywords, Copyright Check, Restricted Content, Hashtags.

  • Each check returns Passed / Warning / Failed with a detail message and a compliance score (%).
  • Reviewer can “Edit & Fix Issues” to override individual check results and add remarks, or “Reject Content”

outright.

  • “Submit for Review” → POST /save-compliance-review/ (action=approved) sets status =

submitted_for_approval and triggers an email to Approver L1 with one-click Approve/Reject buttons.

Step 4 — Approver L1 (via Email)

  • L1 approver receives an email with the content preview and signed, time-limited Approve / Reject links — no

login required.

  • Approve → GET /email-action/ verifies the token, keeps status = submitted_for_approval, and emails Approver

L2.

  • Reject → status = rejected (terminal); creator is expected to revise and resubmit.

Step 5 — Approver L2 (via Email)

  • Same one-click pattern. Approve → status stays submitted_for_approval and emails the Client with

Approve/Reject buttons.

  • Reject → status = rejected.

Step 6 — Client Approval (via Email) — Final Gate

  • Client reviews and clicks Approve or Reject directly from the email.
  • Approve → status = approved (FINAL). This is the only action that produces a final approved state.
  • Reject → status = rejected.

Step 7 — Approval Flow Dashboard

Screen: Flow History / Approval Flow page

  • Shows a visual pipeline: Content Creator → Compliance Check → Approver L1 → Approver L2 → Client, each

marked done / active / failed / pending.

  • Displays campaign details, uploaded media preview, compliance results, and team members in one place.
  • Once status = approved, a “Publish Content” button appears and opens the Publish screen.

Step 8 — Publish or Schedule

Screen: Publish page

  • User selects which approved platforms to post to and can customize the caption per platform.
  • Picks a Publish Date, Time, and Time Zone using the date/time pickers.
  • “Schedule Post” or “Publish Now” → POST /save-publish/ creates a CampaignPublish record, sets status =

scheduled or published, and — for Instagram with Publish Now — triggers the live Graph API call described in

Section 5.

  • Recently Published list (GET /publish-history/) shows a history of completed posts for the campaign.

5. Instagram Publishing — Implementation

“Publish Now” and “Schedule Post” create the CampaignPublish record as before. In addition, when the target

platform is Instagram and the action is Publish Now, the backend now makes a live call to the Meta Graph API and

posts the approved content to the connected Instagram Business account. This section documents how that

integration works end-to-end, and the environment issues that had to be solved to get a local/dev setup talking to

Meta's servers.

5.1 Graph API Flow

Instagram does not accept an uploaded file directly. The Graph API instead fetches the media itself from a URL you

give it, in a two-step container/publish pattern:

  • Step 1 — Create container: POST /{ig-business-account-id}/media with image_url (photos) or video_url +

media_type=REELS (video). Meta responds with a creation_id and asynchronously downloads and processes

the media.

  • Step 2 — Poll status: GET /{creation_id}?fields=status_code until status_code = FINISHED (or ERROR).

Images typically finish in a few seconds; video/Reels processing takes noticeably longer, so the video path polls

more times with a longer interval.

  • Step 3 — Publish: POST /{ig-business-account-id}/media_publish with the creation_id. Meta returns the final

media ID, confirming the post is live.

Implementation: campaignflow/services/instagram.py — publish_to_instagram() (image) and

publish_video_to_instagram() (video/Reels). campaignflow/api.py inspects the uploaded file extension in

save_publish() and routes to the correct function, so the existing image flow is untouched and video is additive.

5.2 The Core Problem: Meta Must Reach the Media URL Publicly

The image/video URL passed to the Graph API is fetched by Meta's own servers, not by the browser or the Django

backend. That means it must be:

  • Reachable from the public internet (Meta's infrastructure, not just the developer's machine or Docker network).
  • Served over HTTPS in practice — plain HTTP is frequently rejected.
  • A stable, correctly content-typed response — Graph API error code 9004 (“Only photo or video can be

accepted as media type”) surfaces whenever the fetch fails or the wrong media parameter is used for the file

type.

Local hostnames such as backend:8000 (a Docker-internal service name) or alyousuf.localhost:8000 (a machine-

local tenant domain) are both invisible to Meta's servers, and requests to them fail with an unreachable-media error

at the container-creation step.

5.3 Development Fix: ngrok Tunnel for Media Only

For local/demo environments without a public domain, ngrok exposes the backend's port 8000 through a temporary

public HTTPS URL that forwards to http://localhost:8000. This gives Meta's servers a reachable address to fetch the

content-preview image/video from, without requiring production infrastructure.

ngrok config add-authtoken # one-time setup ngrok http 8000 # prints the public Forwarding URL

Two settings were deliberately kept separate rather than reusing one URL for both purposes:

Setting Used for Value in this setup SITE_URL Email approve/reject links opened by humans in a browser on the same machine/network. http://alyousuf.localhost:8000/api INSTAGRAM_MEDIA_BA SE_URL Media URL passed to the Graph API — must be fetchable by Meta's servers. https://.ngrok-free.dev/api Rationale: email links are opened by people already on the same local network/tenant domain, so changing SITE_URL to the ngrok host would have broken nothing functionally but was unnecessary churn — and ngrok's free-tier URL changes on every restart, which would otherwise invalidate already-sent, unexpired approval emails. Splitting the settings means only the Instagram-facing path depends on the rotating tunnel URL.

5.4 Multi-Tenant Routing Fix

The application uses django-tenants, which resolves the current tenant schema from the request's Host header via the

main_domain table. Once the ngrok hostname started receiving requests (Instagram fetching content-preview, or a

browser opening an email link through the tunnel), Django rejected them with:

No tenant for hostname ".ngrok-free.dev" (raised by ninja.operation._sync_view)

Fix: the ngrok hostname was added as an additional Domain row pointing at the existing tenant (same tenant_id as

the working alyousuf.localhost row, is_primary = false). This required no schema or code change — only one

INSERT — and the original alyousuf.localhost domain remained untouched, so the in-app UI and email links were

unaffected.

  • Because ngrok's free tier issues a new hostname on every restart, this Domain row (and the

INSTAGRAM_MEDIA_BASE_URL value) needs to be refreshed before each demo/test session if the tunnel

was restarted.

5.5 Image vs. Video Handling

The Graph API treats photos and video/Reels as distinct upload contracts; passing a video file through the image

parameter fails with error 36001 (“The image format is not supported”) because Meta attempts to convert it to a still

JPEG.

Media type Container parameters Notes Photo (.jpg/.png/.gif) image_url + caption Handled by publish_to_instagram(); processing typically completes in 1– polling cycles. Video (.mp4/.mov) media_type=REELS, video_url + caption Handled by publish_video_to_instagram(); polls up to 30 times at 5-second intervals to allow for longer server-side transcoding.

File type is detected from the uploaded file's extension in save_publish(); the routing is additive and does not change

the existing image publish path.

5.6 Errors Encountered and Resolved

Code Graph API message Root cause & resolution