# OpenShorts + n8n Two importable workflows, from a one-shot clipper to a channel watcher. Both run against a self-hosted OpenShorts instance (point them at your base URL, default `http://localhost:8000`) and publish through a self-hosted [Postiz](https://postiz.pbento.pt/) instance. No API key is required on a self-hosted instance, but the server needs a Google Gemini key for the AI stages, and Postiz needs the target channels connected. | Workflow | What it does | Credentials | |---|---|---| | `openshorts-clip-and-notify.json` | A video URL goes in through a form, clips come back on a signed webhook. No polling. | None (self-hosted) | | `openshorts-content-machine.json` | Watches your YouTube channel: daily clipping, approval buttons in Telegram, drip-scheduled posting through Postiz, weekly analytics digest. | Telegram bot | ## Shared setup 1. In n8n: **Workflows → Import from file** → pick the workflow. 2. Set `OPENSHORTS_URL` / the request base URL to your instance (`http://localhost:8000`). 3. Open the **Clips ready (webhook)** node, copy its production URL, and paste it as `webhook_url` inside the **Start OpenShorts job** node body. 4. Optional: change `webhook_secret`. OpenShorts signs the webhook body with HMAC-SHA256 and sends it as `X-OpenShorts-Signature: sha256=`; verify it in a Code node with: ```javascript const crypto = require('crypto'); const expected = 'sha256=' + crypto .createHmac('sha256', 'change-me') .update(JSON.stringify($json.body)) .digest('hex'); ``` ## The Content Machine `openshorts-content-machine.json` runs your channel in four acts: 1. **Watch** — once a day it reads your channel's RSS feed (`https://www.youtube.com/feeds/videos.xml?channel_id=UC...`) and clips **one** video: the newest upload if there is one, otherwise the next unprocessed video from your back catalog. One video a day keeps processing predictable. 2. **Approve from your phone** — every finished clip lands in Telegram with ✅ Publish / ❌ Skip buttons. Clips over Telegram's ~20 MB URL limit fall back to a link message with the same buttons. 3. **Drip-publish** — each approved clip takes the next free daily slot and is scheduled through `POST /api/postiz/post` to every channel connected in Postiz. Approve five clips today, fill five days of content. The slot comes from the queue the server actually holds (`GET /api/postiz/scheduled`), so two clips approved seconds apart cannot book the same one. 4. **Sunday digest** — the machine reads the analytics of what it published (`GET /api/postiz/analytics/*`) and reports total impressions, per-platform split, and your best post of the week. Machine-specific setup, all inside sticky notes on the canvas: - Put your channel id in the **Channel RSS feed** node. - Create a Telegram bot with [@BotFather](https://t.me/BotFather), add the `Telegram bot` credential, and replace `YOUR_TELEGRAM_CHAT_ID` in the notification nodes (message your bot, then check `api.telegram.org/bot/getUpdates` for your chat id). - Connect your social accounts in your self-hosted Postiz instance — the posting step uses them directly; no extra social credentials in n8n. Note: the machine remembers which videos it already processed in n8n workflow static data, which only persists for **production** executions — test runs in the editor won't advance it. Scheduling deliberately does *not* use that mechanism (see act 3). ## Webhook payload ```json { "event": "job.completed", "job_id": "…", "status": "completed", "clips": [ { "index": 0, "title": "…", "video_url": "…", "download_url": "…" } ] } ``` Failed jobs fire the same webhook with `"event": "job.failed"` and an `error` field, so the flow never hangs waiting. `download_url` is a 24-hour presigned link to the archived clip. ## Publishing and analytics API Direct posting: `POST /api/postiz/post` (accepts `scheduled_date`, ISO-8601). Connected channels: `GET /api/postiz/integrations`. Publishing queue: `GET /api/postiz/scheduled`, and `DELETE /api/postiz/scheduled/{id}` to cancel one before it goes out. Analytics of what you published: `GET /api/postiz/analytics` (channel totals) and `GET /api/postiz/analytics/posts` (per-post metrics). Full API reference: `/docs` (OpenAPI) on your instance.