This workflow follows the HTTP Request → OpenAI recipe pattern — see all workflows that pair these two integrations.
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 →
{
"name": "WhatsApp - Receive Messages",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "whatsapp/={{$parameter[\"companyId\"]}}",
"responseMode": "responseNode",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "companyId",
"value": "={{$node[\"Webhook\"].json[\"companyId\"]}}"
},
{
"name": "phoneNumber",
"value": "={{$node[\"Webhook\"].json[\"data\"][\"key\"][\"remoteJid\"].split('@')[0]}}"
},
{
"name": "messageText",
"value": "={{$node[\"Webhook\"].json[\"data\"][\"message\"][\"conversation\"] || $node[\"Webhook\"].json[\"data\"][\"message\"][\"extendedTextMessage\"][\"text\"]}}"
},
{
"name": "messageId",
"value": "={{$node[\"Webhook\"].json[\"data\"][\"key\"][\"id\"]}}"
},
{
"name": "timestamp",
"value": "={{$node[\"Webhook\"].json[\"data\"][\"messageTimestamp\"]}}"
}
]
},
"options": {}
},
"name": "Extract Data",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
450,
300
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "INSERT INTO contacts (company_id, phone, whatsapp_id, last_contact_at)\nVALUES ('{{$node[\"Extract Data\"].json[\"companyId\"]}}', '{{$node[\"Extract Data\"].json[\"phoneNumber\"]}}', '{{$node[\"Extract Data\"].json[\"phoneNumber\"]}}', NOW())\nON CONFLICT (company_id, phone) \nDO UPDATE SET \n last_contact_at = NOW(),\n total_conversations = contacts.total_conversations + 1\nRETURNING *",
"additionalFields": {}
},
"name": "Find or Create Contact",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [
650,
300
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "SELECT * FROM conversations \nWHERE contact_id = '{{$node[\"Find or Create Contact\"].json[\"id\"]}}' \nAND status IN ('open', 'pending') \nORDER BY created_at DESC \nLIMIT 1",
"additionalFields": {}
},
"name": "Check Open Conversation",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [
850,
300
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{$node[\"Check Open Conversation\"].json.length}}",
"operation": "equal",
"value2": 0
}
]
}
},
"name": "IF No Conversation",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1050,
300
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "INSERT INTO conversations (company_id, contact_id, channel_id, status, last_message_at)\nSELECT \n '{{$node[\"Extract Data\"].json[\"companyId\"]}}',\n '{{$node[\"Find or Create Contact\"].json[\"id\"]}}',\n id,\n 'open',\n NOW()\nFROM channels \nWHERE company_id = '{{$node[\"Extract Data\"].json[\"companyId\"]}}' \nAND type = 'whatsapp' \nLIMIT 1\nRETURNING *"
},
"name": "Create Conversation",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [
1250,
200
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "INSERT INTO messages (conversation_id, sender_type, content, external_id, created_at)\nVALUES (\n '{{$node[\"Merge\"].json[\"conversation_id\"]}}',\n 'contact',\n '{{$node[\"Extract Data\"].json[\"messageText\"]}}',\n '{{$node[\"Extract Data\"].json[\"messageId\"]}}',\n NOW()\n)\nRETURNING *"
},
"name": "Save Message",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [
1650,
300
]
},
{
"parameters": {},
"name": "Merge",
"type": "n8n-nodes-base.merge",
"typeVersion": 1,
"position": [
1450,
300
]
},
{
"parameters": {
"resource": "text",
"operation": "message",
"model": "gpt-4-turbo-preview",
"messages": {
"values": [
{
"role": "system",
"content": "Voc\u00ea \u00e9 um assistente que analisa mensagens de clientes. Retorne APENAS um objeto JSON com:\n- sentiment: \"positive\" | \"neutral\" | \"negative\"\n- intent: \"question\" | \"complaint\" | \"compliment\" | \"sales\" | \"support\"\n- urgency: \"low\" | \"medium\" | \"high\"\n- tags: array de strings com tags relevantes\n- suggested_response: sugest\u00e3o de resposta em portugu\u00eas"
},
{
"role": "user",
"content": "={{$node[\"Extract Data\"].json[\"messageText\"]}}"
}
]
},
"options": {
"temperature": 0.3
}
},
"name": "AI Analysis",
"type": "n8n-nodes-base.openAi",
"typeVersion": 1,
"position": [
1850,
300
],
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"url": "={{$env[\"BACKEND_URL\"]}}/api/socket/emit",
"method": "POST",
"bodyParameters": {
"values": [
{
"name": "event",
"value": "new_message"
},
{
"name": "room",
"value": "conversation:={{$node[\"Save Message\"].json[\"conversation_id\"]}}"
},
{
"name": "data",
"value": "={{JSON.stringify($node[\"Save Message\"].json)}}"
}
]
},
"options": {}
},
"name": "Emit Socket Event",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
2250,
300
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "UPDATE messages \nSET \n ai_suggestion = '{{$node[\"AI Analysis\"].json[\"choices\"][0][\"message\"][\"content\"]}}',\n ai_metadata = '{{JSON.stringify($node[\"AI Analysis\"].json)}}'\nWHERE id = '{{$node[\"Save Message\"].json[\"id\"]}}'"
},
"name": "Update Message with AI",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [
2050,
300
]
},
{
"parameters": {
"mode": "raw",
"jsonOutput": "={\"success\": true, \"messageId\": \"{{$node[\"Save Message\"].json[\"id\"]}}\"}"
},
"name": "Response",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
2450,
300
]
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "Extract Data",
"type": "main",
"index": 0
}
]
]
},
"Extract Data": {
"main": [
[
{
"node": "Find or Create Contact",
"type": "main",
"index": 0
}
]
]
},
"Find or Create Contact": {
"main": [
[
{
"node": "Check Open Conversation",
"type": "main",
"index": 0
}
]
]
},
"Check Open Conversation": {
"main": [
[
{
"node": "IF No Conversation",
"type": "main",
"index": 0
}
]
]
},
"IF No Conversation": {
"main": [
[
{
"node": "Create Conversation",
"type": "main",
"index": 0
}
],
[
{
"node": "Merge",
"type": "main",
"index": 1
}
]
]
},
"Create Conversation": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 0
}
]
]
},
"Merge": {
"main": [
[
{
"node": "Save Message",
"type": "main",
"index": 0
}
]
]
},
"Save Message": {
"main": [
[
{
"node": "AI Analysis",
"type": "main",
"index": 0
}
]
]
},
"AI Analysis": {
"main": [
[
{
"node": "Update Message with AI",
"type": "main",
"index": 0
}
]
]
},
"Update Message with AI": {
"main": [
[
{
"node": "Emit Socket Event",
"type": "main",
"index": 0
}
]
]
},
"Emit Socket Event": {
"main": [
[
{
"node": "Response",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {},
"staticData": null,
"tags": [],
"triggerCount": 1,
"updatedAt": "2024-01-01T00:00:00.000Z",
"versionId": "1"
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
openAiApipostgres
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
WhatsApp - Receive Messages. Uses postgres, openAi, httpRequest. Webhook trigger; 12 nodes.
Source: https://github.com/suntzu62/MultiChannel/blob/bc085acf9e24125d4f3a02291ad6577c9bc63feb/n8n-workflows/whatsapp-receiver.json — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Eu Clara – Funil Kiwify Completo. Uses postgres, openAi, httpRequest, gmail. Webhook trigger; 70 nodes.
Lua Nova - Sistema Completo. Uses postgres, httpRequest, openAi. Webhook trigger; 55 nodes.
User Signup & Verification: The workflow starts when a user signs up. It generates a verification code and sends it via SMS using Twilio. Code Validation: The user replies with the code. The workflow
Send-Outreach. Uses postgres, openAi, httpRequest, emailSend. Webhook trigger; 15 nodes.
AI Resume Screening Workflow. Uses openAi, emailSend, httpRequest, postgres. Webhook trigger; 14 nodes.