{
  "name": "Manage coupon campaigns and customer chats with WhatsApp and PostgreSQL",
  "nodes": [
    {
      "id": "7974c25c-9cd3-470c-859b-b8ac6b56690d",
      "name": "Dashboard Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2704,
        6448
      ]
    },
    {
      "id": "822890c1-ed25-4a60-9df2-adfa470dfd0f",
      "name": "Respond with Dashboard HTML",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2496,
        6448
      ]
    },
    {
      "id": "28e3f6ad-f0a5-4213-ae18-cae5dd7f9f54",
      "name": "Execute SQL Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2704,
        6656
      ]
    },
    {
      "id": "b3958756-d816-45e3-b73c-53894cc9a870",
      "name": "Postgres Init",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2496,
        6656
      ]
    },
    {
      "id": "b111ea27-9fd3-4887-87b5-591e3c288ca0",
      "name": "Respond Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2304,
        6656
      ]
    },
    {
      "id": "aebbe1a5-3f73-4564-865d-db1a0ab2d2ba",
      "name": "Stats API Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2704,
        6848
      ]
    },
    {
      "id": "2b873782-fea5-48db-b93f-bc2020f08cc4",
      "name": "Get Stats Query",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2496,
        6848
      ]
    },
    {
      "id": "b16d4d0c-979e-4d9f-a51e-4eead9039a50",
      "name": "Respond Stats",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2304,
        6848
      ]
    },
    {
      "id": "a5f931f9-627c-4ade-902e-6da8cbf10aeb",
      "name": "Companies API",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2720,
        7104
      ]
    },
    {
      "id": "e3202c5a-a165-46c8-befc-44db2757f336",
      "name": "Switch Company Method",
      "type": "n8n-nodes-base.if",
      "position": [
        -2512,
        7104
      ]
    },
    {
      "id": "d786ad0d-9857-411f-8db8-707efbd62238",
      "name": "Get Companies",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2288,
        7200
      ]
    },
    {
      "id": "1e4d03a9-6631-4452-9bb0-994fd298cb05",
      "name": "Modify Company",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2288,
        7024
      ]
    },
    {
      "id": "659962ba-cbf2-49f1-9540-b43d93e7b166",
      "name": "Respond Companies",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2080,
        7200
      ]
    },
    {
      "id": "2db4a6ae-b6d4-4030-a1e5-3f3af75e9178",
      "name": "Respond Company Modified",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2080,
        7024
      ]
    },
    {
      "id": "72a180db-38b5-483e-be1b-d59bdb44bb43",
      "name": "Coupons API",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2720,
        7472
      ]
    },
    {
      "id": "0ecaf993-6e3e-4e34-ab43-da126ea86e59",
      "name": "Switch Coupon Method",
      "type": "n8n-nodes-base.if",
      "position": [
        -2512,
        7472
      ]
    },
    {
      "id": "15427b71-5784-419c-917f-9367831e545a",
      "name": "Get Coupons",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2288,
        7600
      ]
    },
    {
      "id": "e1a011d8-2a00-4369-90ca-3408b2c5e875",
      "name": "Modify Coupon",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2288,
        7424
      ]
    },
    {
      "id": "f74bce24-e60a-47e6-97e3-1d7de6440952",
      "name": "Respond Coupons",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2080,
        7600
      ]
    },
    {
      "id": "236f9929-e9e3-4756-81ed-7fe7d53db39b",
      "name": "Respond Coupon Modified",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2080,
        7424
      ]
    },
    {
      "id": "ac1317d7-d0ac-4624-abb9-edc2d4e6dc2a",
      "name": "Inbox API",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2736,
        7792
      ]
    },
    {
      "id": "d327ca3e-0776-4f36-b937-8854a742245c",
      "name": "Get Messages",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2528,
        7792
      ]
    },
    {
      "id": "96c8f8d4-6b1b-49f0-b980-2d5561c81acf",
      "name": "Respond Messages",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2336,
        7792
      ]
    },
    {
      "id": "2531fda1-9fb6-42f2-a20f-5b687cd41b88",
      "name": "Settings API",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2736,
        8000
      ]
    },
    {
      "id": "eca6405d-7592-4e19-979f-368d5aa4a594",
      "name": "Switch Settings Method",
      "type": "n8n-nodes-base.if",
      "position": [
        -2528,
        8000
      ]
    },
    {
      "id": "842d901a-4f17-48c1-b2ac-35cf6367bb68",
      "name": "Save Settings",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2336,
        8000
      ]
    },
    {
      "id": "464f3547-b90b-4e54-891b-56a5d276dfc8",
      "name": "Get Settings",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2336,
        8144
      ]
    },
    {
      "id": "2af699ee-5b0e-454f-9085-17b2443373d9",
      "name": "Respond Settings Saved",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2128,
        8000
      ]
    },
    {
      "id": "69b608f7-3843-4751-864c-3a3bc6e75875",
      "name": "Respond Settings",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2128,
        8144
      ]
    },
    {
      "id": "82475bcd-8dda-4439-a6b7-2208e37dcf6a",
      "name": "Migrate API Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2736,
        8352
      ]
    },
    {
      "id": "776706d3-8ce0-447f-849e-0282ca3dbfd9",
      "name": "Repair Tables Schema",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2528,
        8352
      ]
    },
    {
      "id": "f7b7598d-f70f-4d34-9e9a-7b22dfc0b578",
      "name": "Respond Migration Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2336,
        8352
      ]
    },
    {
      "id": "6fdb986b-15a2-4ed1-a099-4d97ad00cb2e",
      "name": "Chat History API",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -3168,
        8160
      ]
    },
    {
      "id": "9a7b3ecc-3016-4be7-9b26-db0c051669cd",
      "name": "Get Chat History",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2960,
        8160
      ]
    },
    {
      "id": "bccd1835-1420-4aeb-bdfa-84fa11599c1d",
      "name": "Respond History",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2768,
        8160
      ]
    },
    {
      "id": "826667ad-d445-4278-9849-1dabfb0c6e7c",
      "name": "Customers API",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2736,
        8528
      ]
    },
    {
      "id": "26269f3f-c9ec-48a5-beb8-33d72d5bc9a0",
      "name": "Get Customers",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2528,
        8528
      ]
    },
    {
      "id": "ce8c2d87-ee65-4715-a124-11dcb86fce4a",
      "name": "Respond Customers",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2336,
        8528
      ]
    },
    {
      "id": "94ab2f14-ec87-45f2-b857-c8538661790d",
      "name": "Records API",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2736,
        8736
      ]
    },
    {
      "id": "212732b3-8f67-4f15-a538-db6a5b2c7ab0",
      "name": "Get Records",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -2528,
        8736
      ]
    },
    {
      "id": "f7193791-adf7-4fde-abad-4868b272273b",
      "name": "Respond Records",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -2336,
        8736
      ]
    },
    {
      "id": "0a6a50dc-9f21-4c59-b5ae-b9cdf13d654d",
      "name": "WhatsApp Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -480,
        8528
      ]
    },
    {
      "id": "53916c9b-f215-4809-b3a0-5b57f806c77a",
      "name": "Is Message?",
      "type": "n8n-nodes-base.if",
      "position": [
        -240,
        8528
      ]
    },
    {
      "id": "a6034fab-a9c5-464d-a03d-8c4ed0e7911a",
      "name": "Get Admin Phone",
      "type": "n8n-nodes-base.postgres",
      "position": [
        16,
        8512
      ]
    },
    {
      "id": "32150657-cc95-450e-b9fe-e95bea90916a",
      "name": "Set Basic Data",
      "type": "n8n-nodes-base.set",
      "position": [
        240,
        8512
      ]
    },
    {
      "id": "cab7469c-8d42-4072-bc3c-34bd8682c132",
      "name": "Upsert Customer",
      "type": "n8n-nodes-base.postgres",
      "position": [
        544,
        8528
      ]
    },
    {
      "id": "5c910ffa-1f6f-4a35-930f-f8b9b4baa5ad",
      "name": "Save Incoming Message",
      "type": "n8n-nodes-base.postgres",
      "position": [
        800,
        8528
      ]
    },
    {
      "id": "4d4f4279-7019-45e3-a026-c08dfaabff46",
      "name": "Get User Session",
      "type": "n8n-nodes-base.postgres",
      "position": [
        992,
        8528
      ]
    },
    {
      "id": "93f5a166-3d01-4d67-9161-004d2a618fa4",
      "name": "Is Admin?",
      "type": "n8n-nodes-base.if",
      "position": [
        1200,
        8528
      ]
    },
    {
      "id": "6d61ca8b-39aa-4adb-a2e5-712a4633fe51",
      "name": "Switch User Action",
      "type": "n8n-nodes-base.if",
      "position": [
        1872,
        8560
      ]
    },
    {
      "id": "fec7b14c-d577-431a-bfe5-67c24542f93e",
      "name": "Get Companies List",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3856,
        7792
      ]
    },
    {
      "id": "1df6c23a-d069-4f29-9874-a03854e3a078",
      "name": "Send Companies List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4144,
        7520
      ]
    },
    {
      "id": "fe07e168-5450-4a40-89f6-116bdb4997dc",
      "name": "Is Company Selection?",
      "type": "n8n-nodes-base.if",
      "position": [
        3888,
        8032
      ]
    },
    {
      "id": "f320746f-88d7-4742-a687-29c9a5f0150e",
      "name": "Get Coupons List",
      "type": "n8n-nodes-base.postgres",
      "position": [
        4288,
        7760
      ]
    },
    {
      "id": "5a563bd9-3865-456a-b228-cdf9be8da995",
      "name": "Send Coupons List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4496,
        8016
      ]
    },
    {
      "id": "3a2eb1a9-2d17-46f9-b388-52633fa7363b",
      "name": "Get Coupon Details",
      "type": "n8n-nodes-base.postgres",
      "position": [
        4288,
        8144
      ]
    },
    {
      "id": "2156a012-0d3f-4e07-8121-efde69421a20",
      "name": "Log Coupon Redemption",
      "type": "n8n-nodes-base.postgres",
      "position": [
        4704,
        8080
      ]
    },
    {
      "id": "bd48c551-5dc9-42bd-985d-dce9edd4c99f",
      "name": "Send Coupon Details",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4512,
        8384
      ]
    },
    {
      "id": "5d4818b9-0455-401c-b720-f42d64185f05",
      "name": "Check Admin State",
      "type": "n8n-nodes-base.if",
      "position": [
        1472,
        8400
      ]
    },
    {
      "id": "6b51c752-a60b-4984-a78d-9e5a004b5779",
      "name": "Add Company (Admin)",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3504,
        5568
      ]
    },
    {
      "id": "bac44789-fc03-409a-88cd-9f4fa7a9d2a7",
      "name": "Send Admin Success",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3776,
        5632
      ]
    },
    {
      "id": "790c1575-9dd9-41f7-9560-efe003612470",
      "name": "Admin Choice",
      "type": "n8n-nodes-base.switch",
      "position": [
        2496,
        7888
      ]
    },
    {
      "id": "9c9eac2d-5220-43dc-912f-4cece6e97054",
      "name": "Set Admin State (Add Co)",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3168,
        7712
      ]
    },
    {
      "id": "a6934aa6-3aab-4b51-bae7-5d5ddc9aa28d",
      "name": "Ask Admin Input",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3520,
        7776
      ]
    },
    {
      "id": "3d6735d6-e004-41eb-90ff-2242ae129536",
      "name": "Show Admin Menu",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3424,
        8880
      ]
    },
    {
      "id": "e155a6c9-6a37-40bc-8e3a-9a0f150fc7a8",
      "name": "Log Sent Companies",
      "type": "n8n-nodes-base.postgres",
      "position": [
        4096,
        7840
      ]
    },
    {
      "id": "4dba4fc4-7d37-4dc2-be86-c81ed38cff15",
      "name": "Log Sent Coupons",
      "type": "n8n-nodes-base.postgres",
      "position": [
        4560,
        7616
      ]
    },
    {
      "id": "a6b6c5b7-52f4-49c7-95fb-549de69b0eb6",
      "name": "Log Sent Details",
      "type": "n8n-nodes-base.postgres",
      "position": [
        4512,
        8208
      ]
    },
    {
      "id": "edda2b09-4919-45e4-8cfe-2fb2280a2eb1",
      "name": "Log Admin Success",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3776,
        5488
      ]
    },
    {
      "id": "51413e15-5780-412a-aaa0-21040abbdf44",
      "name": "Log Admin Input",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3520,
        7568
      ]
    },
    {
      "id": "f79743b0-18b9-464c-b2a0-1861863788b4",
      "name": "Log Admin Menu",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3440,
        8768
      ]
    },
    {
      "id": "5535e0fc-51da-42c0-be5a-b2c32ada37ef",
      "name": "Admin State Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        2240,
        6992
      ]
    },
    {
      "id": "8bad6268-c50f-4823-bb2b-b858cabd07ca",
      "name": "Save Edited Company",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3552,
        5952
      ]
    },
    {
      "id": "a013cd2f-4a63-483c-8880-e4163ffe43fb",
      "name": "Send Edit Company Success",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3808,
        5952
      ]
    },
    {
      "id": "fd7ca772-0ae2-4233-bee3-fc1b0e61fa59",
      "name": "Delete Company Exec",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3552,
        6144
      ]
    },
    {
      "id": "7c6f7509-dddc-4df0-b85f-b89ec8e28210",
      "name": "Send Delete Company Success",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3808,
        6128
      ]
    },
    {
      "id": "13bc5f77-8c4f-432c-b423-c781fd83b342",
      "name": "Set Coupon Company",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3568,
        6304
      ]
    },
    {
      "id": "e2b6cb94-6041-43b4-bfa5-4a44fc719cf5",
      "name": "Ask Coupon Text",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3824,
        6304
      ]
    },
    {
      "id": "253aae5d-d688-478c-9b1e-7a5df2d5103e",
      "name": "Save Coupon Text",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3568,
        6464
      ]
    },
    {
      "id": "07495e0e-bc6e-45c1-a2aa-4147ac1febe3",
      "name": "Ask Coupon Value",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3840,
        6464
      ]
    },
    {
      "id": "986ca793-bf95-49a0-87a2-d791559893cd",
      "name": "Insert New Coupon",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3568,
        6640
      ]
    },
    {
      "id": "d56037ad-c3c0-4a01-b1f6-772a14bd18a1",
      "name": "Send Add Coupon Success",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3840,
        6624
      ]
    },
    {
      "id": "6c4863de-5a72-4922-9e26-8ef4b24da7ba",
      "name": "Set Edit Coupon Select",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3584,
        6800
      ]
    },
    {
      "id": "d9197059-c085-4591-83e2-8eff20686d8f",
      "name": "Ask Edit Coupon Text",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3856,
        6816
      ]
    },
    {
      "id": "bab41a96-b679-4b5c-853c-316e80b6dde0",
      "name": "Save Edited Coupon",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3584,
        6960
      ]
    },
    {
      "id": "651ee444-bd34-4fa0-a1f7-0d76e6ce6725",
      "name": "Send Edit Coupon Success",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3856,
        6976
      ]
    },
    {
      "id": "13a27e1e-307b-4f55-9068-5069329d5b9d",
      "name": "Delete Coupon Exec",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3584,
        7136
      ]
    },
    {
      "id": "9a4114c7-33fb-4fd0-85f0-b71ad347121d",
      "name": "Send Delete Coupon Success",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3872,
        7120
      ]
    },
    {
      "id": "aa88c7aa-ddd3-4b78-86d7-77e477dc84ba",
      "name": "Set Edit Company State",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3552,
        5776
      ]
    },
    {
      "id": "c3cd639f-ebda-40c1-831e-359e68fdb00d",
      "name": "Ask Edit Company Name",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3792,
        5776
      ]
    },
    {
      "id": "d5a1c9da-9d6e-4c33-9203-2e52d14115af",
      "name": "Get Companies For Edit",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3376,
        8128
      ]
    },
    {
      "id": "b526455b-92e3-4bd0-b2b6-38f26857a622",
      "name": "Send Edit Companies List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3616,
        8128
      ]
    },
    {
      "id": "62d62b65-94bd-4a9c-a33c-0a5e88de8483",
      "name": "Get Companies For Delete",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3360,
        8288
      ]
    },
    {
      "id": "c1f3a323-efab-41cb-9287-d3b9aa752222",
      "name": "Send Delete Companies List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3600,
        8288
      ]
    },
    {
      "id": "4cd30ff8-03f5-4bd0-be5b-3e8175b0d925",
      "name": "Get Companies For Add Coupon",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3392,
        7920
      ]
    },
    {
      "id": "f13a5376-87f2-4c58-880b-1f44c3bce843",
      "name": "Send Add Coupon Companies",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3632,
        7904
      ]
    },
    {
      "id": "34d58e84-b928-4c6d-a76d-b86d8daaa75c",
      "name": "Get Coupons For Edit",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3344,
        8448
      ]
    },
    {
      "id": "ba5c3fc0-9e4a-4726-a5fc-01a3efd33a48",
      "name": "Send Edit Coupons List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3584,
        8448
      ]
    },
    {
      "id": "6e41f752-9d19-4404-bfad-6cfbd941c330",
      "name": "Get Coupons For Delete",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3360,
        8592
      ]
    },
    {
      "id": "a1e8290d-b6dd-4ab9-a2b0-a1e9ccb0f4d4",
      "name": "Send Delete Coupons List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3600,
        8592
      ]
    },
    {
      "id": "183d0b63-f521-49ba-9e7e-60bb9d3afbfa",
      "name": "Set Edit Company List State",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3168,
        8112
      ]
    },
    {
      "id": "d798fa98-626c-4741-b340-69bc3d746ba9",
      "name": "Set Delete Company List State",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3168,
        8288
      ]
    },
    {
      "id": "d8a73ae6-8b73-40ab-b69a-d12d076894ec",
      "name": "Set Add Coupon State",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3168,
        7920
      ]
    },
    {
      "id": "bd6ea451-c4c1-447a-a355-3b913e9bfb45",
      "name": "Set Edit Coupon State",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3152,
        8448
      ]
    },
    {
      "id": "66173b93-1f48-492c-8281-029e65ec4648",
      "name": "Set Delete Coupon State",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3168,
        8592
      ]
    },
    {
      "id": "b54e0af6-913f-43f0-acea-5a48b2810a85",
      "name": "Check If Single Coupon",
      "type": "n8n-nodes-base.if",
      "position": [
        4448,
        7824
      ]
    },
    {
      "id": "006b3867-aa1b-4af2-a1c8-bb0a3021b6b0",
      "name": "Get Welcome & End Messages",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3888,
        7424
      ]
    },
    {
      "id": "3b2d74a1-deb4-45a5-bf18-d847e1d1218b",
      "name": "Get End Message For Coupon",
      "type": "n8n-nodes-base.postgres",
      "position": [
        4800,
        8304
      ]
    },
    {
      "id": "d1bd3d06-e1f4-4415-a699-12dd9901d061",
      "name": "Set Edit Welcome State",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2752,
        6160
      ]
    },
    {
      "id": "117bca63-609b-465e-bc1a-ed43f1e5cd6d",
      "name": "Ask Welcome Message",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2928,
        6160
      ]
    },
    {
      "id": "0d373d30-a5c9-41ca-b64d-4346ca83d00c",
      "name": "Save Welcome Message",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3104,
        6400
      ]
    },
    {
      "id": "e3a62d9f-b200-4639-872c-eb4a75364624",
      "name": "Send Welcome Success",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3280,
        6400
      ]
    },
    {
      "id": "b39d9982-fa9c-4c18-9282-143cbf696232",
      "name": "Set Edit End State",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2752,
        6496
      ]
    },
    {
      "id": "a53a7a88-2c03-4ba4-a3b9-cf5eab8d8273",
      "name": "Ask End Message",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2928,
        6496
      ]
    },
    {
      "id": "a17c9215-6f3d-4a04-a081-12e1bedf909c",
      "name": "Save End Message",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3104,
        6736
      ]
    },
    {
      "id": "94a4a03b-2aab-465d-bfe0-b8ad2e36da12",
      "name": "Send End Success",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3280,
        6736
      ]
    },
    {
      "id": "4e1269af-a96f-45f7-a3fa-b4aba7f833f1",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3824,
        6112
      ],
      "parameters": {
        "width": 544,
        "height": 512,
        "content": "# 🎯 Coupon Bot Dashboard\n\nA complete admin dashboard for managing discount coupons, \ncompanies, and customer conversations via WhatsApp/Telegram.\n\n### How it works:\n1. Dashboard UI served via webhook "
      }
    },
    {
      "id": "1c6d239c-567d-49cc-950e-9644bc5932df",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3136,
        6352
      ],
      "parameters": {
        "width": 1008,
        "height": 272,
        "content": "📊 Dashboard UI\n- Vue.js 3 + Tailwind CSS interface\n- English LTR layout\n- Responsive mobile design\n- Served via RespondToWebhook node"
      }
    },
    {
      "id": "02e7c3a8-031a-42cd-a9bf-e371a2889f19",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3056,
        6640
      ],
      "parameters": {
        "width": 1008,
        "height": 320,
        "content": "🗄️ Database Schema\n- Customers, Companies, Coupons tables\n- Messages & Records tracking\n- Settings & Sessions management\n- Migration support for updates"
      }
    },
    {
      "id": "cf0b90f2-aae6-45e2-a23a-75250e57248a",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3024,
        6992
      ],
      "parameters": {
        "width": 1072,
        "height": 384,
        "content": "🔌 REST API Routes\n- GET/POST /api/companies\n- GET/POST /api/coupons  \n- GET/POST /api/settings\n- GET /api/stats, /api/inbox, /api/history"
      }
    },
    {
      "id": "f2835cb2-7ca4-4a5d-aecd-c0c42db05578",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3008,
        7392
      ],
      "parameters": {
        "width": 1056,
        "height": 384,
        "content": "⚙️ System Tools\n- Database initialization (/execute-init)\n- Schema migration & repair (/migrate)\n- Full reset capability\n- Settings management"
      }
    },
    {
      "id": "b9fee30c-5dd9-4d25-beb7-94ef5d5e199a",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3264,
        7792
      ],
      "parameters": {
        "width": 1328,
        "height": 544,
        "content": "💬 Customer Inbox System\n- Real-time chat interface\n- Message history tracking\n- Customer conversation threads\n- WhatsApp/Telegram integration ready\n- Webhook endpoints: /api/inbox, /api/history"
      }
    },
    {
      "id": "5fda487c-65ed-43c8-877e-46cb775da390",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3248,
        8352
      ],
      "parameters": {
        "width": 1328,
        "height": 544,
        "content": "👥 Customer Management\n- Customer profiles and phone tracking\n- Coupon usage records\n- Usage analytics and history\n- API endpoints: /api/customers, /api/records"
      }
    },
    {
      "id": "39e2809e-8bc8-497e-948e-79a4421f7f30",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1104,
        7120
      ],
      "parameters": {
        "width": 496,
        "height": 1872,
        "content": "# 🤖 WhatsApp Coupon Bot\n\nComplete WhatsApp Business API integration for the Coupon Dashboard. Handles customer conversations and admin management via WhatsApp.\n\n---\n# 🔄 Session-Based State Management\n"
      }
    },
    {
      "id": "68e78c25-3ff3-4146-957c-6f9251cc9392",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        7344
      ],
      "parameters": {
        "width": 496,
        "height": 656,
        "content": "# 🔄 Session-Based State Management\n\nThe bot uses PostgreSQL sessions table to track conversations across multiple messages.\n\nHow it works:\n• Each phone number has one active session\n• State column tra"
      }
    },
    {
      "id": "e40ec871-1a86-4e4d-8454-7eb9b2c4019a",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2288,
        8656
      ],
      "parameters": {
        "width": 496,
        "height": 704,
        "content": "# 🔌 WhatsApp API Integration & User Routing\n\nMessage Types:\n• Text - simple replies and confirmations (4096 chars max)\n• Interactive List - company/coupon selection (10 items max)\n• Button Reply - qui"
      }
    },
    {
      "id": "920d663c-928b-44c2-a94f-627b1cba6438",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2224,
        5088
      ],
      "parameters": {
        "width": 1936,
        "height": 960,
        "content": "\n\n![Dashboard Screenshot](https://jobotai.site/1.png)"
      }
    },
    {
      "id": "83d2df4c-20fb-4894-8419-8a6641efb654",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1216,
        6096
      ],
      "parameters": {
        "width": 1936,
        "height": 960,
        "content": "\n\n![Dashboard Screenshot](https://jobotai.site/4.png)"
      }
    },
    {
      "id": "89f12ec6-2ec9-4316-a9af-327bbf813f36",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        5104
      ],
      "parameters": {
        "width": 1936,
        "height": 960,
        "content": "\n\n![Dashboard Screenshot](https://jobotai.site/5.png)"
      }
    },
    {
      "id": "44984253-a7d1-48c2-888a-9e9ccf3c0cea",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        4928
      ],
      "parameters": {
        "width": 640,
        "height": 96,
        "content": "# 🎯 Coupon Bot  +  Dashboard + Inbox"
      }
    }
  ],
  "connections": {
    "Inbox API": {
      "main": [
        [
          {
            "node": "Get Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Admin?": {
      "main": [
        [
          {
            "node": "Check Admin State",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Switch User Action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Coupons API": {
      "main": [
        [
          {
            "node": "Switch Coupon Method",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Coupons": {
      "main": [
        [
          {
            "node": "Respond Coupons",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Records": {
      "main": [
        [
          {
            "node": "Respond Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Message?": {
      "main": [
        [
          {
            "node": "Get Admin Phone",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Records API": {
      "main": [
        [
          {
            "node": "Get Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Admin Choice": {
      "main": [
        [
          {
            "node": "Set Admin State (Add Co)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Companies List",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Is Company Selection?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Edit Company List State",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Delete Company List State",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Add Coupon State",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Edit Coupon State",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Delete Coupon State",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Show Admin Menu",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Admin Menu",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Edit Welcome State",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Edit End State",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Messages": {
      "main": [
        [
          {
            "node": "Respond Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Settings": {
      "main": [
        [
          {
            "node": "Respond Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings API": {
      "main": [
        [
          {
            "node": "Switch Settings Method",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Companies API": {
      "main": [
        [
          {
            "node": "Switch Company Method",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Customers API": {
      "main": [
        [
          {
            "node": "Get Customers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Companies": {
      "main": [
        [
          {
            "node": "Respond Companies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Customers": {
      "main": [
        [
          {
            "node": "Respond Customers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Modify Coupon": {
      "main": [
        [
          {
            "node": "Respond Coupon Modified",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Init": {
      "main": [
        [
          {
            "node": "Respond Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Settings": {
      "main": [
        [
          {
            "node": "Respond Settings Saved",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Modify Company": {
      "main": [
        [
          {
            "node": "Respond Company Modified",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Basic Data": {
      "main": [
        [
          {
            "node": "Upsert Customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Admin Phone": {
      "main": [
        [
          {
            "node": "Set Basic Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Stats Query": {
      "main": [
        [
          {
            "node": "Respond Stats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert Customer": {
      "main": [
        [
          {
            "node": "Save Incoming Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat History API": {
      "main": [
        [
          {
            "node": "Get Chat History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Chat History": {
      "main": [
        [
          {
            "node": "Respond History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Coupons List": {
      "main": [
        [
          {
            "node": "Check If Single Coupon",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Sent Coupons",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get User Session": {
      "main": [
        [
          {
            "node": "Is Admin?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Coupon Text": {
      "main": [
        [
          {
            "node": "Ask Coupon Value",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save End Message": {
      "main": [
        [
          {
            "node": "Send End Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Webhook": {
      "main": [
        [
          {
            "node": "Is Message?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Admin State": {
      "main": [
        [
          {
            "node": "Admin State Router",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Admin Choice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dashboard Webhook": {
      "main": [
        [
          {
            "node": "Respond with Dashboard HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert New Coupon": {
      "main": [
        [
          {
            "node": "Send Add Coupon Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Stats API Webhook": {
      "main": [
        [
          {
            "node": "Get Stats Query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Admin State Router": {
      "main": [
        [
          {
            "node": "Add Company (Admin)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Edit Company State",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Edited Company",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete Company Exec",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Coupon Company",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Coupon Text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Insert New Coupon",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Edit Coupon Select",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Edited Coupon",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete Coupon Exec",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Welcome Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save End Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Coupon Exec": {
      "main": [
        [
          {
            "node": "Send Delete Coupon Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Companies List": {
      "main": [
        [
          {
            "node": "Send Companies List",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Sent Companies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Coupon Details": {
      "main": [
        [
          {
            "node": "Log Coupon Redemption",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get End Message For Coupon",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Sent Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Edited Coupon": {
      "main": [
        [
          {
            "node": "Send Edit Coupon Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Coupon Company": {
      "main": [
        [
          {
            "node": "Ask Coupon Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Edit End State": {
      "main": [
        [
          {
            "node": "Ask End Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch User Action": {
      "main": [
        [
          {
            "node": "Is Company Selection?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Companies List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Company (Admin)": {
      "main": [
        [
          {
            "node": "Send Admin Success",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Admin Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Company Exec": {
      "main": [
        [
          {
            "node": "Send Delete Company Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute SQL Webhook": {
      "main": [
        [
          {
            "node": "Postgres Init",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Migrate API Webhook": {
      "main": [
        [
          {
            "node": "Repair Tables Schema",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Edited Company": {
      "main": [
        [
          {
            "node": "Send Edit Company Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Coupons For Edit": {
      "main": [
        [
          {
            "node": "Send Edit Coupons List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Repair Tables Schema": {
      "main": [
        [
          {
            "node": "Respond Migration Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Welcome Message": {
      "main": [
        [
          {
            "node": "Send Welcome Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Add Coupon State": {
      "main": [
        [
          {
            "node": "Get Companies For Add Coupon",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch Coupon Method": {
      "main": [
        [
          {
            "node": "Modify Coupon",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Coupons",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Company Selection?": {
      "main": [
        [
          {
            "node": "Get Coupons List",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Coupon Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Incoming Message": {
      "main": [
        [
          {
            "node": "Get User Session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Edit Coupon State": {
      "main": [
        [
          {
            "node": "Get Coupons For Edit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch Company Method": {
      "main": [
        [
          {
            "node": "Modify Company",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Companies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If Single Coupon": {
      "main": [
        [
          {
            "node": "Get Coupon Details",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Coupons List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Companies For Edit": {
      "main": [
        [
          {
            "node": "Send Edit Companies List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Coupons For Delete": {
      "main": [
        [
          {
            "node": "Send Delete Coupons List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Edit Company State": {
      "main": [
        [
          {
            "node": "Ask Edit Company Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Edit Coupon Select": {
      "main": [
        [
          {
            "node": "Ask Edit Coupon Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Edit Welcome State": {
      "main": [
        [
          {
            "node": "Ask Welcome Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch Settings Method": {
      "main": [
        [
          {
            "node": "Save Settings",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Delete Coupon State": {
      "main": [
        [
          {
            "node": "Get Coupons For Delete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Companies For Delete": {
      "main": [
        [
          {
            "node": "Send Delete Companies List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Admin State (Add Co)": {
      "main": [
        [
          {
            "node": "Ask Admin Input",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Admin Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get End Message For Coupon": {
      "main": [
        [
          {
            "node": "Send Coupon Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Welcome & End Messages": {
      "main": [
        [
          {
            "node": "Get Companies List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Edit Company List State": {
      "main": [
        [
          {
            "node": "Get Companies For Edit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Companies For Add Coupon": {
      "main": [
        [
          {
            "node": "Send Add Coupon Companies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Delete Company List State": {
      "main": [
        [
          {
            "node": "Get Companies For Delete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}