AutomationFlowsSlack & Telegram › Referral Credit Processor

Referral Credit Processor

Referral Credit Processor. Uses postgres, whatsApp. Event-driven trigger; 9 nodes.

Event trigger★★★★☆ complexity9 nodesPostgresWhatsApp
Slack & Telegram Trigger: Event Nodes: 9 Complexity: ★★★★☆ Added:

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "Referral Credit Processor",
  "nodes": [
    {
      "parameters": {
        "message": "={{$json.message}}",
        "extraOptions": {}
      },
      "id": "rc-trigger",
      "name": "Sub-workflow Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false
          },
          "conditions": [
            {
              "id": "has-referral",
              "leftValue": "={{$json.referred_by_phone}}",
              "rightValue": "",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "id": "rc-check-referral",
      "name": "Is Referred Order?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        200,
        0
      ]
    },
    {
      "parameters": {
        "operation": "select",
        "table": "customers",
        "columns": "phone, total_orders",
        "conditions": "phone = '{{$json.customer_phone}}'"
      },
      "id": "rc-check-order-count",
      "name": "Check Order Count",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        400,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true
          },
          "conditions": [
            {
              "id": "first-order",
              "leftValue": "={{$json.total_orders}}",
              "rightValue": 1,
              "operation": "equals"
            }
          ]
        }
      },
      "id": "rc-first-order",
      "name": "First Order Only?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        600,
        0
      ]
    },
    {
      "parameters": {
        "functionCode": "// Calculate 5% referral credit\nconst order = $input.first().json;\nconst amount = order.amount_paid || order.price_kobo / 100;\nconst credit = Math.round(amount * 0.05 * 100) / 100;\n\nreturn [{ json: { ...order, referral_credit: credit } }];"
      },
      "id": "rc-calc-credit",
      "name": "Calculate 5% Credit",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        800,
        0
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "table": "customers",
        "values": "referral_credit_ngn = referral_credit_ngn + {{$json.referral_credit}}"
      },
      "id": "rc-add-credit",
      "name": "Add Credit to Referrer",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        1000,
        0
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "table": "orders",
        "values": "referral_credit_earned_ngn = {{$json.referral_credit}}"
      },
      "id": "rc-log-order",
      "name": "Log Credit on Order",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        1200,
        0
      ]
    },
    {
      "parameters": {
        "operation": "select",
        "table": "customers",
        "columns": "name",
        "conditions": "phone = '{{$json.referred_by_phone}}'"
      },
      "id": "rc-get-referrer-name",
      "name": "Get Referrer Name",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        1400,
        0
      ]
    },
    {
      "parameters": {
        "message": "\ud83c\udf89 You earned referral credit!\n\n{{$json.referred_customer_name}} just completed their first order.\n\nThey bought: {{$json.product_type}}\nOrder value: \u20a6{{$json.amount_paid}}\n\nYour credit earned: \u20a6{{$json.referral_credit}}\n\nYour total referral credit: \u20a6{{$json.new_total_credit}}\n\nKeep sharing your name \u2014 every first purchase = more credit! \ud83d\udd17",
        "extraOptions": {}
      },
      "id": "rc-notify-referrer",
      "name": "Notify Referrer",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        1600,
        0
      ]
    }
  ],
  "connections": {
    "Sub-workflow Trigger": {
      "main": [
        [
          {
            "node": "Is Referred Order?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Referred Order?": {
      "main": [
        [
          {
            "node": "Check Order Count",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Check Order Count": {
      "main": [
        [
          {
            "node": "First Order Only?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "First Order Only?": {
      "main": [
        [
          {
            "node": "Calculate 5% Credit",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Calculate 5% Credit": {
      "main": [
        [
          {
            "node": "Add Credit to Referrer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Credit to Referrer": {
      "main": [
        [
          {
            "node": "Log Credit on Order",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Credit on Order": {
      "main": [
        [
          {
            "node": "Get Referrer Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Referrer Name": {
      "main": [
        [
          {
            "node": "Notify Referrer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": false,
    "timezone": "Africa/Lagos"
  },
  "staticData": null,
  "tags": [
    "referral",
    "credit",
    "sub-workflow"
  ]
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Referral Credit Processor. Uses postgres, whatsApp. Event-driven trigger; 9 nodes.

Source: https://github.com/sonnyagent30-beep/bunche/blob/8887b0da2107acb83f0c0632a8d7665b1adbfc44/.n8n/workflows/referral-credit.json — original creator credit. Request a take-down →

More Slack & Telegram workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Slack & Telegram

This workflow is for service-based businesses and freelancers who want to automate booking appointments via WhatsApp without relying on third-party scheduling tools. It's perfect for small teams who w

WhatsApp Trigger, WhatsApp, Postgres +1
Slack & Telegram

Worflow. Uses whatsAppTrigger, httpRequest, whatsApp. Event-driven trigger; 94 nodes.

WhatsApp Trigger, HTTP Request, WhatsApp
Slack & Telegram

Pede Ai. Uses httpRequest, telegram, postgres, telegramTrigger. Event-driven trigger; 57 nodes.

HTTP Request, Telegram, Postgres +1
Slack & Telegram

Pede Ai. Uses httpRequest, telegram, postgres, telegramTrigger. Event-driven trigger; 53 nodes.

HTTP Request, Telegram, Postgres +1
Slack & Telegram

03 - Command Handler. Uses executeWorkflowTrigger, telegram, executeCommand, postgres. Event-driven trigger; 53 nodes.

Execute Workflow Trigger, Telegram, Execute Command +2