{
  "id": "sSq3OBOGly6oGT5M",
  "name": "AI-Powered Morning Haiku Generator (Google Docs + Gmail)",
  "tags": [],
  "nodes": [
    {
      "id": "c2c25ff3-8044-40c1-9a0f-08e469f42250",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        16,
        144
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 7
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b86d8fbd-7154-43f0-a722-e22ca8ac170a",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        592,
        144
      ],
      "parameters": {
        "jsCode": "// \u524d\u306eAI Agent\u30ce\u30fc\u30c9\u304b\u3089\u51fa\u529b\u3092\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002\n// \u30c7\u30fc\u30bf\u306f 'output' \u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5165\u3063\u3066\u3044\u307e\u3059\u3002\nlet aiResponse = $node[\"AI Agent\"].json.output;\n\n// AI\u306e\u5fdc\u7b54\u306b```json ... ```\u306e\u3088\u3046\u306a\u4f59\u5206\u306a\u6587\u5b57\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u5834\u5408\u3001\n// \u4e2d\u8eab\u306eJSON\u90e8\u5206\u3060\u3051\u3092\u62bd\u51fa\u3057\u307e\u3059\u3002\nif (aiResponse.includes('```')) {\n  aiResponse = aiResponse.substring(aiResponse.indexOf('{'), aiResponse.lastIndexOf('}') + 1);\n}\n\n// JSON\u6587\u5b57\u5217\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u63db\u3057\u307e\u3059\u3002\nconst words = JSON.parse(aiResponse);\n\n// AI\u304c\u751f\u6210\u3057\u305f\u5358\u8a9e\u3092\u4f7f\u3063\u3066\u30015-7-5\u8abf\u306e\u4ff3\u53e5\u3092\u7d44\u307f\u7acb\u3066\u307e\u3059\u3002\nconst line1 = `${words.kigo}\u306e\u4e2d`;\nconst line2 = `${words.noun}\u3067\u5fc3\u304c${words.verb1}`;\nconst line3 = `\u4eca\u65e5\u3082\u307e\u305f${words.verb2}`;\n\nconst haiku = `${line1}\\n${line2}\\n${line3}`;\n\n// \u30bf\u30a4\u30c8\u30eb\u3092\u751f\u6210\u3057\u3001haiku\u3068\u4e00\u7dd2\u306b\u5f8c\u7d9a\u306e\u30ce\u30fc\u30c9\u3078\u6e21\u3057\u307e\u3059\u3002\nconst title = `\u4eca\u65e5\u306e\u4e00\u53e5 (${new Date().toLocaleDateString('ja-JP')})`; // \u2190 \u3053\u3053\u306e\u30bf\u30a4\u30d7\u30df\u30b9\u3092\u4fee\u6b63\n\nreturn [{\n  json: {\n    haiku,\n    title\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "8da62bb5-391d-40ad-a9e3-e8a50f3d2983",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        816,
        144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "774b47ef-875a-4f9f-9530-51ae0720ae44",
              "name": "documentTitle",
              "type": "string",
              "value": "={{ $json.title }}"
            },
            {
              "id": "66d74b89-e9f5-4982-ae66-e5fb18b10993",
              "name": "documentBody",
              "type": "string",
              "value": "={{ \"# \" + $json.title + \"\\n\\n\" + $json.haiku + \"\\n\\n$2014 n8n Haiku Generator\" }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "f21266fa-3226-443f-a84d-a958497a5948",
      "name": "Create a document",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        1040,
        144
      ],
      "parameters": {
        "title": "={{ $node[\"Edit Fields\"].json.documentTitle ?? '\u4eca\u65e5\u306e\u4e00\u53e5' }}\n",
        "folderId": "1W45ugKiRbbwp3FIFdLL690DAgkVKCKWB"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d9b2fbbb-341f-4d20-b493-c48e7c1e56d7",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1712,
        144
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "={{ $node[\"Code in JavaScript\"].json.haiku + \"\\n\\n$2014 \u672c\u65e5\u306e\u4ff3\u53e5\u3092\u304a\u5c4a\u3051\u3057\u307e\u3059 $2600$FE0F\" }}",
        "options": {},
        "subject": "={{ $node[\"Edit Fields\"].json.documentTitle }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "745a8e10-7393-42e1-8d01-3808d5c0553a",
      "name": "Prepare Append",
      "type": "n8n-nodes-base.set",
      "position": [
        1264,
        144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e4fc8729-a49f-42b4-a626-8e15ed84d7fc",
              "name": "docId",
              "type": "string",
              "value": "={{ $node[\"Create a document\"].json.id }}"
            },
            {
              "id": "469d4459-0ec7-4cbd-8bd7-f32853d7e3a8",
              "name": "text",
              "type": "string",
              "value": "={{ $node[\"Edit Fields\"].json.documentBody }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "5f7c8ef7-bd1a-4987-a976-69924d084c33",
      "name": "Update a document",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        1488,
        144
      ],
      "parameters": {
        "actionsUi": {
          "actionFields": [
            {
              "text": "={{ $node[\"Prepare Append\"].json.text }}",
              "action": "insert"
            }
          ]
        },
        "operation": "update",
        "documentURL": "={{ $node[\"Prepare Append\"].json.docId }}"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c0b48c24-42be-45ca-959d-ef0d439b38cd",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        240,
        144
      ],
      "parameters": {
        "text": "\u3042\u306a\u305f\u306f\u5275\u9020\u7684\u306a\u4ff3\u4eba\u3067\u3059\u3002\n\u4ff3\u53e5\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u306e\u90e8\u54c1\u3068\u306a\u308b\u5358\u8a9e\u30924\u3064\u3001JSON\u5f62\u5f0f\u3067\u63d0\u6848\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\n- kigo: \u73fe\u5728\u306e\u5b63\u7bc0\u306b\u5408\u3063\u305f\u7f8e\u3057\u3044\u5b63\u8a9e\u30921\u3064\n- noun: \u60c5\u666f\u304c\u6d6e\u304b\u3076\u3088\u3046\u306a\u540d\u8a5e\u30921\u3064\n- verb1: \u52d5\u4f5c\u3084\u72b6\u614b\u3092\u8868\u3059\u52d5\u8a5e\u30921\u3064\n- verb2: 1\u3064\u76ee\u306e\u52d5\u8a5e\u3068\u306f\u7570\u306a\u308b\u3001\u4f59\u97fb\u3092\u6b8b\u3059\u3088\u3046\u306a\u52d5\u8a5e\u3092\u3082\u30461\u3064\n\n\u8aac\u660e\u3084\u4f59\u8a08\u306a\u30c6\u30ad\u30b9\u30c8\u306f\u4e00\u5207\u542b\u3081\u305a\u3001\u5fc5\u305a\u4ee5\u4e0b\u306eJSON\u5f62\u5f0f\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u3001\u30ad\u30fc\u3082\u82f1\u8a9e\u3067\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044:\n{\n  \"kigo\": \"\u3053\u3053\u306b\u5b63\u8a9e\",\n  \"noun\": \"\u3053\u3053\u306b\u540d\u8a5e\",\n  \"verb1\": \"\u3053\u3053\u306b\u52d5\u8a5e1\",\n  \"verb2\": \"\u3053\u3053\u306b\u52d5\u8a5e2\"\n}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "a39e75bc-a06d-4dfd-a521-579a5bd34838",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        312,
        368
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b3378d42-0e19-4103-ad86-b0f67399a29d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        -384
      ],
      "parameters": {
        "width": 400,
        "height": 512,
        "content": "## Overview: AI-Powered Morning Haiku Generator\n\n## How it works\nThis workflow automatically creates and emails a morning haiku every day at 7:00 AM.\nIt uses OpenRouter AI to generate four creative words $2014 a seasonal word, a noun, and two verbs $2014 then builds a 5-7-5 haiku. The haiku is saved to Google Docs and delivered via Gmail as a daily poem.\n\n## Setup steps\nConnect your OpenRouter, Google Docs, and Gmail credentials.\nAdjust the schedule in the \u201cSchedule Trigger\u201d node (default: 07:00 AM).\nUpdate the email recipient in the \u201cSend a message\u201d node.\nOptionally change the Google Docs folder ID in \u201cCreate a document.\u201d"
      },
      "typeVersion": 1
    },
    {
      "id": "a50e624c-29f3-4e4e-bed8-ac023a2b5e4b",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -112
      ],
      "parameters": {
        "color": 7,
        "height": 240,
        "content": "### Section 1 $2014 Scheduling & AI Generation\n\n$D83D$DCC5 Schedule Trigger \u2192 AI Agent \u2192 OpenRouter Model\n\n\nGenerates haiku components \ndaily at 07:00 AM using OpenRouter AI. ($2248 40 words)"
      },
      "typeVersion": 1
    },
    {
      "id": "bf77288f-0b71-4552-898d-f21994175afd",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        256,
        -112
      ],
      "parameters": {
        "color": 7,
        "height": 240,
        "content": "### Section 2 $2014 Build and Format Haiku\n\n$D83D$DCBB Code in JavaScript \u2192 Edit Fields\n\nCombines AI outputs into a 5-7-5 haiku and sets the title and body text. ($2248 40 words)"
      },
      "typeVersion": 1
    },
    {
      "id": "f45248f1-6075-4fd4-a782-403a2f55c323",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        -112
      ],
      "parameters": {
        "color": 7,
        "height": 240,
        "content": "### Section 3 $2014 Google Docs Automation\n\n$D83D$DCC4 Create Document \u2192 Prepare Append \u2192 Update Document\n\nCreates a Google Doc for today\u2019s haiku and appends the new text daily. ($2248 35 words)"
      },
      "typeVersion": 1
    },
    {
      "id": "79cf9fc1-7420-4e28-a6df-9b6ff0de685e",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        768,
        -112
      ],
      "parameters": {
        "color": 7,
        "height": 240,
        "content": "### Section 4 $2014 Email Delivery\n\n$2709$FE0F Send a message (Gmail)\n\nSends the final haiku via email each morning with a warm greeting. ($2248 25 words)"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c8750437-c566-4ffc-aad7-874169a5d914",
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Create a document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Append": {
      "main": [
        [
          {
            "node": "Update a document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a document": {
      "main": [
        [
          {
            "node": "Prepare Append",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update a document": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}