Skip to main content

Detect fraud in user activity with PostgreSQL, OpenAI and Slack

Workflow preview

Workflow preview
100%
Detect fraud in user activity with PostgreSQL, OpenAI and Slack preview
Open on n8n.io

1. Workflow Overview

AI Fraud Detection Workflow n8n + PostgreSQL + OpenAI + Slack This AI Fraud Detection Workflow is an automated n8n pipeline that analyzes user activity in real time using a combination of rule...

Best for

  • SecOps automation workflows
  • AI Summarization automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.webhook, n8n-nodes-base.code, n8n-nodes-base.stickynote, n8n-nodes-base.postgres, n8n-nodes-base.function, n8n-nodes-base.openai, n8n-nodes-base.if, n8n-nodes-base.slack

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by WeblineIndia.

Original n8n.io source

1.1 Workflow description

Title
Detect fraud in user activity with PostgreSQL, OpenAI and Slack
Workflow name
Detect fraud in user activity with PostgreSQL, OpenAI and Slack

AI Fraud Detection Workflow

> n8n + PostgreSQL + OpenAI + Slack


This AI Fraud Detection Workflow is an automated n8n pipeline that analyzes user activity in real time using a combination of rule-based fraud detection, AI interpretation and historical behavioral context. It processes events like login attempts, password changes or transactions, evaluates risk, stores results in PostgreSQL and triggers alerts for high-risk activity.

Quick Implementation Steps

  1. Import workflow into n8n
  2. Configure webhook endpoint /user-activity
  3. Set up PostgreSQL connection and user_activity_logs table
  4. Add OpenAI API credentials
  5. Configure alerting node (Slack or alternative)
  6. Activate workflow and test with sample payload

What It Does

This workflow continuously monitors user activity events and evaluates them for suspicious behavior.

When a user event is received, the system:

  • Validates the incoming request
  • Fetches last 10 user activity logs from PostgreSQL
  • Builds behavioral context
  • Applies rule-based fraud scoring
  • Sends structured data to AI for interpretation
  • Combines AI + rule-based decisions
  • Stores results in the database
  • Sends alerts for HIGH-risk cases

It helps detect anomalies like:

  • New device usage
  • Impossible travel (rapid location change)
  • Foreign access attempts
  • Sensitive actions like password changes

Who It's For

  • Fintech applications
  • Banking & payment platforms
  • SaaS applications with authentication systems
  • E-commerce platforms
  • Security and fraud prevention teams
  • DevOps and backend engineers

Requirements to Use This Workflow

Database Schema

CREATE TABLE user_activity_logs (
 id BIGSERIAL PRIMARY KEY,
 user_id TEXT,
 event TEXT,
 ip TEXT,
 location TEXT,
 device TEXT,
 risk_score INT,
 ai_flag TEXT,
 created_at TIMESTAMP DEFAULT NOW()
);

How It Works & Setup Guide

1. Webhook Trigger

Receives user activity via POST request:

Endpoint:

/user-activity

Payload:

{
 "user_id": "user_002",
 "event": "password_change",
 "ip": "192.165.1.45",
 "location": "United States",
 "device": "Chrome Browser - Windows"
}

2. Request Validation

Ensures required fields exist:

  • user_id
  • event
  • ip
  • location
  • device

3. Fetch User History (PostgreSQL)

Retrieves last 10 activity logs for the user to build behavioral context.

4. Context Builder

Merges:

  • Current event
  • Historical activity logs

This helps detect behavioral anomalies.

5. Rule-Based Fraud Engine

Applies deterministic fraud logic:

  • New device detection
  • Impossible travel detection
  • Foreign location access
  • Sensitive operations (password change, withdrawal)

Outputs:

  • rule_score
  • rule_risk (LOW / MEDIUM / HIGH)
  • risk_reasons

6. AI Fraud Interpreter (OpenAI)

The AI does not calculate risk.

It only interprets rule-based output and returns:

{
 "risk_level": "LOW | MEDIUM | HIGH",
 "reason": "short explanation"
}

7. AI Response Cleaner

  • Parses AI output safely
  • Extracts:
  • ai_risk
  • ai_reason

8. Decision Fusion Layer

Final risk logic:

  • If rule OR AI = HIGH → FINAL = HIGH
  • Else if either = MEDIUM → FINAL = MEDIUM
  • Else → LOW

9. Database Logger

Stores final result in PostgreSQL:

  • user_id
  • event
  • ip
  • location
  • device
  • risk_score (rule-based)
  • ai_flag (AI risk level)

10. High Risk Filter

Triggers only when:

final_risk === "HIGH"

11. Alert Dispatcher

Sends fraud alert via Slack (or can be replaced with email, SMS, Teams, etc.)

How to Customize Nodes

  • Fraud Rules Engine: Adjust scoring weights and conditions
  • AI Prompt: Add domain-specific fraud rules or compliance logic
  • Database Node: Add extra fields like session_id, user_agent
  • Alert System: Replace Slack with email, SMS or webhook
  • Threshold Logic: Modify HIGH/MEDIUM/LOW conditions

Add-ons (Enhancements)

  • GeoIP enrichment using IP tracking
  • Device fingerprinting integration
  • Real-time fraud dashboard
  • Machine learning anomaly scoring
  • Multi-channel alerting (Slack + Email + SMS)
  • Fraud case management system
  • Rate limiting and bot detection

Use Case Examples

  • Detect unauthorized login attempts
  • Prevent account takeover (ATO) attacks
  • Monitor suspicious password changes
  • Detect fraudulent financial transactions
  • Identify VPN or proxy-based access

This workflow can be extended to many more fraud detection and security monitoring use cases.

Troubleshooting Guide

Issue Possible Cause Solution
Webhook not receiving data Incorrect endpoint or inactive workflow Ensure workflow is active and webhook URL is correct
AI parsing error Unexpected response format from OpenAI Verify JSON structure from AI output
No historical data found Empty user logs table Ensure user_activity_logs has existing records
Slack alert not triggered Risk not classified as HIGH Check fusion logic in decision node
PostgreSQL error Wrong credentials or schema mismatch Verify DB connection and table structure
Incorrect risk score Rule logic misconfiguration Review fraud scoring conditions

Need Help

If you need help with:

  • Setting up this workflow in n8n
  • Customizing fraud detection rules
  • Integrating advanced alerting systems
  • Scaling workflows for production

You can reach out to our n8n workflow developers at WeblineIndia for professional assistance in building and optimizing automation workflows like this.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - User Activity Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 1

Block 2 - Request Validator

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 3 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Fetch Recent User Logs

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 1

Block 5 - Context Builder

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 6 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 8 - Fraud Rules Engine

Type / Role
n8n-nodes-base.function - function
Config choices
Version 1

Block 9 - AI Fraud Interpreter

Type / Role
n8n-nodes-base.openAi - openAi
Config choices
Version 1

Block 10 - AI Response Cleaner

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 11 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 13 - Risk Decision Combiner

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 14 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 15 - Database Logger

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 1

Block 16 - High Risk Filter

Type / Role
n8n-nodes-base.if - if
Config choices
Version 1

Block 17 - Slack Alert Dispatcher

Type / Role
n8n-nodes-base.slack - slack
Config choices
Version 2.4

Block 18 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Detect fraud in user activity with PostgreSQL, OpenAI and Slack
Complexity advanced
Nodes 18
Categories SecOps, AI Summarization
Author WeblineIndia
Published 01 May 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/15419/15419.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Detect fraud in user activity with PostgreSQL, OpenAI and Slack do?

AI Fraud Detection Workflow n8n + PostgreSQL + OpenAI + Slack This AI Fraud Detection Workflow is an automated n8n pipeline that analyzes user activity in real time using a combination of rule...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your SecOps, AI Summarization use case.