{
  "name": "Telegram to PostSider",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "id": "00000000-0000-4000-8000-000000000001",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.5,
      "position": [
        0,
        0
      ],
      "credentials": {
        "telegramApi": {
          "id": "4",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "00000000-0000-4000-8000-000000000002",
              "name": "idea",
              "value": "={{ $json.message.text }}",
              "type": "string"
            },
            {
              "id": "00000000-0000-4000-8000-000000000003",
              "name": "tone",
              "value": "confident and friendly",
              "type": "string"
            },
            {
              "id": "00000000-0000-4000-8000-000000000004",
              "name": "mode",
              "value": "approval",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "00000000-0000-4000-8000-000000000005",
      "name": "1. Post idea",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "00000000-0000-4000-8000-000000000006",
              "leftValue": "={{ ($json.mode || '').toLowerCase() }}",
              "rightValue": "approval",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "00000000-0000-4000-8000-000000000007",
      "name": "2. Mode?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.postsider.com/public/v1/find-slot/[YOUR POSTSIDER CHANNEL ID]"
      },
      "id": "00000000-0000-4000-8000-000000000008",
      "name": "3a. Find best slot",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        -180
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "1",
          "name": "PostSider API Key"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"temperature\": 0.8,\n  \"messages\": [\n    { \"role\": \"system\", \"content\": \"You write social media posts for your chosen platform. Rules: Match the platform tone and limits. If the topic is a simple command like \"post this\", write a short clean post. Respond with the post text only.\" },\n    { \"role\": \"user\", \"content\": \"Topic: {{ $('1. Post idea').first().json.idea }}. Tone: {{ $('1. Post idea').first().json.tone }}. Write the post.\" }\n  ]\n}"
      },
      "id": "00000000-0000-4000-8000-000000000009",
      "name": "4a. Generate post (AI)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        -180
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "2",
          "name": "OpenAI API Key"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const slot = $('3a. Find best slot').first().json; // { date } UTC, append 'Z'\nconst ai = $input.first().json;\nconst content = (ai.choices?.[0]?.message?.content || '').trim();\nreturn [{\n  json: {\n    body: {\n      type: 'draft',\n      date: slot.date + 'Z',\n      shortLink: false,\n      tags: [],\n      posts: [{\n        integration: { id: '[YOUR POSTSIDER CHANNEL ID]' },\n        value: [{ content, image: [] }],\n        settings: {\"__type\":\"[YOUR PLATFORM TYPE, e.g. x or linkedin]\"}\n      }]\n    }\n  }\n}];"
      },
      "id": "00000000-0000-4000-8000-000000000010",
      "name": "5a. Build draft",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        -180
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.postsider.com/public/v1/posts",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.body) }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "=ps-{{ $now.toISO() }}"
            }
          ]
        }
      },
      "id": "00000000-0000-4000-8000-000000000011",
      "name": "6a. Create draft",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        -180
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "1",
          "name": "PostSider API Key"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.postsider.com/public/v1/posts/{{ $json.postId }}/request-approval"
      },
      "id": "00000000-0000-4000-8000-000000000012",
      "name": "7a. Request approval",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1540,
        -180
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "1",
          "name": "PostSider API Key"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"temperature\": 0.8,\n  \"messages\": [\n    { \"role\": \"system\", \"content\": \"You write social media posts for your chosen platform. Rules: Match the platform tone and limits. If the topic is a simple command like \"post this\", write a short clean post. Respond with the post text only.\" },\n    { \"role\": \"user\", \"content\": \"Topic: {{ $('1. Post idea').first().json.idea }}. Tone: {{ $('1. Post idea').first().json.tone }}. Write the post.\" }\n  ]\n}"
      },
      "id": "00000000-0000-4000-8000-000000000013",
      "name": "4b. Generate post (AI)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        180
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "2",
          "name": "OpenAI API Key"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const ai = $input.first().json;\nconst content = (ai.choices?.[0]?.message?.content || '').trim();\nreturn [{\n  json: {\n    body: {\n      type: 'now',\n      date: '',\n      shortLink: false,\n      tags: [],\n      posts: [{\n        integration: { id: '[YOUR POSTSIDER CHANNEL ID]' },\n        value: [{ content, image: [] }],\n        settings: { __type: '[YOUR PLATFORM TYPE, e.g. x or linkedin]' }\n      }]\n    }\n  }\n}];"
      },
      "id": "00000000-0000-4000-8000-000000000014",
      "name": "5b. Build post",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        180
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.postsider.com/public/v1/posts",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.body) }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "=ps-{{ $now.toISO() }}"
            }
          ]
        }
      },
      "id": "00000000-0000-4000-8000-000000000015",
      "name": "6b. Publish now",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        180
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "1",
          "name": "PostSider API Key"
        }
      }
    },
    {
      "parameters": {
        "content": "WHAT THIS DOES\nPost from your phone: send a message to your Telegram bot and the AI turns it into a post published through PostSider, immediately (mode = \"now\") or via the approval queue (mode = \"approval\").\n\nSETUP (once, about 5 minutes)\n1. Create a Telegram bot with @BotFather and copy its token.\n2. In n8n create a Telegram account credential (the bot token) and select it on the \"Telegram Trigger\".\n3. PostSider API key: app.postsider.com > Settings > API > Create key (ps_...).\n4. n8n credentials (Header Auth): \"PostSider API Key\" (Authorization = ps_...) and \"OpenAI API Key\" (Authorization = Bearer sk-...).\n5. Replace [YOUR POSTSIDER CHANNEL ID] with a real channel id (app > Settings > Channels).\n6. Replace [YOUR PLATFORM TYPE, e.g. x or linkedin] in the Build nodes with the platform type of that channel (x, linkedin, facebook, instagram, ...).\n7. Activate the workflow, open Telegram and message your bot.\n\nHOW TO RUN\n1. In Telegram, message your bot something like: \"Our new n8n workflows are live\".\n2. The AI writes the post and PostSider publishes it (or queues it for approval).\n\nSELF-HOSTED POSTSIDER\nReplace api.postsider.com with your domain; add /api if your install serves the API under /api.",
        "height": 720,
        "width": 620,
        "color": 3
      },
      "id": "00000000-0000-4000-8000-000000000016",
      "name": "How to use",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -460
      ]
    },
    {
      "parameters": {
        "content": "SETUP STEP BY STEP\nFollow in order. Do this once per workflow.\n\nSTEP 1 - Create a Telegram bot (5 min):\n  Open Telegram, message @BotFather, send /newbot, follow the prompts. Copy the token it gives you.\n\nSTEP 2 - Create the n8n credentials:\n  a. \"Telegram account\" (Telegram API): paste the bot token from BotFather.\n  b. \"PostSider API Key\" (Header Auth): Name = Authorization, Value = your ps_ key (app.postsider.com > Settings > API > Create key).\n  c. \"OpenAI API Key\" (Header Auth): Name = Authorization, Value = Bearer sk-... (platform.openai.com).\n\nSTEP 3 - \"Telegram Trigger\":\n  Select the \"Telegram account\" credential. Trigger On = Message.\n\nSTEP 4 - Select the \"PostSider API Key\" credential on:\n  - \"3a. Find best slot\"\n  - \"6a. Create draft\"\n  - \"7a. Request approval\"\n  - \"6b. Publish now\"\n\nSTEP 5 - Select the \"OpenAI API Key\" credential on:\n  - \"4a. Generate post (AI)\"\n  - \"4b. Generate post (AI)\"\n\nSTEP 6 - Replace the channel id:\n  Replace [YOUR POSTSIDER CHANNEL ID] in \"3a. Find best slot\", \"5a. Build draft\", \"5b. Build post\" and \"6b. Publish now\" with your real channel id (app > Settings > Channels).\n\nSTEP 7 - Replace the platform type:\n  Replace [YOUR PLATFORM TYPE, e.g. x or linkedin] in \"5a. Build draft\" and \"5b. Build post\" with the type of that channel (x, linkedin, facebook, instagram, ...).\n\nSTEP 8 - Run:\n  Activate the workflow. Message your bot in Telegram: the AI writes the post and PostSider publishes it (or queues it for approval when mode = \"approval\").",
        "height": 780,
        "width": 640,
        "color": 3
      },
      "id": "00000000-0000-4000-8000-000000000017",
      "name": "Setup step by step",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -1260
      ]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "1. Post idea",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1. Post idea": {
      "main": [
        [
          {
            "node": "2. Mode?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2. Mode?": {
      "main": [
        [
          {
            "node": "3a. Find best slot",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "4b. Generate post (AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3a. Find best slot": {
      "main": [
        [
          {
            "node": "4a. Generate post (AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4a. Generate post (AI)": {
      "main": [
        [
          {
            "node": "5a. Build draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5a. Build draft": {
      "main": [
        [
          {
            "node": "6a. Create draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6a. Create draft": {
      "main": [
        [
          {
            "node": "7a. Request approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4b. Generate post (AI)": {
      "main": [
        [
          {
            "node": "5b. Build post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5b. Build post": {
      "main": [
        [
          {
            "node": "6b. Publish now",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "active": false,
  "tags": [
    "PostSider",
    "Telegram",
    "AI",
    "Automation"
  ]
}