@digibandit
{
"name": "It flow test",
"nodes": [
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Parser for Retell AI webhook payload\\n\\nconst call = $json.body?.call ?? {};\\nconst analysis = call.call_analysis?.custom_analysis_data ?? {};\\n\\nconst clean = (v) => (typeof v === 'string' ? v.trim() : (v || ''));\\n\\nreturn {\\n contact_name: clean(analysis.name) || \\"Unknown Caller\\",\\n contact_email: clean(analysis.email),\\n contact_phone: clean(call.from_number),\\n\\n ticket_subject: \`Support Request - ${clean(analysis.issue) || \\"AI Captured\\"}\`,\\n ticket_details: clean(analysis.summary) || clean(call.transcript) || \\"No details provided\\",\\n\\n client_name: clean(analysis.name) || \\"Unknown Caller\\",\\n email: clean(analysis.email),\\n issue: clean(analysis.summary) || \\"No issue provided\\",\\n\\n timestamp: new Date().toISOString(),\\n call_id: clean(call.id),\\n call_start: clean(call.start_time),\\n call_end: clean(call.end_time)\\n};"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-624,
96
],
"id": "<redacted>",
"name": "Sort Data"
},
{
"parameters": {
"url": "https://<redacted>.com/api/v1/contacts/read.php",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "api_key",
"value": "<redacted>"
},
{
"name": "contact_email",
"value": "={{ $json.contact_email }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-464,
96
],
"id": "<redacted>",
"name": "Lookup Contact",
"alwaysOutputData": true
},
{
"parameters": {
"conditions": {
"conditions": [
{
"leftValue": "={{ $json.success }}",
"rightValue": "True",
"operator": {
"type": "string",
"operation": "equals"
}
}
]
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
-64,
96
],
"id": "<redacted>",
"name": "Contact Exists?"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"name": "client_id",
"value": "={{ $json.data[0].contact_client_id }}"
},
{
"name": "ticket_contact_id",
"value": "={{ $json.data[0].contact_id }}"
},
{
"name": "=",
"value": "={{ $('Sort Data').item.json }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
288,
-16
],
"id": "<redacted>",
"name": "Set Existing IDs",
"alwaysOutputData": true
},
{
"parameters": {
"method": "POST",
"url": "https://<redacted>.com/api/v1/clients/create.php",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\\n \\"api_key\\":\\n \\"client_name\\": \\"{{ $('Sort Data').item.json.client_name }}\\",\\n \\"client_email\\": \\"{{ $('Sort Data').item.json.email }}\\",\\n \\"client_type\\": \\"Lead\\",\\n \\"client_referral\\": \\"Retell AI Bot\\",\\n \\"client_rate\\": \\"90\\",\\n \\"client_currency_code\\": \\"CAD\\",\\n \\"client_net_terms\\": \\"30\\",\\n \\"client_notes\\": \\"created by Retell AI automation\\"\\n}",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
160,
192
],
"id": "<redacted>",
"name": "Create Client"
},
{
"parameters": {
"method": "POST",
"url": "https://<redacted>.com/api/v1/contacts/create.php",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\\n \\"api_key\\": \\n \\"client_id\\": \\"{{ $('Create Client').item.json.data[0].insert_id }}\\",\\n \\"contact_name\\": \\"{{ $('Sort Data').item.json.contact_name }}\\",\\n \\"contact_title\\": \\"AI Lead\\",\\n \\"contact_email\\": \\"{{ $('Sort Data').item.json.contact_email }}\\",\\n \\"contact_phone\\": \\"{{ $('Sort Data').item.json.contact_phone }}\\",\\n \\"contact_notes\\": \\"created by Retell AI automation\\"\\n}",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
352,
192
],
"id": "<redacted>",
"name": "Create Contact"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"name": "client_id",
"value": "={{ $('Create Client').item.json.data[0].insert_id }}"
},
{
"name": "ticket_contact_id",
"value": "={{ $json.data[0].insert_id }}"
},
{
"name": "=",
"value": "={{ $('Sort Data').item.json }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
544,
192
],
"id": "<redacted>",
"name": "Set New IDs"
},
{
"parameters": {
"method": "POST",
"url": "https://<redacted>.com/api/v1/tickets/create.php",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\\n \\"api_key\\": \\n \\"client_id\\": \\"{{ $json.client_id }}\\",\\n \\"ticket_contact_id\\": \\"{{ $json.ticket_contact_id }}\\",\\n \\"ticket_subject\\": \\"{{ $('Sort Data').item.json.ticket_subject }}\\",\\n \\"ticket_details\\": \\"{{ $('Sort Data').item.json.ticket_details }}\\",\\n \\"ticket_priority\\": \\"Low\\",\\n \\"ticket_assigned_to\\": \\"0\\"\\n}",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
944,
96
],
"id": "<redacted>",
"name": "Create Ticket"
},
{
"parameters": {
"httpMethod": "POST",
"path": "retell-ai-webhook",
"options": {}
},
"type": "n8n-nodes-base.webhook",
"typeVersion": 2.1,
"position": [
-800,
96
],
"id": "<redacted>",
"name": "Retell AI Lead",
"webhookId": "retell-ai-webhook"
}
],
"pinData": {},
"connections": {
"Sort Data": {
"main": [
[
{
"node": "Lookup Contact",
"type": "main",
"index": 0
}
]
]
},
"Lookup Contact": {
"main": [
[
{
"node": "Contact Exists?",
"type": "main",
"index": 0
}
]
]
},
"Contact Exists?": {
"main": [
[
{
"node": "Set Existing IDs",
"type": "main",
"index": 0
}
],
[
{
"node": "Create Client",
"type": "main",
"index": 0
}
]
]
},
"Set Existing IDs": {
"main": [
[
{
"node": "Create Ticket",
"type": "main",
"index": 0
}
]
]
},
"Create Client": {
"main": [
[
{
"node": "Create Contact",
"type": "main",
"index": 0
}
]
]
},
"Create Contact": {
"main": [
[
{
"node": "Set New IDs",
"type": "main",
"index": 0
}
]
]
},
"Set New IDs": {
"main": [
[
{
"node": "Create Ticket",
"type": "main",
"index": 0
}
]
]
},
"Retell AI Lead": {
"main": [
[
{
"node": "Sort Data",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "380fe481-5d75-4040-a91c-d5f93a094cd7",
"meta": {
"instanceId": "2b92c2205e678906f56c87a8ed9aa14dac5ea67ef7d6c927947d8bf65e9ba4e5"
},
"id": "dGdMyQvzE3Qm15o3",
"tags": []
}