diff --git a/workflows/Automated Email Inquiry Processing & Routing with Gmail and Gemini AI-6633/automated_email_inquiry_processing_routing_with_gmail_and_gemini_ai.json b/workflows/Automated Email Inquiry Processing & Routing with Gmail and Gemini AI-6633/automated_email_inquiry_processing_routing_with_gmail_and_gemini_ai.json new file mode 100644 index 000000000..0d403409d --- /dev/null +++ b/workflows/Automated Email Inquiry Processing & Routing with Gmail and Gemini AI-6633/automated_email_inquiry_processing_routing_with_gmail_and_gemini_ai.json @@ -0,0 +1 @@ +{"id":"Jvq4AmoNIbbAwo5x","meta":{"instanceId":"dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281","templateCredsSetupCompleted":true},"name":"AI-Powered Smart Inquiry & Booking Assistant for Any Industry","tags":[],"nodes":[{"id":"e39522a9-4024-4b8e-84c0-4d77cd49e266","name":"Gmail Trigger","type":"n8n-nodes-base.gmailTrigger","position":[-500,120],"parameters":{"simple":false,"filters":{"sender":"acdert@gmail.com"},"options":{},"pollTimes":{"item":[{"mode":"everyX","unit":"minutes"}]}},"credentials":{"gmailOAuth2":{"id":"PcTqvGU9uCunfltE","name":"Gmail account - test"}},"typeVersion":1.2},{"id":"92249d18-6db6-4e2b-a8c6-7cdaabf68360","name":"AI Agent","type":"@n8n/n8n-nodes-langchain.agent","position":[-280,120],"parameters":{"text":"={{ $json.text }}","options":{"systemMessage":"You are a smart AI assistant for [Business Name] (e.g., Cool Realty, AutoDeals, HealthPlus).\n\nBased on the customer’s message, decide the intent:\n\n\"check_info\" → if they request product/service availability, pricing, or details\n\n\"forward_action\" → if they want to book, buy, confirm, schedule, or take the next step\n\nReturn only one JSON including:\n\naction: either \"check_info\" or \"forward_action\"\n\nreasoning: brief summary of how you inferred the action\n\ndata_extracted: structured info from the email (e.g., name, date, service, etc.)\n\nreply: full, professional, human-like response to the user’s message\n\nBehavior logic:\n\nAssume 70% availability for requested service/product\n\nRandomly generate sample details (features, price, timelines, etc.)\n\nIf not available, suggest alternatives\n\nUse a warm, helpful, professional tone. Output only the JSON. No extra text.\n\n"},"promptType":"define"},"typeVersion":1.9},{"id":"1e6c541e-30c6-4a4b-86fd-8bc31ca4c798","name":"Google Gemini Chat Model","type":"@n8n/n8n-nodes-langchain.lmChatGoogleGemini","position":[-280,340],"parameters":{"options":{},"modelName":"models/gemini-2.5-pro"},"credentials":{"googlePalmApi":{"id":"RvSkIBjP48ORJKhU","name":"Google Gemini(PaLM) Api account - test"}},"typeVersion":1},{"id":"d98d2938-f78e-4d0d-a89f-a2629f58c1a9","name":"HTTP Request","type":"n8n-nodes-base.httpRequestTool","disabled":true,"position":[-60,320],"parameters":{"url":"=https://google.serper.dev/search","method":"POST","options":{"redirect":{"redirect":{}}},"sendBody":true,"sendHeaders":true,"bodyParameters":{"parameters":[{"name":"=q","value":"={{ $fromAI('parameters0_Value', ``, 'string') }}"}]},"headerParameters":{"parameters":[{"name":"X-API-KEY","value":"b05bf2fc7c01a8a70ecac675eafeb00777c8db22"}]}},"typeVersion":4.2},{"id":"5755463a-5ef3-409b-9c06-e1acb85e14e1","name":"Code","type":"n8n-nodes-base.code","position":[60,120],"parameters":{"jsCode":"const output = [];\n\nfor (const item of $input.all()) {\n // 1. Grab the raw string from the 'output' field\n let raw = item.json.output;\n if (typeof raw !== 'string') {\n // nothing to do\n output.push({ json: {} });\n continue;\n }\n\n // 2. Remove `````` fences\n raw = raw.replace(/``````/g, '').trim();\n\n // 3. Extract the JSON payload between the first { and last }\n const start = raw.indexOf('{');\n const end = raw.lastIndexOf('}');\n const jsonString = (start !== -1 && end !== -1)\n ? raw.substring(start, end + 1)\n : raw;\n\n // 4. Attempt to parse\n try {\n const parsed = JSON.parse(jsonString);\n output.push({ json: parsed });\n } catch (e) {\n // on error, output the raw string and error\n output.push({\n json: {\n error: e.message,\n raw: jsonString\n }\n });\n }\n}\n\nreturn output;\n"},"typeVersion":2},{"id":"ba012b2b-8207-4639-b57b-79956c5bdba8","name":"If","type":"n8n-nodes-base.if","position":[460,120],"parameters":{"options":{},"conditions":{"options":{"version":2,"leftValue":"","caseSensitive":true,"typeValidation":"strict"},"combinator":"and","conditions":[{"id":"e4cc28d0-bee8-475a-b0fb-fa446fbfb954","operator":{"name":"filter.operator.equals","type":"string","operation":"equals"},"leftValue":"={{ $json.action }}","rightValue":"check_availability"}]}},"typeVersion":2.2},{"id":"cbae6b70-6d91-4973-b149-6a960515f06b","name":"Forward booking email","type":"n8n-nodes-base.gmail","position":[720,200],"webhookId":"482cede1-d0e5-4556-a1f7-e5c836dc8ae7","parameters":{"sendTo":"abc@gmail.com","message":"=Name : {{ $json.customer_data.name }}\nEmail : {{ $json.customer_data.email }}\nPhone: {{ $json.customer_data.phone }}\nOriginal Message: {{ $json.customer_data.message }}\n\nInternal Note: {{ $json.internal_note }}\n\nSummary : {{ $json.booking_summary }}","options":{},"subject":"Inquiry Details","emailType":"text"},"credentials":{"gmailOAuth2":{"id":"PcTqvGU9uCunfltE","name":"Gmail account - test"}},"typeVersion":2.1},{"id":"7f784192-0b32-437c-bd2a-6ecb4b51f2c8","name":"availability check email","type":"n8n-nodes-base.gmail","position":[720,20],"webhookId":"482cede1-d0e5-4556-a1f7-e5c836dc8ae7","parameters":{"sendTo":"={{ $json.customer_data.email }}","message":"={{ $('Code').item.json.email_response }}","options":{},"subject":"Inquiry Details","emailType":"text"},"credentials":{"gmailOAuth2":{"id":"PcTqvGU9uCunfltE","name":"Gmail account - test"}},"typeVersion":2.1},{"id":"99fc6c79-6888-4093-968b-668f8cec525b","name":"Workflow Overview","type":"n8n-nodes-base.stickyNote","position":[-520,-160],"parameters":{"width":780,"height":240,"content":"## Workflow Overview 📧\n\nThis workflow automates the processing of any inquiry emails:\n\n1. **Gmail Trigger**: Initiates the workflow upon receiving a new email.\n2. **AI Agent**: Analyzes the email content to determine the customer's intent (availability check or direct booking).\n3. **Code**: Parses the JSON output from the AI Agent.\n4. **If**: Routes the workflow based on the detected intent.\n5. **Gmail Nodes**: Sends appropriate responses or forwards booking details."},"typeVersion":1},{"id":"0333faf4-3690-487a-a151-ac329c1eacd8","name":"AI Agent and Code Explanation","type":"n8n-nodes-base.stickyNote","position":[120,400],"parameters":{"color":5,"width":600,"height":320,"content":"## AI Agent and Code Node Explained 🤖\n\n- **AI Agent**: This node acts as an intelligent assistant, powered by the Google Gemini Chat Model (although the Google Gemini Chat Model node currently has execution issues). It processes incoming emails and classifies them as either an \"availability check\" or a \"direct booking request\" based on the prompt instructions. It also attempts to extract relevant customer data and generate appropriate responses or internal notes.\n- **HTTP Request (Disabled)**: This node is currently disabled and not used by the AI Agent, but it is set up to make a search request to Serper.\n- **Code**: This node is crucial for parsing the raw string output from the AI Agent into a usable JSON format. It handles potential formatting inconsistencies by removing markdown fences and extracting the valid JSON payload, making the data accessible for subsequent nodes."},"typeVersion":1},{"id":"1772a67e-ac94-45f5-b37d-1ef3084b9891","name":"Conditional Routing and Email Responses","type":"n8n-nodes-base.stickyNote","position":[300,-280],"parameters":{"color":4,"width":600,"height":280,"content":"## Conditional Routing & Email Responses 🚦\n\n- **Wait**: This node is used for wait for data.\n- **If**: This node acts as a decision point, checking the `action` field from the AI Agent's parsed output. If the `action` is `check_availability`, the workflow proceeds to the \"availability check email\" node.\n- **availability check email**: This Gmail node sends an email directly to the customer with availability details, as provided by the AI Agent's `email_response`.\n- **Forward booking email**: If the `If` node's condition is not met (meaning the action is `forward_booking`), this Gmail node is triggered. It forwards the customer's booking request details and internal notes to a predefined internal email address (`@gmail.com`) for manual processing."},"typeVersion":1},{"id":"3cfad505-0925-4b8d-b275-c7e319764925","name":"Wait for Data","type":"n8n-nodes-base.wait","position":[280,120],"webhookId":"4e0cbcd3-6378-4ff8-bda1-cd43550f3088","parameters":{},"typeVersion":1.1}],"active":false,"pinData":{},"settings":{"executionOrder":"v1"},"versionId":"1dd6ab03-d62a-4ed1-b2da-1f254160ff20","connections":{"If":{"main":[[{"node":"availability check email","type":"main","index":0}],[{"node":"Forward booking email","type":"main","index":0}]]},"Code":{"main":[[{"node":"Wait for Data","type":"main","index":0}]]},"AI Agent":{"main":[[{"node":"Code","type":"main","index":0}]]},"HTTP Request":{"ai_tool":[[{"node":"AI Agent","type":"ai_tool","index":0}]]},"Gmail Trigger":{"main":[[{"node":"AI Agent","type":"main","index":0}]]},"Wait for Data":{"main":[[{"node":"If","type":"main","index":0}]]},"Google Gemini Chat Model":{"ai_languageModel":[[{"node":"AI Agent","type":"ai_languageModel","index":0}]]}}} \ No newline at end of file