# Citizen Complaint Routing & SLA Escalation

**Category:** Government  
**Tools:** n8n, OpenAI, HTTP  
**Nodes:** 22  
**Built by:** Forgent Systems

Takes complaints over WhatsApp, has AI classify them and route them to the right department, stores them in a database and confirms receipt. Complaints that miss their SLA are escalated automatically.

![Workflow](preview.webp)

## How it works

1. A WhatsApp message arrives through a webhook.
2. AI classifies the complaint (water, electricity, sanitation and so on).
3. It's assigned to the right department and saved in Postgres.
4. The citizen gets a confirmation with a reference.
5. Every few minutes, pending complaints are checked and SLA breaches are escalated.

## Use cases

- Municipal corporations
- Utility providers
- Housing societies and campuses

## Setup

1. In n8n open **Workflows → Import from File** and choose `workflow.json`.
2. Connect these credentials:
   - OpenAI account
   - Postgres account
   - Twilio account
3. Point the Sheets / Airtable / Drive / Slack nodes at your own resources (structure above).
4. Replace placeholder emails, phone numbers and `YOUR-FORM-ID` links with your own.
5. Times use the America/New_York timezone and dates use MM/DD/YYYY. Adjust if needed.
6. Run a test execution, then activate.

## Nodes

- **OpenAI Chat Model** — `@n8n/n8n-nodes-langchain.lmChatOpenAi`
- **Simple Memory** — `@n8n/n8n-nodes-langchain.memoryBufferWindow`
- **Citizen Request Webhook** — `n8n-nodes-base.webhook`
- **Extract WhatsApp Message** — `n8n-nodes-base.set`
- **AI Complaint Classifier** — `@n8n/n8n-nodes-langchain.agent`
- **Route to Department** — `n8n-nodes-base.switch`
- **Assign Water Department** — `n8n-nodes-base.set`
- **Assign Electricity Department** — `n8n-nodes-base.set`
- **Assign Sanitation Department** — `n8n-nodes-base.set`
- **Save Complaint to Database** — `n8n-nodes-base.postgres`
- **Generate Confirmation Message** — `n8n-nodes-base.code`
- **Send WhatsApp Notification** — `n8n-nodes-base.twilio`
- **SLA Scheduler (Every 5 Minutes)** — `n8n-nodes-base.scheduleTrigger`
- **Fetch Pending Complaints** — `n8n-nodes-base.postgres`
- **Check SLA Breach** — `n8n-nodes-base.if`
- **Mark Complaint as Escalated** — `n8n-nodes-base.postgres`
- **Assign Senior Officer** — `n8n-nodes-base.set`
- **Generate Escalation Alert Message** — `n8n-nodes-base.code`
- **Send Escalation WhatsApp Alert** — `n8n-nodes-base.twilio`
- **No SLA Breach (Skip)** — `n8n-nodes-base.noOp`
- **Sticky Note1** — `n8n-nodes-base.stickyNote`
- **Sticky Note** — `n8n-nodes-base.stickyNote`
