diff --git a/examples/n8n/README.md b/examples/n8n/README.md index c1616ea..1061fe6 100644 --- a/examples/n8n/README.md +++ b/examples/n8n/README.md @@ -1,11 +1,20 @@ # OpenShorts + n8n -Importable workflow: a video URL goes in through a form, OpenShorts clips it, -and a signed webhook brings back the finished clips. No polling. +Two importable workflows, from a one-shot clipper to a full channel autopilot. +Both work out of the box with [OpenShorts Cloud](https://www.openshorts.app/) +(free tier: 20 min of video, paid plans from $12/mo). OpenShorts is also open +source: self-hosters can point either workflow at their own instance by +changing the base URL (needs a GPU box, your own Gemini key, and your own +[Upload-Post](https://www.upload-post.com/) account for the posting steps). -## Import +| 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. | OpenShorts API key | +| `openshorts-content-machine.json` | Your YouTube channel on autopilot: daily clipping, approval buttons in Telegram, drip-scheduled posting, weekly analytics digest. | OpenShorts API key + Telegram bot | -1. In n8n: **Workflows → Import from file** → `openshorts-clip-and-notify.json`. +## Shared setup + +1. In n8n: **Workflows → Import from file** → pick the workflow. 2. Create a **Header Auth** credential named `OpenShorts API key`: - Name: `Authorization` - Value: `Bearer osk_...` (create the key in your account page at @@ -24,6 +33,41 @@ and a signed webhook brings back the finished clips. No polling. .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 quota burn + predictable; a 402 (out of minutes) pauses the machine and tells you on + Telegram instead of failing silently. +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/social/post` to every account you connected in + OpenShorts (TikTok, Instagram, YouTube). Approve five clips today, fill five + days of content. +4. **Sunday digest** — the machine reads the analytics of what it published + (`GET /api/social/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 OpenShorts account page (Cloud) — the + posting step uses them directly; no extra social credentials in n8n. + +Note: the machine remembers processed videos and scheduling slots in n8n +workflow static data, which only persists for **production** executions — test +runs in the editor won't advance the state. + ## Webhook payload ```json @@ -44,10 +88,12 @@ field, so the flow never hangs waiting. service). On the self-hosted edition the same workflow runs against `http://localhost:8000` with no API key. -## Publishing the clips +## Publishing and analytics API -Each item after **One item per clip** is a finished 9:16 clip. Chain whatever -comes next: Slack/email notification, a Sheets log, or direct posting via -`POST /api/social/post`. Full API reference: -[api.openshorts.app/docs](https://api.openshorts.app/docs). Agent-native -version of the same pipeline: [openshorts.app/mcp](https://www.openshorts.app/mcp). +Direct posting: `POST /api/social/post` (accepts `scheduled_date`, ISO-8601). +Analytics of what you published: `GET /api/social/analytics` (profile totals), +`GET /api/social/analytics/posts` (per-post metrics), +`GET /api/social/analytics/impressions` (windowed totals, `period=last_week`). +Full API reference: [api.openshorts.app/docs](https://api.openshorts.app/docs). +Agent-native version of the same pipeline (MCP): +[openshorts.app/mcp](https://www.openshorts.app/mcp). diff --git a/examples/n8n/openshorts-clip-and-notify.json b/examples/n8n/openshorts-clip-and-notify.json index f0cf29f..1a3c027 100644 --- a/examples/n8n/openshorts-clip-and-notify.json +++ b/examples/n8n/openshorts-clip-and-notify.json @@ -3,7 +3,7 @@ "nodes": [ { "parameters": { - "content": "## OpenShorts + n8n, the whole loop\n\n**One HTTP request starts the job, one signed webhook ends it.** No polling loop, no wait nodes.\n\n### Setup (3 steps)\n1. Create an API key at [openshorts.app](https://www.openshorts.app/) (account page, starts with `osk_`). Add a **Header Auth** credential: name `Authorization`, value `Bearer osk_...`, and select it in the *Start OpenShorts job* node.\n2. Open the *Clips ready* webhook node, copy its **production** URL, and paste it as `webhook_url` in the *Start OpenShorts job* node body.\n3. Optional: set your own `webhook_secret`. OpenShorts signs the body with HMAC-SHA256 in the `X-OpenShorts-Signature` header (`sha256=`), so you can verify the sender.\n\n### What you get back\n`event`, `job_id`, `status`, and `clips[]` with `title`, `video_url` and a 24h `download_url` per clip. Failed jobs also fire the webhook with an `error` field, so the flow never hangs.\n\nAPI docs: https://api.openshorts.app/docs · Self-hosted works the same on your own machine (MIT).", + "content": "## OpenShorts + n8n, the whole loop\n\n**One HTTP request starts the job, one signed webhook ends it.** No polling loop, no wait nodes.\n\n### Setup (3 steps)\n1. Create an API key at [openshorts.app](https://www.openshorts.app/) (account page, starts with `osk_`). Add a **Header Auth** credential: name `Authorization`, value `Bearer osk_...`, and select it in the *Start OpenShorts job* node.\n2. Open the *Clips ready* webhook node, copy its **production** URL, and paste it as `webhook_url` in the *Start OpenShorts job* node body.\n3. Optional: set your own `webhook_secret`. OpenShorts signs the body with HMAC-SHA256 in the `X-OpenShorts-Signature` header (`sha256=`), so you can verify the sender.\n\n### What you get back\n`event`, `job_id`, `status`, and `clips[]` with `title`, `video_url` and a 24h `download_url` per clip. Failed jobs also fire the webhook with an `error` field, so the flow never hangs.\n\nAPI docs: https://api.openshorts.app/docs \u00b7 Self-hosted works the same on your own machine (MIT).", "height": 460, "width": 480 }, @@ -11,7 +11,10 @@ "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, - "position": [-560, -80] + "position": [ + -560, + -80 + ] }, { "parameters": { @@ -31,7 +34,10 @@ "name": "Video URL form", "type": "n8n-nodes-base.formTrigger", "typeVersion": 2, - "position": [-80, 0] + "position": [ + -80, + 0 + ] }, { "parameters": { @@ -48,7 +54,10 @@ "name": "Start OpenShorts job", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, - "position": [180, 0], + "position": [ + 180, + 0 + ], "credentials": { "httpHeaderAuth": { "name": "OpenShorts API key" @@ -79,7 +88,10 @@ "name": "Job queued", "type": "n8n-nodes-base.set", "typeVersion": 3.4, - "position": [440, 0] + "position": [ + 440, + 0 + ] }, { "parameters": { @@ -91,7 +103,11 @@ "name": "Clips ready (webhook)", "type": "n8n-nodes-base.webhook", "typeVersion": 2, - "position": [-80, 320] + "position": [ + -80, + 320 + ], + "webhookId": "2f8351c1-d51d-4af7-bab3-57f21e07956d" }, { "parameters": { @@ -120,7 +136,10 @@ "name": "Job completed?", "type": "n8n-nodes-base.if", "typeVersion": 2.2, - "position": [180, 320] + "position": [ + 180, + 320 + ] }, { "parameters": { @@ -131,7 +150,10 @@ "name": "One item per clip", "type": "n8n-nodes-base.splitOut", "typeVersion": 1, - "position": [440, 220] + "position": [ + 440, + 220 + ] }, { "parameters": { @@ -157,7 +179,10 @@ "name": "Clip title + download link", "type": "n8n-nodes-base.set", "typeVersion": 3.4, - "position": [700, 220] + "position": [ + 700, + 220 + ] }, { "parameters": { @@ -183,7 +208,10 @@ "name": "Job failed", "type": "n8n-nodes-base.set", "typeVersion": 3.4, - "position": [440, 420] + "position": [ + 440, + 420 + ] }, { "parameters": { @@ -195,7 +223,10 @@ "name": "Sticky Note 2", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, - "position": [960, 180] + "position": [ + 960, + 180 + ] } ], "connections": { @@ -266,4 +297,4 @@ "executionOrder": "v1" }, "pinData": {} -} +} \ No newline at end of file diff --git a/examples/n8n/openshorts-content-machine.json b/examples/n8n/openshorts-content-machine.json new file mode 100644 index 0000000..d24be58 --- /dev/null +++ b/examples/n8n/openshorts-content-machine.json @@ -0,0 +1,885 @@ +{ + "name": "OpenShorts Content Machine: your channel clips itself, you approve from your phone", + "nodes": [ + { + "parameters": { + "content": "## ACT 1 \u2014 Watch the channel (daily)\n\nOnce a day this branch reads your channel's RSS feed and picks **one** video to clip: a new upload if there is one, otherwise the next unprocessed video from your back catalog (newest first). One video per day keeps your quota burn predictable.\n\n**Setup**: put your channel id in the *Channel RSS feed* node (`https://www.youtube.com/feeds/videos.xml?channel_id=UC...`). Find it at youtube.com \u2192 your channel \u2192 About \u2192 Share \u2192 Copy channel ID.\n\nIf OpenShorts answers 402 (out of minutes) the machine pauses and tells you on Telegram instead of failing silently.", + "height": 420, + "width": 400, + "color": 4 + }, + "id": "note-act1", + "name": "Act 1 note", + "type": "n8n-nodes-base.stickyNote", + "typeVersion": 1, + "position": [ + -560, + -120 + ] + }, + { + "parameters": { + "rule": { + "interval": [ + { + "field": "days", + "triggerAtHour": 9 + } + ] + } + }, + "id": "daily-schedule", + "name": "Every day 09:00", + "type": "n8n-nodes-base.scheduleTrigger", + "typeVersion": 1.2, + "position": [ + -80, + 0 + ] + }, + { + "parameters": { + "url": "https://www.youtube.com/feeds/videos.xml?channel_id=YOUR_CHANNEL_ID", + "options": {} + }, + "id": "channel-rss", + "name": "Channel RSS feed", + "type": "n8n-nodes-base.rssFeedRead", + "typeVersion": 1.1, + "position": [ + 140, + 0 + ] + }, + { + "parameters": { + "jsCode": "// One video per run: the newest video we have not processed yet.\n// A fresh upload is by definition the newest unprocessed one, so new\n// uploads win automatically; with nothing new, the back catalog drains\n// newest-first. Processed links persist in workflow static data\n// (production executions only \u2014 manual test runs do not save it).\nconst staticData = $getWorkflowStaticData('global');\nconst done = staticData.processedVideos || [];\nconst videos = $input.all().map((i) => i.json);\nconst fresh = videos.filter((v) => v.link && !done.includes(v.link));\nif (fresh.length === 0) {\n return [];\n}\nconst pick = fresh[0];\nreturn [{ json: { url: pick.link, title: pick.title, published: pick.isoDate } }];" + }, + "id": "pick-video", + "name": "Pick next video", + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [ + 360, + 0 + ] + }, + { + "parameters": { + "method": "POST", + "url": "https://api.openshorts.app/api/process", + "authentication": "genericCredentialType", + "genericAuthType": "httpHeaderAuth", + "sendBody": true, + "specifyBody": "json", + "jsonBody": "={\n \"url\": \"{{ $json.url }}\",\n \"acknowledged\": true,\n \"webhook_url\": \"PASTE_THE_PRODUCTION_URL_OF_THE_CLIPS-READY_WEBHOOK_NODE_HERE\",\n \"webhook_secret\": \"change-me\"\n}", + "options": {} + }, + "id": "start-job", + "name": "Start OpenShorts job", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4.2, + "position": [ + 580, + 0 + ], + "onError": "continueErrorOutput", + "credentials": { + "httpHeaderAuth": { + "name": "OpenShorts API key" + } + } + }, + { + "parameters": { + "jsCode": "// Only mark the video done once OpenShorts accepted the job \u2014 a failed\n// submit (quota, downtime) leaves it unmarked so tomorrow retries it.\nconst staticData = $getWorkflowStaticData('global');\nconst done = staticData.processedVideos || [];\nconst url = $('Pick next video').first().json.url;\nif (!done.includes(url)) {\n done.push(url);\n}\nstaticData.processedVideos = done;\nreturn $input.all();" + }, + "id": "mark-processed", + "name": "Mark video as processed", + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [ + 800, + -60 + ] + }, + { + "parameters": { + "chatId": "YOUR_TELEGRAM_CHAT_ID", + "text": "=\ud83c\udfac Clipping started: {{ $('Pick next video').first().json.title }}\n\nI'll send the clips here for approval when they're ready.", + "additionalFields": {} + }, + "id": "tg-clipping", + "name": "Notify: clipping started", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1.2, + "position": [ + 1020, + -60 + ], + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + } + }, + { + "parameters": { + "chatId": "YOUR_TELEGRAM_CHAT_ID", + "text": "\u26a0\ufe0f Autopilot paused: OpenShorts rejected the job (most likely you're out of minutes this month). The video was NOT marked as processed, so it will be retried tomorrow. Top up or upgrade at https://www.openshorts.app/", + "additionalFields": {} + }, + "id": "tg-quota", + "name": "Notify: out of minutes", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1.2, + "position": [ + 800, + 120 + ], + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + } + }, + { + "parameters": { + "content": "## ACT 2 \u2014 Clips arrive on your phone\n\n**No polling, no Wait-node loop.** OpenShorts calls this webhook once per job (success **and** failure, so nothing ever hangs). Each finished 9:16 clip lands in your Telegram with two buttons: \u2705 publish or \u274c skip \u2014 a human approves every post, which is also what keeps you on the right side of YouTube's inauthentic-content policy.\n\n**Setup**: copy the **production** URL of the *Clips ready* webhook node and paste it as `webhook_url` inside *Start OpenShorts job*. Telegram fetches videos by URL up to ~20 MB; bigger clips fall back to a message with the download link and the same buttons.", + "height": 380, + "width": 400, + "color": 5 + }, + "id": "note-act2", + "name": "Act 2 note", + "type": "n8n-nodes-base.stickyNote", + "typeVersion": 1, + "position": [ + -560, + 340 + ] + }, + { + "parameters": { + "httpMethod": "POST", + "path": "openshorts-machine-clips", + "options": {} + }, + "id": "clips-webhook", + "name": "Clips ready (webhook)", + "type": "n8n-nodes-base.webhook", + "typeVersion": 2, + "position": [ + -80, + 440 + ], + "webhookId": "30f3bc66-1f03-4d2f-94b8-aed49571238d" + }, + { + "parameters": { + "conditions": { + "options": { + "caseSensitive": true, + "typeValidation": "strict", + "version": 2 + }, + "conditions": [ + { + "id": "c1", + "leftValue": "={{ $json.body.event }}", + "rightValue": "job.completed", + "operator": { + "type": "string", + "operation": "equals" + } + } + ], + "combinator": "and" + }, + "options": {} + }, + "id": "if-completed", + "name": "Job completed?", + "type": "n8n-nodes-base.if", + "typeVersion": 2.2, + "position": [ + 140, + 440 + ] + }, + { + "parameters": { + "jsCode": "// One Telegram message per clip, carrying everything the approval\n// buttons need inside callback_data (Telegram caps it at 64 bytes:\n// action|job_id|clip_index fits).\nconst body = $json.body;\nreturn (body.clips || []).map((clip, i) => ({\n json: {\n job_id: body.job_id,\n clip_index: i,\n title: clip.title || `Clip ${i + 1}`,\n download_url: clip.download_url || clip.video_url,\n },\n}));" + }, + "id": "split-clips", + "name": "One item per clip", + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [ + 360, + 380 + ] + }, + { + "parameters": { + "operation": "sendVideo", + "chatId": "YOUR_TELEGRAM_CHAT_ID", + "file": "={{ $json.download_url }}", + "replyMarkup": "inlineKeyboard", + "inlineKeyboard": { + "rows": [ + { + "row": { + "buttons": [ + { + "text": "\u2705 Publish", + "additionalFields": { + "callback_data": "=pub|{{ $json.job_id }}|{{ $json.clip_index }}" + } + }, + { + "text": "\u274c Skip", + "additionalFields": { + "callback_data": "skip" + } + } + ] + } + } + ] + }, + "additionalFields": { + "caption": "={{ $json.title }}" + } + }, + "id": "tg-clip-video", + "name": "Send clip for approval", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1.2, + "position": [ + 580, + 380 + ], + "onError": "continueErrorOutput", + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + } + }, + { + "parameters": { + "chatId": "YOUR_TELEGRAM_CHAT_ID", + "text": "=\ud83c\udfac {{ $json.title }}\n\nToo big for Telegram preview \u2014 watch it here:\n{{ $json.download_url }}", + "replyMarkup": "inlineKeyboard", + "inlineKeyboard": { + "rows": [ + { + "row": { + "buttons": [ + { + "text": "\u2705 Publish", + "additionalFields": { + "callback_data": "=pub|{{ $json.job_id }}|{{ $json.clip_index }}" + } + }, + { + "text": "\u274c Skip", + "additionalFields": { + "callback_data": "skip" + } + } + ] + } + } + ] + }, + "additionalFields": {} + }, + "id": "tg-clip-link", + "name": "Send clip link instead", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1.2, + "position": [ + 800, + 480 + ], + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + } + }, + { + "parameters": { + "chatId": "YOUR_TELEGRAM_CHAT_ID", + "text": "=\u274c OpenShorts job failed: {{ $json.body.error || 'unknown error' }}\n\nNothing was published. The machine keeps running tomorrow.", + "additionalFields": {} + }, + "id": "tg-job-failed", + "name": "Notify: job failed", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1.2, + "position": [ + 360, + 560 + ], + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + } + }, + { + "parameters": { + "content": "## ACT 3 \u2014 Tap \u2705, it gets scheduled\n\nThe Telegram trigger listens for the approval buttons. Every approved clip is scheduled through OpenShorts (which posts to every social account you connected there \u2014 TikTok, Instagram, YouTube) at a rate of **one post per day**: approve five clips today and you just filled five days of content.\n\n**Setup**: none beyond the Telegram credential \u2014 the chat id comes from the button tap itself. Change the platforms list in *Schedule social post* if you want fewer networks.", + "height": 380, + "width": 400, + "color": 6 + }, + "id": "note-act3", + "name": "Act 3 note", + "type": "n8n-nodes-base.stickyNote", + "typeVersion": 1, + "position": [ + -560, + 800 + ] + }, + { + "parameters": { + "updates": [ + "callback_query" + ], + "additionalFields": {} + }, + "id": "tg-trigger", + "name": "Approval buttons", + "type": "n8n-nodes-base.telegramTrigger", + "typeVersion": 1.2, + "position": [ + -80, + 900 + ], + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + }, + "webhookId": "906a710d-3e76-4911-b7e6-f336e6da5d66" + }, + { + "parameters": { + "jsCode": "const cb = $json.callback_query || {};\nconst [action, jobId, clipIndex] = String(cb.data || '').split('|');\nreturn [{\n json: {\n action: action || 'skip',\n job_id: jobId || '',\n clip_index: parseInt(clipIndex || '0', 10),\n chat_id: cb.message && cb.message.chat ? cb.message.chat.id : null,\n clip_title: cb.message ? (cb.message.caption || '') : '',\n },\n}];" + }, + "id": "parse-button", + "name": "Parse button", + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [ + 140, + 900 + ] + }, + { + "parameters": { + "conditions": { + "options": { + "caseSensitive": true, + "typeValidation": "strict", + "version": 2 + }, + "conditions": [ + { + "id": "c2", + "leftValue": "={{ $json.action }}", + "rightValue": "pub", + "operator": { + "type": "string", + "operation": "equals" + } + } + ], + "combinator": "and" + }, + "options": {} + }, + "id": "if-approved", + "name": "Approved?", + "type": "n8n-nodes-base.if", + "typeVersion": 2.2, + "position": [ + 360, + 900 + ] + }, + { + "parameters": { + "jsCode": "// One post per day: each approval takes the next free daily slot, so a\n// batch of approvals turns into a steady drip instead of a burst.\nconst staticData = $getWorkflowStaticData('global');\nconst now = Date.now();\nconst last = staticData.lastScheduledAt || 0;\nconst slot = Math.max(now + 10 * 60 * 1000, last + 24 * 60 * 60 * 1000);\nstaticData.lastScheduledAt = slot;\nconst item = $input.first().json;\nreturn [{ json: { ...item, scheduled_date: new Date(slot).toISOString() } }];" + }, + "id": "reserve-slot", + "name": "Reserve daily slot", + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [ + 580, + 840 + ] + }, + { + "parameters": { + "method": "POST", + "url": "https://api.openshorts.app/api/social/post", + "authentication": "genericCredentialType", + "genericAuthType": "httpHeaderAuth", + "sendBody": true, + "specifyBody": "json", + "jsonBody": "={\n \"job_id\": \"{{ $json.job_id }}\",\n \"clip_index\": {{ $json.clip_index }},\n \"platforms\": [\"tiktok\", \"instagram\", \"youtube\"],\n \"scheduled_date\": \"{{ $json.scheduled_date }}\",\n \"timezone\": \"UTC\"\n}", + "options": {} + }, + "id": "social-post", + "name": "Schedule social post", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4.2, + "position": [ + 800, + 840 + ], + "onError": "continueErrorOutput", + "credentials": { + "httpHeaderAuth": { + "name": "OpenShorts API key" + } + } + }, + { + "parameters": { + "chatId": "={{ $('Parse button').first().json.chat_id }}", + "text": "=\ud83d\udcc5 Scheduled! Going out to your connected accounts on {{ $('Reserve daily slot').first().json.scheduled_date.slice(0, 10) }}.", + "additionalFields": {} + }, + "id": "tg-scheduled", + "name": "Confirm: scheduled", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1.2, + "position": [ + 1020, + 780 + ], + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + } + }, + { + "parameters": { + "chatId": "={{ $('Parse button').first().json.chat_id }}", + "text": "=\u26a0\ufe0f Could not schedule that clip: {{ $json.error && $json.error.message ? $json.error.message : 'posting failed' }}. Make sure your social accounts are connected in your OpenShorts account page.", + "additionalFields": {} + }, + "id": "tg-post-failed", + "name": "Confirm: posting failed", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1.2, + "position": [ + 1020, + 900 + ], + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + } + }, + { + "parameters": { + "chatId": "={{ $('Parse button').first().json.chat_id }}", + "text": "\ud83d\uddd1 Skipped. It stays in your OpenShorts dashboard if you change your mind.", + "additionalFields": {} + }, + "id": "tg-skipped", + "name": "Confirm: skipped", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1.2, + "position": [ + 580, + 980 + ], + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + } + }, + { + "parameters": { + "content": "## ACT 4 \u2014 The feedback loop: learn what worked\n\nOnce a week the machine reads the analytics of everything it published (via the OpenShorts analytics API, which aggregates TikTok/Instagram/YouTube numbers) and sends you the verdict: total impressions, per-platform split, and your best post.\n\nThe machine that posts is the machine that measures \u2014 so every approval you make next week is informed by what actually landed. Close the loop further by feeding your winners back as examples in your clip prompts.", + "height": 340, + "width": 400, + "color": 3 + }, + "id": "note-act4", + "name": "Act 4 note", + "type": "n8n-nodes-base.stickyNote", + "typeVersion": 1, + "position": [ + -560, + 1260 + ] + }, + { + "parameters": { + "rule": { + "interval": [ + { + "field": "weeks", + "triggerAtDay": [ + 0 + ], + "triggerAtHour": 18 + } + ] + } + }, + "id": "weekly-schedule", + "name": "Every Sunday 18:00", + "type": "n8n-nodes-base.scheduleTrigger", + "typeVersion": 1.2, + "position": [ + -80, + 1360 + ] + }, + { + "parameters": { + "url": "https://api.openshorts.app/api/social/analytics/impressions", + "authentication": "genericCredentialType", + "genericAuthType": "httpHeaderAuth", + "sendQuery": true, + "queryParameters": { + "parameters": [ + { + "name": "period", + "value": "last_week" + }, + { + "name": "breakdown", + "value": "true" + } + ] + }, + "options": {} + }, + "id": "weekly-impressions", + "name": "Weekly impressions", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4.2, + "position": [ + 140, + 1360 + ], + "credentials": { + "httpHeaderAuth": { + "name": "OpenShorts API key" + } + } + }, + { + "parameters": { + "url": "https://api.openshorts.app/api/social/analytics/posts", + "authentication": "genericCredentialType", + "genericAuthType": "httpHeaderAuth", + "sendQuery": true, + "queryParameters": { + "parameters": [ + { + "name": "since", + "value": "={{ $now.minus({ days: 7 }).toFormat('yyyy-MM-dd') }}" + } + ] + }, + "options": {} + }, + "id": "weekly-posts", + "name": "Per-post metrics", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4.2, + "position": [ + 360, + 1360 + ], + "credentials": { + "httpHeaderAuth": { + "name": "OpenShorts API key" + } + } + }, + { + "parameters": { + "jsCode": "// Turn the two analytics responses into one human digest message.\nconst impressions = $('Weekly impressions').first().json || {};\nconst postsResp = $input.first().json || {};\nconst posts = postsResp.posts || postsResp.data || postsResp.items || [];\n\nconst views = (post) => {\n const m = post.post_metrics || post.metrics || post;\n return Number(m.views || m.impressions || m.plays || 0);\n};\n\nconst total = impressions.total_impressions || posts.reduce((s, p) => s + views(p), 0);\nconst sorted = [...posts].sort((a, b) => views(b) - views(a));\nconst best = sorted[0];\n\nconst perPlatform = impressions.per_platform\n ? Object.entries(impressions.per_platform)\n .map(([p, v]) => ` \u2022 ${p}: ${Number(v).toLocaleString('en-US')}`)\n .join('\\n')\n : '';\n\nlet text = `\ud83d\udcca Your week on autopilot\\n\\n`;\ntext += `Posts published: ${posts.length}\\n`;\ntext += `Total impressions: ${Number(total).toLocaleString('en-US')}\\n`;\nif (perPlatform) {\n text += `${perPlatform}\\n`;\n}\nif (best && views(best) > 0) {\n const title = best.title || best.caption || best.platform_post_id || 'your top post';\n text += `\\n\ud83c\udfc6 Best post: \"${title}\" \u2014 ${views(best).toLocaleString('en-US')} views`;\n}\nif (posts.length === 0) {\n text += `\\nNothing published this week. Approve some clips and the machine does the rest.`;\n}\nreturn [{ json: { digest: text } }];" + }, + "id": "write-digest", + "name": "Write the digest", + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [ + 580, + 1360 + ] + }, + { + "parameters": { + "chatId": "YOUR_TELEGRAM_CHAT_ID", + "text": "={{ $json.digest }}", + "additionalFields": {} + }, + "id": "tg-digest", + "name": "Send weekly digest", + "type": "n8n-nodes-base.telegram", + "typeVersion": 1.2, + "position": [ + 800, + 1360 + ], + "credentials": { + "telegramApi": { + "name": "Telegram bot" + } + } + } + ], + "connections": { + "Every day 09:00": { + "main": [ + [ + { + "node": "Channel RSS feed", + "type": "main", + "index": 0 + } + ] + ] + }, + "Channel RSS feed": { + "main": [ + [ + { + "node": "Pick next video", + "type": "main", + "index": 0 + } + ] + ] + }, + "Pick next video": { + "main": [ + [ + { + "node": "Start OpenShorts job", + "type": "main", + "index": 0 + } + ] + ] + }, + "Start OpenShorts job": { + "main": [ + [ + { + "node": "Mark video as processed", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Notify: out of minutes", + "type": "main", + "index": 0 + } + ] + ] + }, + "Mark video as processed": { + "main": [ + [ + { + "node": "Notify: clipping started", + "type": "main", + "index": 0 + } + ] + ] + }, + "Clips ready (webhook)": { + "main": [ + [ + { + "node": "Job completed?", + "type": "main", + "index": 0 + } + ] + ] + }, + "Job completed?": { + "main": [ + [ + { + "node": "One item per clip", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Notify: job failed", + "type": "main", + "index": 0 + } + ] + ] + }, + "One item per clip": { + "main": [ + [ + { + "node": "Send clip for approval", + "type": "main", + "index": 0 + } + ] + ] + }, + "Send clip for approval": { + "main": [ + [], + [ + { + "node": "Send clip link instead", + "type": "main", + "index": 0 + } + ] + ] + }, + "Approval buttons": { + "main": [ + [ + { + "node": "Parse button", + "type": "main", + "index": 0 + } + ] + ] + }, + "Parse button": { + "main": [ + [ + { + "node": "Approved?", + "type": "main", + "index": 0 + } + ] + ] + }, + "Approved?": { + "main": [ + [ + { + "node": "Reserve daily slot", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Confirm: skipped", + "type": "main", + "index": 0 + } + ] + ] + }, + "Reserve daily slot": { + "main": [ + [ + { + "node": "Schedule social post", + "type": "main", + "index": 0 + } + ] + ] + }, + "Schedule social post": { + "main": [ + [ + { + "node": "Confirm: scheduled", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Confirm: posting failed", + "type": "main", + "index": 0 + } + ] + ] + }, + "Every Sunday 18:00": { + "main": [ + [ + { + "node": "Weekly impressions", + "type": "main", + "index": 0 + } + ] + ] + }, + "Weekly impressions": { + "main": [ + [ + { + "node": "Per-post metrics", + "type": "main", + "index": 0 + } + ] + ] + }, + "Per-post metrics": { + "main": [ + [ + { + "node": "Write the digest", + "type": "main", + "index": 0 + } + ] + ] + }, + "Write the digest": { + "main": [ + [ + { + "node": "Send weekly digest", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "settings": { + "executionOrder": "v1" + }, + "pinData": {} +} \ No newline at end of file