{
  "id": "b8pNYJBx3cR14Knu",
  "meta": {
    "instanceId": "14e4c77104722ab186539dfea5182e419aecc83d85963fe13f6de862c875ebfa",
    "templateCredsSetupCompleted": true
  },
  "name": "Facebook Story Replies → Telegram “Human Required” Routing + Supabase CRM",
  "tags": [
    {
      "id": "F5TgwgrB2LTO3oA7",
      "name": "completed",
      "createdAt": "2026-01-02T08:54:40.571Z",
      "updatedAt": "2026-01-02T08:54:40.571Z"
    }
  ],
  "nodes": [
    {
      "id": "3b800fff-134c-40fd-81be-7961815ee7d7",
      "name": "Facebook Story Reply Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1104,
        80
      ],
      "webhookId": "7920d733-5e9e-44b5-aa08-758b077bac6e",
      "parameters": {
        "path": "facebook-story-reply",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 1
    },
    {
      "id": "daeefdb5-aa9c-42c6-bbf7-5e509da5b305",
      "name": "Normalize Story Reply Payload",
      "type": "n8n-nodes-base.function",
      "position": [
        -768,
        80
      ],
      "parameters": {
        "functionCode": "const body = items[0].json.body;\nconst entry = body?.entry?.[0];\nconst messaging = entry?.messaging?.[0];\n\nreturn [\n  {\n    json: {\n      platform: 'facebook_story',\n      sender_id: messaging?.sender?.id || null,\n      sender_name: null, // Facebook story replies don’t include name by default\n      message: messaging?.message?.text || null,\n      story_id: messaging?.message?.mid || null,\n      received_at: messaging?.timestamp\n        ? new Date(messaging.timestamp).toISOString()\n        : new Date().toISOString(),\n      status: 'pending',\n      raw_payload: body\n    }\n  }\n];\n"
      },
      "typeVersion": 1
    },
    {
      "id": "aaab48b7-1f89-458b-b98c-5d432547f9ed",
      "name": "Time-Zone Router",
      "type": "n8n-nodes-base.function",
      "position": [
        -320,
        80
      ],
      "parameters": {
        "functionCode": "const hour = new Date().getUTCHours();\n\nif (hour >= 6 && hour <= 14) {\n  return [{ json: { ...$json, assigned_to: 'support_asia', status: 'assigned' } }];\n}\n\nif (hour > 14 && hour <= 22) {\n  return [{ json: { ...$json, assigned_to: 'support_europe', status: 'assigned' } }];\n}\n\nreturn [{ json: { ...$json, status: 'unassigned' } }];"
      },
      "typeVersion": 1
    },
    {
      "id": "1d0614bd-5166-40d1-b644-e8d0f5dfe25a",
      "name": "Assignment Successful?",
      "type": "n8n-nodes-base.if",
      "position": [
        -96,
        80
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.status }}",
              "value2": "=assigned"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ba916845-aa3b-4a7d-bdd9-6a286e0d050c",
      "name": "Telegram Notify – Human Assigned",
      "type": "n8n-nodes-base.telegram",
      "position": [
        352,
        -16
      ],
      "webhookId": "0e2d8d9a-e6fe-4925-8d97-25120df8bc94",
      "parameters": {
        "text": "=*New Facebook Story Reply Assigned*\n\nAssigned: {{ $json.assigned_to }}\nMessage: {{$json.message}}\nStatus: Assigned",
        "chatId": "=5758325294",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "ehsm99085wI6Y3wR",
          "name": "Telegram Personal Account 0001"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f87f0b74-f466-4846-b1b1-d82b96846cec",
      "name": "Telegram Alert – Unassigned Story Reply",
      "type": "n8n-nodes-base.telegram",
      "position": [
        352,
        176
      ],
      "webhookId": "ffb0356b-be93-4b76-af1a-b39626df6882",
      "parameters": {
        "text": "*Unassigned Facebook Story Reply*\n\nMessage: {{$json.message}}\nAction Required",
        "chatId": "=5758325294",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "ehsm99085wI6Y3wR",
          "name": "Telegram Personal Account 0001"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "50a9bf0c-b091-470e-8e9c-e5a7d4fc4246",
      "name": "Slack Alert – Unassigned Story Reply",
      "type": "n8n-nodes-base.slack",
      "position": [
        608,
        176
      ],
      "webhookId": "d2da0973-c665-49f7-b43a-c91a3afe716f",
      "parameters": {
        "text": "New Facebook Story Reply Assigned:  \nCustomer: {{ $json.sender_name }} \nSender Id: {{ $json.sender_id }} \nStory Id: {{ $json.story_id }}  \nMessage: {{ $json.message }}  \nAssigned To: {{ $json.assigned_to }} \nReceived At: {{ $json.received_at }} ",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09S57E2JQ2",
          "cachedResultName": "n8n"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "id": "2LUITH1BIh32MbAZ",
          "name": "Slack Mobile 1"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b1317bb1-2a1f-44a3-9983-241b03d13443",
      "name": "Slack Notify – Human Assigned",
      "type": "n8n-nodes-base.slack",
      "position": [
        576,
        -16
      ],
      "webhookId": "d2da0973-c665-49f7-b43a-c91a3afe716f",
      "parameters": {
        "text": "=*New Facebook Story Reply Assigned:* \nCustomer: {{ $json.sender_name }}\nSender Id: {{ $json.sender_id }}\nStory Id: {{ $json.story_id }}\n\nMessage: {{ $json.message }}\n\nAssigned To: {{ $json.assigned_to }}\nReceived At: {{ $json.received_at }} \n",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09S57E2JQ2",
          "cachedResultName": "n8n"
        },
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "id": "2LUITH1BIh32MbAZ",
          "name": "Slack Mobile 1"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "56d96140-eace-4bb5-a992-ff4749b511af",
      "name": "Insert Story Reply into Supabase",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -544,
        80
      ],
      "parameters": {
        "tableId": "facebook_story_replies",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "platform",
              "fieldValue": "={{ $json.platform }}"
            },
            {
              "fieldId": "story_id",
              "fieldValue": "={{ $json.story_id }}"
            },
            {
              "fieldId": "sender_id",
              "fieldValue": "={{ $json.sender_id }}"
            },
            {
              "fieldId": "sender_name",
              "fieldValue": "={{ $json.sender_name }}"
            },
            {
              "fieldId": "message",
              "fieldValue": "={{ $json.message }}"
            },
            {
              "fieldId": "status",
              "fieldValue": "={{ $json.status }}"
            },
            {
              "fieldId": "received_at",
              "fieldValue": "={{ $json.received_at }}"
            }
          ]
        }
      },
      "credentials": {
        "supabaseApi": {
          "id": "RJrTGiPlkUKQI3RW",
          "name": "Supabase account 3"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "25221da5-3901-4ef8-ba30-8b09a28dc74d",
      "name": "Update Supabase – Assigned",
      "type": "n8n-nodes-base.supabase",
      "position": [
        128,
        -16
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "keyValue": "={{ $json.id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "facebook_story_replies",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "id",
              "fieldValue": "={{ $json.id }}"
            },
            {
              "fieldId": "platform",
              "fieldValue": "={{ $json.platform }}"
            },
            {
              "fieldId": "story_id",
              "fieldValue": "={{ $json.story_id }}"
            },
            {
              "fieldId": "sender_id",
              "fieldValue": "={{ $json.sender_id }}"
            },
            {
              "fieldId": "sender_name",
              "fieldValue": "={{ $json.sender_name }}"
            },
            {
              "fieldId": "message",
              "fieldValue": "={{ $json.message }}"
            },
            {
              "fieldId": "status",
              "fieldValue": "={{ $json.status }}"
            },
            {
              "fieldId": "assigned_to",
              "fieldValue": "={{ $json.assigned_to }}"
            },
            {
              "fieldId": "received_at",
              "fieldValue": "={{ $json.received_at }}"
            },
            {
              "fieldId": "updated_at",
              "fieldValue": "={{ $json.updated_at }}"
            },
            {
              "fieldId": "raw_payload",
              "fieldValue": "={{ $json.raw_payload }}"
            }
          ]
        },
        "operation": "update"
      },
      "credentials": {
        "supabaseApi": {
          "id": "RJrTGiPlkUKQI3RW",
          "name": "Supabase account 3"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "93c62a17-eb46-4fea-8ef4-43d0d46c5047",
      "name": "Update Supabase – Unassigned",
      "type": "n8n-nodes-base.supabase",
      "position": [
        128,
        176
      ],
      "parameters": {
        "tableId": "facebook_story_replies",
        "operation": "update"
      },
      "credentials": {
        "supabaseApi": {
          "id": "RJrTGiPlkUKQI3RW",
          "name": "Supabase account 3"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ee813015-e98f-4625-aefe-a9955afa1abb",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1264,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 432,
        "content": "# Incoming Facebook Story Replies\n**This section receives Facebook Story reply events in real time using a webhook. It captures basic details like sender ID, message content, story ID, and timestamp so replies can be processed, tracked, and routed automatically.**"
      },
      "typeVersion": 1
    },
    {
      "id": "ee43f8c6-5427-4e3b-9d55-a656f30c278a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 864,
        "height": 432,
        "content": "# Normalize, Store & Assign Replies\n**This section cleans and standardizes incoming story reply data, saves it into Supabase, and assigns each reply to the correct support team based on the current time zone. It ensures replies are organized and ownership is clearly defined.**"
      },
      "typeVersion": 1
    },
    {
      "id": "142977fb-ddd7-420e-ad73-035b0084be2b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -224
      ],
      "parameters": {
        "color": 7,
        "width": 704,
        "height": 576,
        "content": "# Notify Teams & Update Status\n**This section sends notifications to Telegram and Slack based on assignment status. Assigned replies notify the responsible team, while unassigned replies trigger alerts for manual action. Supabase records are updated to reflect the final handling status.**"
      },
      "typeVersion": 1
    },
    {
      "id": "3ca6a221-1825-4332-9378-deaee93b497b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1936,
        -432
      ],
      "parameters": {
        "width": 544,
        "height": 512,
        "content": "## **How It Works**\nThis workflow listens for new Facebook Story reply events in real time using a webhook. When a reply is received, the incoming payload is normalized into a clean and structured format so it can be processed consistently. Each reply is then stored in Supabase with an initial pending status to ensure it is tracked and not lost. The workflow evaluates the current UTC time to determine the appropriate support window and automatically assigns the reply to the Asia or Europe support team when applicable. If the assignment is successful, the reply status is updated to assigned and notifications are sent to both Telegram and Slack so the support team can take action promptly. Replies received outside of defined support hours remain unassigned, and alerts are raised to ensure they receive manual attention. All events and status changes are logged to provide full visibility, traceability, and follow-up.\n\n## **Setup Steps**\n**1)** Import the workflow into your n8n instance.\n**2)** Enable the Facebook webhook and connect it to your Facebook app.\n**3)** Configure Supabase credentials and ensure the table exists.\n**4)** Update the time-zone logic if your support hours differ.\n**5)** Add Telegram bot credentials and set the target chat ID.\n**6)** Connect Slack credentials and select the notification channel.\n**7)** Test the webhook using sample Facebook Story replies.\n**8)** Activate the workflow to process live Story replies."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5028f9b7-0114-4398-b803-7439564a5d0f",
  "connections": {
    "Time-Zone Router": {
      "main": [
        [
          {
            "node": "Assignment Successful?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Assignment Successful?": {
      "main": [
        [
          {
            "node": "Update Supabase – Assigned",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Supabase – Unassigned",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Facebook Story Reply Webhook": {
      "main": [
        [
          {
            "node": "Normalize Story Reply Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Supabase – Assigned": {
      "main": [
        [
          {
            "node": "Telegram Notify – Human Assigned",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Story Reply Payload": {
      "main": [
        [
          {
            "node": "Insert Story Reply into Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Supabase – Unassigned": {
      "main": [
        [
          {
            "node": "Telegram Alert – Unassigned Story Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Story Reply into Supabase": {
      "main": [
        [
          {
            "node": "Time-Zone Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Notify – Human Assigned": {
      "main": [
        [
          {
            "node": "Slack Notify – Human Assigned",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Alert – Unassigned Story Reply": {
      "main": [
        [
          {
            "node": "Slack Alert – Unassigned Story Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}