{ "meta": { "instanceId": "e4f78845dfed9ddcfba1945ae00d12e9a7d76eab052afd19299228ce02349d86" }, "nodes": [ { "id": "23291d25-3e1a-4b0d-9b1d-d066e8c04a1f", "name": "Customer Lead AI Agent", "type": "@n8n/n8n-nodes-langchain.agent", "position": [ -640, 460 ], "parameters": { "text": "=**System Prompt:**\n\nYou are an AI assistant designed to process new leads and generate appropriate responses. Your role includes analyzing lead notes, categorizing them, and generating an email from the system to inform the relevant contact about the inquiry. Do not send the email as if it is directly from the customer; instead, draft it as a notification from the system summarizing the inquiry.\n\n### **Process Flow**\n\n1. **Analyzing Lead Notes:**\n - Extract key details such as the customer name, organization, contact information, and their specific request. \n - Determine if the inquiry relates to products, services, or solutions offered by the company.\n\n2. **Finding the Appropriate Contact(s):**\n - Search the contact database to find the responsible person(s) for the relevant product, service, or solution. \n - If one person is responsible, provide their email. \n - If multiple people are responsible, list all emails separated by commas.\n\n3. **Generating an Email Notification:**\n - Draft a professional email as a notification from the system.\n - Summarize the customer’s inquiry.\n - Include all relevant details to assist the recipient in addressing the inquiry.\n\n4. **Handling Invalid Leads:**\n - If the inquiry is unrelated to products, services, or solutions (e.g., job inquiries or general product inquiries), classify it as invalid and return: \n `\"Invalid Lead - Not related to products, services, or solutions.\"`\n\n### **Output Requirements**\n\n1. **For Relevant Leads:**\n - **Email Address(es):** Provide the appropriate email(s). \n - **Email Message Body:** Generate an email notification from the system summarizing the inquiry.\n\n2. **For Invalid Leads:**\n - Return: `\"Invalid Lead - Not related to products, services, or solutions.\"`\n\n\n### **Email Template for Relevant Leads**\n\n**Email Address(es):** [Relevant Email IDs]\n\n**Email Message Body:**\n\n_Subject: New Inquiry from Customer Regarding [Product/Service/Solution]_ \n\nDear [Recipient(s)], \n\nWe have received a new inquiry from a customer through our system. Below are the details: \n\n**Customer Name:** [Customer Name] \n**Organization:** [Organization Name] \n**Contact Information:** [Contact Details] \n\n**Inquiry Summary:** \n[Summarized description of the customer's request, e.g., “The customer is seeking to upgrade their restroom facilities with touchless soap dispensers and tissue holders installed behind mirrors. They have requested a site visit to assess the location and provide a proposal.”] \n\n**Action Required:** \nPlease prioritize this inquiry and reach out to the customer promptly to address their requirements. \n\nThank you, \n[Your System Name] \n\n\n### **Example Output**\n\n**Input Lead Notes:**\n*\"Dear Syncbricks, We are looking to Develop Workflow Automation Soluition for our company, can you let us know the details what do you offer in tems of this.\"*\n\n**Output:**\n\n- **Email Address(es):** employee@syncbricks.com\n\n- **Email Message Body:** \n\n_Subject: Workflow Automation Platform Integration_ \n\nDear -Emploiyee Name (s) --, \n\nWe have received a new inquiry from a customer through our system. Below are the details: \n\n**Customer Name:** Amjid Ali \n**Organization:** Syncbricks LLC\n**Contact Information:** 123456789 \n\n**Inquiry Summary:** \nThe customer is asking for workflow automation for their company \n\n**Action Required:** \nPlease prioritize this inquiry and reach out to the customer promptly to address their requirements. \n\nThank you, \nSyncbricks LLC\n\n---\nHere are the Lead Details\nLead Name : {{ $json.data.lead_name }}\nCompany : {{ $json.data.company_name }}\nSource : {{ $json.data.source }}\nNotes : {{ $json.data.notes }}\nCity : {{ $json.data.city }}\nCountry : {{ $json.data.country }}\nMobile : {{ $json.data.mobile_no }}", "options": {}, "promptType": "define" }, "typeVersion": 1.7 }, { "id": "1831dc36-910b-4a72-a90e-b411f105a8c3", "name": "OpenAI Chat Model", "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "position": [ -800, 800 ], "parameters": { "options": {} }, "credentials": { "openAiApi": { "id": "hTl3a2XqteCwExYY", "name": "OpenAi account" } }, "typeVersion": 1 }, { "id": "79713c56-2f7c-4872-90e4-331715f54048", "name": "Abbriviations", "type": "n8n-nodes-base.googleSheetsTool", "position": [ -640, 800 ], "parameters": { "options": {}, "sheetName": { "__rl": true, "mode": "list", "value": "gid=0", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gtdrAe-jjQH9gQdXA9PJ5y3dSAN4i6k_Rs5sDyALIfU/edit#gid=0", "cachedResultName": "abbrivaitions" }, "documentId": { "__rl": true, "mode": "list", "value": "1gtdrAe-jjQH9gQdXA9PJ5y3dSAN4i6k_Rs5sDyALIfU", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gtdrAe-jjQH9gQdXA9PJ5y3dSAN4i6k_Rs5sDyALIfU/edit?usp=drivesdk", "cachedResultName": "Abbriviations List" } }, "credentials": { "googleSheetsOAuth2Api": { "id": "L3lApjbQfMm36LLX", "name": "Google Sheets account" } }, "typeVersion": 4.5 }, { "id": "73b1e3c9-4703-4f87-8399-e7a9bf368d4c", "name": "Lead Body", "type": "n8n-nodes-base.set", "position": [ -1640, 640 ], "parameters": { "options": {}, "assignments": { "assignments": [ { "id": "82a674a2-4d12-45f2-b276-cc95cf7b2e93", "name": "body", "type": "object", "value": "={{ $json.body }}" } ] } }, "typeVersion": 3.4 }, { "id": "5f25d846-c639-49e5-bea2-160000bfb104", "name": "Source Website and Status Open", "type": "n8n-nodes-base.if", "position": [ -1920, 640 ], "parameters": { "options": {}, "conditions": { "options": { "version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "combinator": "and", "conditions": [ { "id": "2b184de2-a64e-44e3-8f25-645539681533", "operator": { "name": "filter.operator.equals", "type": "string", "operation": "equals" }, "leftValue": "={{ $json.body.source }}", "rightValue": "Website" }, { "id": "9632cf65-11a1-483c-95c8-94bfe84fb243", "operator": { "name": "filter.operator.equals", "type": "string", "operation": "equals" }, "leftValue": "={{ $json.body.status }}", "rightValue": "Open" } ] } }, "typeVersion": 2.2 }, { "id": "12ba65c9-0890-4862-9704-98492eb8f637", "name": "Microsoft Outlook", "type": "n8n-nodes-base.microsoftOutlook", "position": [ 1180, 580 ], "parameters": { "subject": "={{ $('Fields for Outlook').item.json.subject }}", "bodyContent": "={{ $json.html }}\nHere is Lead {{ $('Source Website and Status Open').item.json.body.name }} \n", "toRecipients": "= {{ $('Fields for Outlook').item.json.email_addresses }}", "additionalFields": { "bodyContentType": "html" } }, "credentials": { "microsoftOutlookOAuth2Api": { "id": "9gy3uvf3pmBdpEsq", "name": "Microsoft Outlook Al Ansari" } }, "typeVersion": 2 }, { "id": "b1410997-3705-4234-918e-a14e4ccc6b70", "name": "Email Body Text Generated by AI", "type": "n8n-nodes-base.set", "position": [ 700, 580 ], "parameters": { "options": {}, "assignments": { "assignments": [ { "id": "cdce31fb-2ec9-45ce-a4ac-a6ff9c811dc3", "name": "email_body", "type": "string", "value": "={{ $json.email_body }}" } ] } }, "typeVersion": 3.4 }, { "id": "b10684b9-9f72-42b3-a9f9-c54e711ceb59", "name": "Fields for Outlook", "type": "n8n-nodes-base.code", "position": [ 360, 600 ], "parameters": { "jsCode": "// Input text from the `output` field\nconst textOutput = $json?.output || '';\n\n// Function to extract values from the text\nfunction extractFields(text) {\n const fields = {};\n\n // Regular expressions to extract each field\n const emailMatch = text.match(/\\*\\*Email Address\\(es\\):\\*\\*\\s*([^\\n]+)/);\n const subjectMatch = text.match(/_Subject:\\s*([^_]+)/);\n const emailBodyMatch = text.match(/Dear[\\s\\S]+/);\n\n // Assign extracted values to the fields\n fields.email_addresses = emailMatch ? emailMatch[1].trim() : null;\n fields.subject = subjectMatch ? subjectMatch[1].trim() : null;\n fields.email_body = emailBodyMatch ? emailBodyMatch[0].trim() : null;\n\n return fields;\n}\n\n// Extract fields from the output\nconst extractedFields = extractFields(textOutput);\n\n// Return the fields as JSON\nreturn {\n json: extractedFields\n};\n" }, "typeVersion": 2 }, { "id": "e2c10569-fde2-425c-8b20-fdb32a6e2bd5", "name": "Email Body for Outlook", "type": "n8n-nodes-base.code", "position": [ 860, 580 ], "parameters": { "jsCode": "// Input email body\nconst emailBody = $json.email_body || '';\n\n// Function to convert plain text email body into HTML\nfunction formatEmailBodyAsHtml(body) {\n // Replace markdown-like sections with corresponding HTML\n let htmlBody = body\n .replace(/\\*\\*Customer Name:\\*\\* (.+)/, '
Customer Name: $1
')\n .replace(/\\*\\*Organization:\\*\\* (.+)/, 'Organization: $1
')\n .replace(/\\*\\*Contact Information:\\*\\* (.+)/, 'Contact Information: $1
')\n .replace(/\\*\\*Inquiry Summary:\\*\\*\\s*([\\s\\S]+?)(?=\\n\\n\\*\\*Action Required:)/, 'Inquiry Summary: $1
')\n .replace(/\\*\\*Action Required:\\*\\*\\s*([\\s\\S]+)/, 'Action Required: $1
');\n\n // Wrap each paragraph in `` tags for better readability\n htmlBody = htmlBody\n .replace(/Dear (.+?),/, '
Dear $1,
')\n .replace(/Thank you,\\s+(.+)/, 'Thank you,
$1