Cron

Günlük 5 AI Paylaşımı (WordPress)

02 May 2026

Description

OpenRouter API ile yapay zeka içeriği oluşturup, her gün 5 kez belirli bir WordPress kategorisine otomatik gönderir. Sabit kullanıcı adı/şifre ile giriş yapılır, hata yakalama ve veri doğrulama içerir.

Setup Guide

1. n8n'de yeni bir workflow oluşturun.
2. Cron node'unu ekleyin ve "Every Day" → "At minutes: 0, 144, 288, 432, 576" (günde 5 kez) ayarlayın.
3. Set node ekleyin; "prompt" alanına AI içeriği için temel bir talimat girin (ör. "Yapay zeka ve teknoloji hakkında 300 kelimelik blog yazısı oluştur").
4. HTTP Request node ekleyin:
- Method: POST
- URL: https://openrouter.ai/api/v1/chat/completions
- Authentication: Header → "Authorization: Bearer <YOUR_OPENROUTER_API_KEY>"
- Body (JSON): {"model":"<MODEL_ID>","messages":[{"role":"user","content":{{$json["prompt"]}}}]}
- Response Format: JSON
5. Function node ekleyin; AI yanıtını alıp "title" ve "content" değişkenlerine ayırın ve boşluk kontrolü yapın.
6. WordPress node ekleyin (n8n’in WordPress entegrasyonu):
- Authentication: Basic Auth → Kullanıcı adı ve şifre girin.
- Operation: Create
- Title: {{$json["title"]}}
- Content: {{$json["content"]}}
- Status: publish
- Categories: Tek kategori ID'si (ör. 5)
7. Error Workflow oluşturun: herhangi bir node’da hata oluşursa "Error Workflow" node’una bağlayın, hatayı loglayın ve Slack/Email gibi bildirim gönderin.
8. Tüm node’ları bağlayın: Cron → Set → HTTP Request → Function → WordPress → (Success) → End; hatalar için Error Workflow.
9. Workflow’u kaydedin ve "Active" konumuna getirin.
10. Açık API anahtarınızı ve WordPress kimlik bilgilerinizi n8n Credentials bölümünde güvenli bir şekilde kaydedin.

Workflow Preview

Loading Visualization...

JSON Code

automation.json
{
    "nodes": [
        {
            "parameters": {
                "cronExpression": "0 *\/4 * * *",
                "timezone": "UTC"
            },
            "name": "Cron",
            "type": "n8n-nodes-base.cron",
            "typeVersion": 1,
            "position": [
                250,
                300
            ]
        },
        {
            "parameters": {
                "values": {
                    "string": [
                        {
                            "name": "prompt",
                            "value": "Yapay zeka ve teknoloji hakkında 300 kelimelik bir blog yazısı oluştur."
                        }
                    ]
                },
                "options": []
            },
            "name": "Set AI Prompt",
            "type": "n8n-nodes-base.set",
            "typeVersion": 2,
            "position": [
                450,
                300
            ]
        },
        {
            "parameters": {
                "authentication": "headerAuth",
                "url": "https:\/\/openrouter.ai\/api\/v1\/chat\/completions",
                "method": "POST",
                "jsonParameters": true,
                "options": {
                    "bodyContentType": "json"
                },
                "headerParametersJson": "={\"Authorization\":\"Bearer {{$env.OPENROUTER_API_KEY}}\"}",
                "bodyParametersJson": "={\"model\":\"{{ $env.OPENROUTER_MODEL_ID }}\",\"messages\":[{\"role\":\"user\",\"content\":{{$json[\"prompt\"]}}}]}"
            },
            "name": "OpenRouter Request",
            "type": "n8n-nodes-base.httpRequest",
            "typeVersion": 2,
            "position": [
                650,
                300
            ]
        },
        {
            "parameters": {
                "functionCode": "const response = items[0].json;\nif (!response.choices || !response.choices[0] || !response.choices[0].message) {\n  throw new Error('AI response malformed');\n}\nconst content = response.choices[0].message.content.trim();\n\/\/ Simple split: first line as title, rest as content\nconst lines = content.split('\\n');\nlet title = lines[0];\nlet body = lines.slice(1).join('\\n').trim();\nif (!title || !body) {\n  \/\/ fallback if format is different\n  title = 'AI Generated Post';\n  body = content;\n}\nreturn [{ json: { title, content: body } }];",
                "continueOnFail": false
            },
            "name": "Validate & Split",
            "type": "n8n-nodes-base.function",
            "typeVersion": 1,
            "position": [
                850,
                300
            ]
        },
        {
            "parameters": {
                "resource": "post",
                "operation": "create",
                "title": "={{$json[\"title\"]}}",
                "content": "={{$json[\"content\"]}}",
                "status": "publish",
                "categories": [
                    "5"
                ],
                "authentication": "basicAuth",
                "user": "{{$env.WP_USERNAME}}",
                "password": "{{$env.WP_PASSWORD}}",
                "url": "https:\/\/yourwordpresssite.com"
            },
            "name": "Create WP Post",
            "type": "n8n-nodes-base.wordpress",
            "typeVersion": 1,
            "position": [
                1050,
                300
            ]
        },
        {
            "parameters": {
                "errorWorkflow": true,
                "continueOnFail": false
            },
            "name": "Error Workflow",
            "type": "n8n-nodes-base.noOp",
            "typeVersion": 1,
            "position": [
                850,
                500
            ]
        }
    ],
    "connections": {
        "Cron": {
            "main": [
                [
                    {
                        "node": "Set AI Prompt",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Set AI Prompt": {
            "main": [
                [
                    {
                        "node": "OpenRouter Request",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "OpenRouter Request": {
            "main": [
                [
                    {
                        "node": "Validate & Split",
                        "type": "main",
                        "index": 0
                    }
                ]
            ],
            "error": [
                [
                    {
                        "node": "Error Workflow",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Validate & Split": {
            "main": [
                [
                    {
                        "node": "Create WP Post",
                        "type": "main",
                        "index": 0
                    }
                ]
            ],
            "error": [
                [
                    {
                        "node": "Error Workflow",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Create WP Post": {
            "main": [
                [
                    {
                        "node": "NoOp",
                        "type": "main",
                        "index": 0
                    }
                ]
            ],
            "error": [
                [
                    {
                        "node": "Error Workflow",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        }
    },
    "active": false,
    "settings": {
        "executionOrder": "v1"
    },
    "id": "1"
}