{
  "id": "b8pNYJBx3cR14Knu",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Facebook Story Replies \u2192 Telegram \u201cHuman Required\u201d 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
      ],
      "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\u2019t 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 \u2013 Human Assigned",
      "type": "n8n-nodes-base.telegram",
      "position": [
        352,
        -16
      ],
      "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": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f87f0b74-f466-4846-b1b1-d82b96846cec",
      "name": "Telegram Alert \u2013 Unassigned Story Reply",
      "type": "n8n-nodes-base.telegram",
      "position": [
        352,
        176
      ],
      "parameters": {
        "text": "*Unassigned Facebook Story Reply*\n\nMessage: {{$json.message}}\nAction Required",
        "chatId": "=5758325294",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "50a9bf0c-b091-470e-8e9c-e5a7d4fc4246",
      "name": "Slack Alert \u2013 Unassigned Story Reply",
      "type": "n8n-nodes-base.slack",
      "position": [
        608,
        176
      ],
      "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": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b1317bb1-2a1f-44a3-9983-241b03d13443",
      "name": "Slack Notify \u2013 Human Assigned",
      "type": "n8n-nodes-base.slack",
      "position": [
        576,
        -16
      ],
      "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": {
          "name": "<your credential>"
        }
      },
      "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": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "25221da5-3901-4ef8-ba30-8b09a28dc74d",
      "name": "Update Supabase \u2013 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": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "93c62a17-eb46-4fea-8ef4-43d0d46c5047",
      "name": "Update Supabase \u2013 Unassigned",
      "type": "n8n-nodes-base.supabase",
      "position": [
        128,
        176
      ],
      "parameters": {
        "tableId": "facebook_story_replies",
        "operation": "update"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "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,
  "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 \u2013 Assigned",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Supabase \u2013 Unassigned",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Facebook Story Reply Webhook": {
      "main": [
        [
          {
            "node": "Normalize Story Reply Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Supabase \u2013 Assigned": {
      "main": [
        [
          {
            "node": "Telegram Notify \u2013 Human Assigned",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Story Reply Payload": {
      "main": [
        [
          {
            "node": "Insert Story Reply into Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Supabase \u2013 Unassigned": {
      "main": [
        [
          {
            "node": "Telegram Alert \u2013 Unassigned Story Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Story Reply into Supabase": {
      "main": [
        [
          {
            "node": "Time-Zone Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Notify \u2013 Human Assigned": {
      "main": [
        [
          {
            "node": "Slack Notify \u2013 Human Assigned",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Alert \u2013 Unassigned Story Reply": {
      "main": [
        [
          {
            "node": "Slack Alert \u2013 Unassigned Story Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}