Skip to content

Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.

7.3 KB
Raw Blame

phase: "12-instagram" plan: "01" subsystem: ops-marketing tags: [instagram, instagram-graph-api, publishing, reels, stories, insights, demographics] dependency_graph: requires: [meta-ads-credential-resolution] provides: [instagram-post-publish, instagram-reel-publish, instagram-story-publish, instagram-insights, instagram-demographics] affects: [ops-marketing/SKILL.md]

Phase 12 Plan 01: Instagram Publishing & Insights

Goal

Add Instagram publishing and analytics sub-commands to ops-marketing/SKILL.md via the Instagram Graph API: publish feed posts, Reels (with async status poll), Stories, retrieve per-post insights, account-level insights, and demographics breakdowns. IG Account ID auto-resolved via /me/accounts and cached in plugin config.

Requirements Addressed

  • Instagram content publishing: feed posts, Reels, Stories
  • Instagram Insights: per-post and account-level metrics
  • Instagram demographics: age/gender and top location breakdowns

Runtime Prerequisites

STOP — the following credentials must be configured before this plan can execute:

Credential Where to get it
META_ACCESS_TOKEN Same token as Meta Ads — must additionally have instagram_basic, instagram_content_publish, instagram_manage_insights permissions
INSTAGRAM_ACCOUNT_ID Auto-resolved via /me/accounts?fields=instagram_business_account (Plan caches on first run in plugin config)
Facebook Page linked to Instagram Instagram must be a Professional (Business or Creator) account connected to a Facebook Page in Business Manager

Permission note: instagram_content_publish requires app review for production use.

Rate limit note: 200 API calls per user per hour. One publish = 2 calls (container create + publish). Plan at ≤ 100 publishes/hour.

Deliverables

Files to Modify

  • claude-ops/skills/ops-marketing/SKILL.md — add ## instagram section with sub-command routing, INSTAGRAM_ACCOUNT_ID auto-resolution, post/reel/story/insights/account-insights/demographics sub-commands

Task Breakdown

Task 1: Credential Resolution and Account ID Auto-Discovery

File: claude-ops/skills/ops-marketing/SKILL.md → ## instagram section preamble

Add INSTAGRAM_ACCOUNT_ID resolution:

INSTAGRAM_ACCOUNT_ID="${instagram_account_id:-${INSTAGRAM_ACCOUNT_ID:-$(claude plugin config get instagram_account_id 2>/dev/null)}}"
if [ -z "$INSTAGRAM_ACCOUNT_ID" ] && [ -n "$META_ACCESS_TOKEN" ]; then
  INSTAGRAM_ACCOUNT_ID=$(curl -sf \
    "https://graph.facebook.com/v19.0/me/accounts?fields=instagram_business_account&access_token=${META_ACCESS_TOKEN}" \
    | jq -r '.data[].instagram_business_account.id // empty' | head -1)
  [ -n "$INSTAGRAM_ACCOUNT_ID" ] && claude plugin config set instagram_account_id "$INSTAGRAM_ACCOUNT_ID" 2>/dev/null
fi

Guard: if either token or account ID is empty after auto-discovery, print setup hint and stop.

Sub-command routing table:

Input Action
post <IMAGE_URL> <CAPTION> Publish feed image post
reel <VIDEO_URL> <CAPTION> Publish Reel (async poll until FINISHED)
story <URL> Publish Story (image or video auto-detected)
insights <MEDIA_ID> Per-post reach, saves, shares, plays
account-insights [days] Account-level reach + impressions (48h delay note)
demographics Age/gender + top cities/countries

Task 2: Publishing Sub-commands (post, reel, story)

File: claude-ops/skills/ops-marketing/SKILL.md → ## instagram section

Feed Post (instagram post <IMAGE_URL> <CAPTION>):

Two-step publish:

  1. Create container: POST /{INSTAGRAM_ACCOUNT_ID}/media with image_url + caption; capture creation_id
  2. Publish: POST /{INSTAGRAM_ACCOUNT_ID}/media_publish with creation_id; print media ID

AskUserQuestion confirmation (Rule 5) before publishing — show image URL and caption preview (first 80 chars).

Reel (instagram reel <VIDEO_URL> <CAPTION>):

  1. Create container with media_type=REELS&video_url=<URL>&caption=<CAPTION>
  2. Poll /{creation_id}?fields=status_code until status_code == "FINISHED" (max 20 polls, 5s intervals; print progress)
  3. Publish when FINISHED; print media ID
  4. Error handling: if status_code == "ERROR", print error code + suggest H.264/MP4/720p/60s re-encode

Story (instagram story <URL>):

Auto-detect media type from URL extension (.jpg|.png|.gif → IMAGE, .mp4|.mov → VIDEO):

  1. Create container with media_type=STORIES + appropriate URL field
  2. For video: poll until FINISHED (same pattern as Reel)
  3. Publish; print media ID
  4. Note: Stories expire automatically after 24 hours

Task 3: Insights Sub-commands (insights, account-insights, demographics)

File: claude-ops/skills/ops-marketing/SKILL.md → ## instagram section

Per-Post Insights (instagram insights <MEDIA_ID>):

GET /{MEDIA_ID}/insights?metric=reach,saved,shares,video_views,likes,comments,impressions&access_token=<TOKEN>

Output banner + metric list:

══ POST INSIGHTS ══
Reach: 12,345  Impressions: 18,901
Likes: 432     Comments: 18
Shares: 67     Saves: 89
Video Plays: N/A (image posts)

Account-Level Insights (instagram account-insights [days]):

Default days=28. GET /{INSTAGRAM_ACCOUNT_ID}/insights with metric=reach,impressions,profile_views,website_clicks,follower_count, period=day, date range from days ago.

Aggregate daily values; note 48-hour data delay in output.

Demographics (instagram demographics):

GET /{INSTAGRAM_ACCOUNT_ID}/insights?metric=audience_gender_age,audience_city,audience_country&period=lifetime

Two output sections:

  1. Age/gender table (top 10 rows): Age Range | Male% | Female%
  2. Top locations: top 5 cities + top 5 countries with percentage

Threat Model

ID Threat Mitigation
T-12-01-01 Publishing to wrong Instagram account Mitigated — INSTAGRAM_ACCOUNT_ID shown in confirmation; AskUserQuestion before every publish
T-12-01-02 Reel poll loop runs indefinitely Mitigated — max 20 polls (100s timeout); print error and exit on EXPIRED/ERROR status
T-12-01-03 Content published without review Mitigated — Rule 5 AskUserQuestion with content preview before every publish
T-12-01-04 Rate limit: 200 calls/hr Accepted — CLI tool is low-volume; document rate limit; no automatic retry loops
T-12-01-05 Demographics data exposed in terminal Accepted — aggregate data only, no individual PII; local terminal

Dependencies

  • Requires: META_ACCESS_TOKEN with Instagram permissions; Instagram Professional account linked to Facebook Page
  • Provides: instagram-post-publish, instagram-reel-publish, instagram-story-publish, instagram-insights, instagram-account-insights, instagram-demographics

Success Criteria (Self-Check)

  • grep "instagram post" claude-ops/skills/ops-marketing/SKILL.md — PASS
  • grep "media_publish" claude-ops/skills/ops-marketing/SKILL.md — PASS
  • grep "status_code.*FINISHED" claude-ops/skills/ops-marketing/SKILL.md — PASS
  • grep "INSTAGRAM_ACCOUNT_ID" claude-ops/skills/ops-marketing/SKILL.md returns ≥ 3
  • grep "audience_gender_age" claude-ops/skills/ops-marketing/SKILL.md — PASS
  • grep "48.hour delay" claude-ops/skills/ops-marketing/SKILL.md — PASS
  • grep "200.*calls\|rate limit" claude-ops/skills/ops-marketing/SKILL.md — PASS