---
name: phix-social-planner-publisher
description: Publish PHIX image posts from the local "Para Publicar" folder to GoHighLevel Social Planner via the official HighLevel MCP server, excluding video-only platforms, selecting Pinterest boards from recent posts, and moving successfully submitted images into the "Publicadas" folder.
metadata:
  short-description: Publish PHIX images to HighLevel Social Planner
---

# PHIX Social Planner Publisher

Use this skill when the user wants to publish PHIX image creatives from the local queue folder into GoHighLevel Social Planner, especially for recurring/daily posting.

## Default Paths

- Queue folder: `C:\Users\Med Lab\Documents\Clientes\MPG\Phix\IA PHIX\outputs\imagenes\Para Publicar`
- Archive folder: `C:\Users\Med Lab\Documents\Clientes\MPG\Phix\IA PHIX\outputs\imagenes\Para Publicar\Publicadas`

Create the archive folder if it does not exist. Do not publish files already inside `Publicadas`.

## Authentication

Prefer the Codex HighLevel connector for normal use. If the connector is authenticated, do not require local environment variables.

- Primary path: use the connected HighLevel app tools available in the Codex session.
- Fallback path: use local environment variables only when the connector is unavailable for the current run.

Never store tokens in the skill or repo. The local-script fallback requires:

- `GHL_TOKEN`: HighLevel private integration token with Social Planner publishing scope.
- `GHL_LOCATION_ID`: HighLevel sub-account/location ID.

If the HighLevel connector returns `401`, `Reauthentication required`, or equivalent auth errors, stop and report that the connector must be reconnected before publishing can continue.

## Workflow

1. Pick one image from the queue folder.
   - For recurring automation runs, treat the folder as FIFO and pick the oldest image first.
   - For explicit manual one-off runs, newest is acceptable if the user asks for that behavior.
2. Prefer publishing through the connected HighLevel app tools in the Codex session.
   - Use the HighLevel connector to discover the Social Planner resources needed for listing accounts, reading recent posts, and creating a post.
   - If the connector is not authenticated, report that clearly and stop instead of pretending the post was attempted.
3. Upload or resolve the local image to a public HTTPS image URL only after authentication is confirmed.
   - Prefer a HighLevel-native media upload path when the connector or token allows it.
   - Only fall back to an external public upload URL if the user allows it and the connector-native route is unavailable.
4. List Social Planner accounts.
5. Include active, non-expired accounts for image-capable platforms:
   - `facebook`
   - `instagram`
   - `linkedin`
   - `pinterest`
6. Always exclude:
   - `youtube`
   - `tiktok`
7. For Pinterest, use board IDs from recent posts if available. If no Pinterest board mapping is discoverable, skip Pinterest rather than failing the whole run.
8. Create a `post` with `body_status: "published"` unless the user requests draft or scheduled.
9. Verify recent posts when possible.
10. Move the image into `Publicadas` only after HighLevel returns `Created Post` successfully.

If the connector path is unavailable but `GHL_TOKEN` and `GHL_LOCATION_ID` are present, use the bundled local script as a fallback.

## Script

Use the bundled script only as a fallback when the HighLevel connector tools are unavailable in the current run and local credentials are present:

```powershell
$env:GHL_TOKEN = "<private integration token>"
$env:GHL_LOCATION_ID = "<location id>"
node ".agents\skills\phix-social-planner-publisher\scripts\publish_social_planner.mjs"
```

Useful options:

```powershell
node ".agents\skills\phix-social-planner-publisher\scripts\publish_social_planner.mjs" --pick oldest
node ".agents\skills\phix-social-planner-publisher\scripts\publish_social_planner.mjs" --dry-run
node ".agents\skills\phix-social-planner-publisher\scripts\publish_social_planner.mjs" --status draft
node ".agents\skills\phix-social-planner-publisher\scripts\publish_social_planner.mjs" --caption-file "C:\path\caption.txt"
```

The script installs/uses `@modelcontextprotocol/sdk` in `.tmp-ghl-mcp-test` if needed.

## Publishing Notes

- If the HighLevel connector is available but returns `401` or `Reauthentication required`, ask the user to reconnect HighLevel. This is the preferred fix for recurring automations.
- If HighLevel Media Storage upload returns "not authorized for this scope", continue with public HTTPS upload unless the user forbids external hosting.
- Do not attempt the external upload step before confirming that either the HighLevel connector is authenticated or the local fallback credentials are present.
- If any individual network fails after creation, report the failed account/platform and reason. Do not move the image back automatically.
- If the user asks to schedule daily execution, use the automation tools available in the current Codex app session; do not write raw scheduler directives by hand.
