{
  "id": "vYPcNPEQKZxdQRgo",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Daily Task Reminder Bot For Telegram",
  "tags": [],
  "nodes": [
    {
      "id": "d085b82b-f923-4d83-941d-2020134b704e",
      "name": "Webhook - Receive Task",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -768,
        448
      ],
      "parameters": {
        "path": "task-YOUR_OPENAI_KEY_HERE-webhook",
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "090aecda-2c33-405d-a602-aaa55fd435cd",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -896,
        80
      ],
      "parameters": {
        "color": 4,
        "width": 380,
        "height": 500,
        "content": "## \ud83d\udce5 WEBHOOK ENTRY POINT\n\nThis webhook receives task creation requests from users.\n\n**Expected JSON Format:**\n```json\n{\n  \"userId\": \"user123\",\n  \"taskName\": \"Team Meeting\",\n  \"reminderTime\": \"2025-10-30T14:00:00Z\",\n  \"description\": \"Discuss Q4 goals\",\n  \"channel\": \"email\" // or \"slack\", \"telegram\"\n}\n```\n\n**Webhook URL:** Copy from webhook node settings"
      },
      "typeVersion": 1
    },
    {
      "id": "eb5810b6-3e18-4ef0-ae8c-e0cf1b3a6743",
      "name": "Validate Input",
      "type": "n8n-nodes-base.if",
      "position": [
        -304,
        448
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "validation-1",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.body.userId }}",
              "rightValue": ""
            },
            {
              "id": "validation-2",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.body.taskName }}",
              "rightValue": ""
            },
            {
              "id": "validation-3",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.body.reminderTime }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "27bf912f-31f5-411d-ae7a-0cf5d12c49b0",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -448,
        160
      ],
      "parameters": {
        "color": 5,
        "width": 408,
        "height": 424,
        "content": "## \u2705 INPUT VALIDATION\n\nChecks if required fields are present:\n- userId (required)\n- taskName (required)\n- reminderTime (required)\n- description (optional)\n- channel (optional)\n\nRoutes to error handler if validation fails."
      },
      "typeVersion": 1
    },
    {
      "id": "7a358fe1-7841-4533-bf48-bf1170d3aa22",
      "name": "Save Task to Database",
      "type": "n8n-nodes-base.postgres",
      "position": [
        128,
        352
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "="
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {},
          "schema": [],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "d39c06bd-11f1-4dd7-9213-c5e251845242",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 6,
        "width": 380,
        "height": 496,
        "content": "## \ud83d\udcbe DATABASE STORAGE\n\nStores task in PostgreSQL database.\n\n**Table Schema:**\n- id (serial, primary key)\n- user_id (varchar)\n- task_name (varchar)\n- reminder_time (timestamp)\n- description (text)\n- channel (varchar)\n- status (varchar)\n- created_at (timestamp)\n\n**Alternative:** Use Airtable, MongoDB, or MySQL"
      },
      "typeVersion": 1
    },
    {
      "id": "e76eb098-e71b-4689-9830-0ac1c59e46f4",
      "name": "Success Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        464,
        352
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "={{ {\n  \"success\": true,\n  \"message\": \"Task created successfully!\",\n  \"taskId\": $json.id,\n  \"taskName\": $json.task_name,\n  \"reminderTime\": $json.reminder_time\n} }}"
      },
      "typeVersion": 1
    },
    {
      "id": "b3cdb19e-6342-4881-937c-651f34b37699",
      "name": "Error Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        128,
        544
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "={{ {\n  \"success\": false,\n  \"message\": \"Invalid input. Required fields: userId, taskName, reminderTime\"\n} }}"
      },
      "typeVersion": 1
    },
    {
      "id": "07e622f7-7f07-4998-b150-88cd1d75324e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        64
      ],
      "parameters": {
        "color": 7,
        "width": 340,
        "height": 432,
        "content": "## \ud83d\udce4 RESPONSE HANDLERS\n\n**Success Response:**\nReturns 200 with task details\n\n**Error Response:**\nReturns 400 with error message\n\nBoth use JSON format for consistency."
      },
      "typeVersion": 1
    },
    {
      "id": "054df4ef-2851-442b-ac8e-45d0acd2b9de",
      "name": "Schedule Trigger - Every 5 Minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -768,
        1040
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "*/5 * * * *"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "110f25f1-6f56-4970-a783-3e6878231d22",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -928,
        752
      ],
      "parameters": {
        "color": 4,
        "width": 408,
        "height": 456,
        "content": "## \u23f0 SCHEDULE TRIGGER\n\nRuns every 5 minutes to check for pending reminders.\n\n**Cron Expression:** */5 * * * *\n\nAdjust frequency based on your needs:\n- Every 1 min: */1 * * * *\n- Every 10 min: */10 * * * *\n- Every hour: 0 * * * *"
      },
      "typeVersion": 1
    },
    {
      "id": "bffcb07b-e5c5-4587-8795-4a316841772e",
      "name": "Fetch Due Tasks",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -352,
        1040
      ],
      "parameters": {
        "query": "SELECT * FROM tasks WHERE status = 'pending' AND reminder_time <= NOW() + INTERVAL '5 minutes' AND reminder_time > NOW()",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "db4232c9-65fa-4be0-8594-582cb64be001",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        768
      ],
      "parameters": {
        "color": 6,
        "width": 360,
        "height": 416,
        "content": "## \ud83d\udd0d FETCH DUE TASKS\n\nQueries database for tasks where:\n- Status is 'pending'\n- Reminder time is within next 5 minutes\n- Not already sent\n\nThis ensures timely delivery without duplicates."
      },
      "typeVersion": 1
    },
    {
      "id": "2f074a5a-5441-4cd9-bedc-36a80b2f0442",
      "name": "Check Tasks Exist",
      "type": "n8n-nodes-base.if",
      "position": [
        16,
        1056
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "has-tasks",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.length }}",
              "rightValue": "0"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "8fb3b2a4-31f4-4e57-a8fc-e5f2e19502ab",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        784
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 408,
        "content": "## \ud83d\udd00 TASK CHECKER\n\nChecks if any tasks were found.\n\nIf YES \u2192 Process reminders\nIf NO \u2192 Skip (no action needed)"
      },
      "typeVersion": 1
    },
    {
      "id": "0284e84a-4b41-407d-9ca2-02950123b14e",
      "name": "Split Into Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        464,
        880
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "2a67a9a4-4317-48fa-b7d4-c666578d27f3",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        672
      ],
      "parameters": {
        "color": 3,
        "width": 304,
        "height": 360,
        "content": "## \ud83d\udd04 SPLIT INTO ITEMS\n\nProcesses each task individually.\n\nEssential for sending personalized reminders to each user with their specific task details."
      },
      "typeVersion": 1
    },
    {
      "id": "34887349-bfcb-4d72-aa3b-80c17cd64188",
      "name": "Route by Channel",
      "type": "n8n-nodes-base.switch",
      "position": [
        864,
        368
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "",
                    "rightValue": ""
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "7d8f1cb8-3c6e-4e0b-9d83-729b1927ec99",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        752,
        112
      ],
      "parameters": {
        "color": 7,
        "width": 340,
        "height": 404,
        "content": "## \ud83d\udce8 CHANNEL ROUTER\n\nRoutes reminders to appropriate channel:\n\n**Output 0:** Email\n**Output 1:** Slack\n**Output 2:** Telegram\n**Output 3:** SMS (Twilio)\n\nAdd more channels as needed!"
      },
      "typeVersion": 1
    },
    {
      "id": "94e39533-9cf6-49ee-9c8b-0b785895d37e",
      "name": "Send Email Reminder",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1264,
        352
      ],
      "parameters": {
        "options": {},
        "subject": "\u23f0 Task Reminder: {{ $json.task_name }}",
        "toEmail": "={{ $json.user_id }}",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "0f0d5935-a428-4616-b230-4a0fcb109a9f",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        48
      ],
      "parameters": {
        "color": 4,
        "width": 340,
        "height": 452,
        "content": "## \ud83d\udce7 EMAIL SENDER\n\nSends formatted HTML email with:\n- Task name\n- Scheduled time\n- Description\n- Professional styling\n\n**Setup Required:**\n- Configure SMTP credentials\n- Set from email address"
      },
      "typeVersion": 1
    },
    {
      "id": "5e0425d6-ed82-4eda-8a0e-80d3fbd8e78f",
      "name": "Send Slack Reminder",
      "type": "n8n-nodes-base.slack",
      "position": [
        944,
        848
      ],
      "parameters": {
        "text": "=\ud83d\udd14 *Task Reminder*\n\n*Task:* {{ $json.task_name }}\n*Time:* {{ $json.reminder_time }}\n*Description:* {{ $json.description || 'No description' }}",
        "user": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "select": "user",
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ed8ca2c7-a374-473a-a35e-a245b434e50c",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        784,
        544
      ],
      "parameters": {
        "color": 5,
        "width": 404,
        "height": 436,
        "content": "## \ud83d\udcac SLACK SENDER\n\nSends Slack message using:\n- Markdown formatting\n- Direct message to user\n- Task details\n\n**Setup Required:**\n- Create Slack App\n- Add bot token\n- Install to workspace"
      },
      "typeVersion": 1
    },
    {
      "id": "5f99e3b6-6458-465c-a300-a64d3e4885b8",
      "name": "Send Telegram Reminder",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1392,
        1248
      ],
      "parameters": {
        "text": "=\ud83d\udd14 *Task Reminder*\n\n*Task:* {{ $json.task_name }}\n*Time:* {{ $json.reminder_time }}\n*Description:* {{ $json.description || 'No description' }}",
        "chatId": "={{ $json.user_id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "efa080e8-9ddd-4ba8-9ffe-01bcd0400bab",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        976
      ],
      "parameters": {
        "color": 6,
        "width": 340,
        "height": 424,
        "content": "## \ud83d\udcf1 TELEGRAM SENDER\n\nSends Telegram message with:\n- Bold formatting\n- Task details\n- Direct to user's chat ID\n\n**Setup Required:**\n- Create bot via @BotFather\n- Get bot token\n- User must start conversation with bot"
      },
      "typeVersion": 1
    },
    {
      "id": "cc667e2b-5728-4ef9-a54b-4eac33d69b74",
      "name": "Update Task Status",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1696,
        848
      ],
      "parameters": {
        "query": "=UPDATE tasks SET status = 'sent', sent_at = NOW() WHERE id = {{ $json.id }}",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "695a7588-6cec-4fd9-942a-c63fca8ede0a",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1552,
        384
      ],
      "parameters": {
        "color": 2,
        "width": 400,
        "height": 616,
        "content": "## \ud83c\udfaf WORKFLOW COMPLETE!\n\n**Setup Checklist:**\n1. \u2705 Configure database credentials\n2. \u2705 Set up email/Slack/Telegram\n3. \u2705 Test webhook with sample data\n4. \u2705 Verify schedule trigger timing\n5. \u2705 Monitor first few runs\n\n**Database Setup SQL:**\n```sql\nCREATE TABLE tasks (\n  id SERIAL PRIMARY KEY,\n  user_id VARCHAR(255),\n  task_name VARCHAR(255),\n  reminder_time TIMESTAMP,\n  description TEXT,\n  channel VARCHAR(50),\n  status VARCHAR(50),\n  created_at TIMESTAMP,\n  sent_at TIMESTAMP\n);\n```"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6f4e3cb7-fd01-44eb-bd5b-b223b34ae217",
  "connections": {
    "Validate Input": {
      "main": [
        [
          {
            "node": "Save Task to Database",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Due Tasks": {
      "main": [
        [
          {
            "node": "Check Tasks Exist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Channel": {
      "main": [
        [
          {
            "node": "Send Email Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Into Items": {
      "main": [
        [
          {
            "node": "Route by Channel",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Slack Reminder",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Telegram Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Tasks Exist": {
      "main": [
        [
          {
            "node": "Split Into Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Task Status": {
      "main": [
        [
          {
            "node": "Split Into Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email Reminder": {
      "main": [
        [
          {
            "node": "Update Task Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Slack Reminder": {
      "main": [
        [
          {
            "node": "Update Task Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Task to Database": {
      "main": [
        [
          {
            "node": "Success Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Telegram Reminder": {
      "main": [
        [
          {
            "node": "Update Task Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook - Receive Task": {
      "main": [
        [
          {
            "node": "Validate Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger - Every 5 Minutes": {
      "main": [
        [
          {
            "node": "Fetch Due Tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}