{
  "id": "OskjNtIb2AnxHXP2",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automated Multilingual Gmail Draft Reply with OpenAI GPT-4o in n8n",
  "tags": [
    {
      "id": "UXY9NrpVC8pjYHmK",
      "name": "n8n Template",
      "createdAt": "2025-06-05T07:41:37.020Z",
      "updatedAt": "2025-06-05T07:41:37.020Z"
    }
  ],
  "nodes": [
    {
      "id": "579d54f2-8c04-4624-890a-c432d96f3911",
      "name": "If Needs Reply",
      "type": "n8n-nodes-base.if",
      "position": [
        1500,
        220
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "53849246-ad32-4845-9976-9f9688f5a6f2",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.needsReply }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "526ab96e-bf2a-44f5-9e1b-3b1a10b5f55b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        580,
        0
      ],
      "parameters": {
        "width": 444,
        "height": 434,
        "content": "### Gmail Trigger\n\nGet new incoming messages from Gmail with a specific label.\n\nIn this example, the \"Inquiry\" label is used. Feel free to set it up using other Gmail filters.\n\n\u26a0\ufe0f Adjust the time (polling) interval according to your needs.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "7289a14b-225e-4399-aa6c-cb56158f450d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1100,
        0
      ],
      "parameters": {
        "width": 576,
        "height": 577,
        "content": "### Assess the email contents that need a reply\n\nThis assessment uses OpenAI GPT-4o and a JSON parser to determine whether a response is necessary and to identify the message\u2019s language."
      },
      "typeVersion": 1
    },
    {
      "id": "d10724dd-406c-4143-9c22-2c3ecd45e6be",
      "name": "Gmail - Create Draft",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2760,
        160
      ],
      "parameters": {
        "message": "={{ $json.text.replace(/\\n/g, \"<br />\\n\") }}",
        "options": {
          "sendTo": "={{ $('Gmail trigger').item.json.headers.from }}",
          "threadId": "={{ $('Gmail trigger').item.json.threadId }}"
        },
        "subject": "=Re: {{ $('Gmail trigger').item.json.headers.subject }}",
        "resource": "draft",
        "emailType": "html"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "b805dfdb-a68e-458f-9af9-8a9e773a951d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2660,
        0
      ],
      "parameters": {
        "width": 326,
        "height": 395,
        "content": "### Create a Draft in the conversation\n\nDraft Integration: after converting the text to html, it places the draft into the Gmail thread as a reply to the first message"
      },
      "typeVersion": 1
    },
    {
      "id": "cbb5c6a6-a445-474b-890f-54d1a546c28a",
      "name": "Switch based on email language",
      "type": "n8n-nodes-base.switch",
      "position": [
        1840,
        200
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Japanese version",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b9788587-ad2a-4d44-bf01-f31c9412a48d",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.message_language }}",
                    "rightValue": "Japanese"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "English version",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "429c0f4a-b5f8-4730-9609-40fe20acd496",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.message_language }}",
                    "rightValue": "English"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": 1
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "a720280e-7c5f-4f83-ad2e-b13572cba762",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1760,
        0
      ],
      "parameters": {
        "width": 813,
        "height": 740,
        "content": "### Generate a Reply\n\nDefine the output from the Switch node. Then, generate a draft reply using OpenAI GPT-4 Turbo based on the message\u2019s detected language. Establish the rules and conventions for each supported language, including appropriate greetings, closings, tone, and any other cultural considerations."
      },
      "typeVersion": 1
    },
    {
      "id": "a107790b-f883-469e-8763-61ec92bf1d8e",
      "name": "Generate email for a Japanese client",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        2080,
        160
      ],
      "parameters": {
        "text": "=Subject: {{ $('Gmail trigger').item.json.subject }}\nMessage: {{ $('Gmail trigger').item.json.textAsHtml }}",
        "messages": {
          "messageValues": [
            {
              "message": "You're a helpful personal assistant and your task is to draft replies on my behalf to my incoming emails. Whenever I provide some text from an email, return an appropriate draft reply for it and nothing else.\nEnsure that the reply is suitable for a professional email setting and addresses the topic in a clear, structured, and detailed manner.\nDo not make things up.\n\nDetailed instructions:\n- Be concise and maintain a business tone (desu-masu).\n- Follow the following content \n[INSERT CLIENT NAME] \u69d8\n\u304a\u4e16\u8a71\u306b\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002\n\u682a\u5f0f\u4f1a\u793e [INSERT YOUR COMPANY NAME] \u306e[INSERT YOUR NAME]\u3067\u3059\u3002\n\nBODY (main content)\n\n\u5f15\u304d\u7d9a\u304d\u3001\u4f55\u5352\u3069\u3046\u305e\u5b9c\u3057\u304f\u304a\u9858\u3044\u3044\u305f\u3057\u307e\u3059\u3002\n\n- When replying to yes-no questions, draft 2 responses: one affirmative and one negative separated by \" - - - - - - - OR - - - - - - - \"\n- If you don't know an answer, you can leave placeholders like \"[YOUR_ANSWER_HERE]\".\n- Don't use any special formatting, only plain text.\n- Make sure each request is separated with a new line break\n- Reply in the same language as the inbound email."
            }
          ]
        },
        "promptType": "define"
      },
      "typeVersion": 1.4
    },
    {
      "id": "a548fcdd-1f5e-4a75-b136-07ecf4e96d3d",
      "name": "Generate email reply for an English client",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        2080,
        440
      ],
      "parameters": {
        "text": "=Subject: {{ $('Gmail trigger').item.json.subject }}\nMessage: {{ $('Gmail trigger').item.json.textAsHtml }}",
        "messages": {
          "messageValues": [
            {
              "message": "You're a helpful personal assistant and your task is to draft replies on my behalf to my incoming emails. Whenever I provide some text from an email, return an appropriate draft reply for it and nothing else.\nEnsure that the reply is suitable for a professional email setting and addresses the topic in a clear, structured, and detailed manner.\nDo not make things up.\n\nDetailed instructions:\n- Be concise and maintain a business casual tone.\n- Start with \"Dear,\", and end with \"Best regards,\"\n- When replying to yes-no questions, draft 2 responses: one affirmative and one negative separated by \" - - - - - - - OR - - - - - - - \"\n- If you don't know an answer, you can leave placeholders like \"[YOUR_ANSWER_HERE]\".\n- Don't use any special formatting, only plain text.\n- Reply in the same language as the inbound email."
            }
          ]
        },
        "promptType": "define"
      },
      "typeVersion": 1.4
    },
    {
      "id": "dcdf44aa-b313-4a22-ae45-0774e5a85add",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 560,
        "height": 941,
        "content": "## Automated Multilingual Gmail Draft Reply with OpenAI GPT-4o in n8n\n\n### Who is this for?\nThis workflow is ideal for anyone who receives a high volume of Gmail inquiries, especially those providing multilingual customer support or handling diverse client \ncommunications.\n\n### What problem is this workflow solving? \nManaging frequent emails in multiple languages can be overwhelming. This workflow reduces manual drafting by automatically generating context-aware replies using OpenAI GPT-4o, letting users focus on personalization and quality assurance.\n\n### What this workflow does\n- Monitors your Gmail inbox for new emails with a specific label (e.g., \"Inquiry\").\n- Uses OpenAI GPT-4o for message assessment and language detection.\n- Parses information using a JSON parser.\n- Generates an AI-powered draft reply in the detected language via OpenAI GPT-4o.\n- Converts the reply to HTML and saves it as a draft in the original Gmail thread for your review.\n\n### Setup\n- Connect your Gmail account and set up relevant labels in both Gmail and the workflow.\n- Integrate your OpenAI credentials in n8n.\n- Configure the workflow trigger for your desired labels.\n\n## How to customize this workflow to your needs\n- Adjust label names in both Gmail and the workflow for different email categories.\n- Define custom starting and ending phrases for draft replies per supported language.\n- Expand supported languages or modify AI prompt instructions to suit your brand\u2019s tone."
      },
      "typeVersion": 1
    },
    {
      "id": "323eb990-e7c4-4495-811a-a3c5b26c27f0",
      "name": "Gmail trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        740,
        220
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "q": ""
        },
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1659ef58-d317-4260-99a8-f1de50d50839",
      "name": "OpenAI GPT-4o",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1140,
        420
      ],
      "parameters": {
        "model": "gpt-4o",
        "options": {
          "temperature": 0,
          "responseFormat": "json_object"
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "aeb51aac-0706-4a0e-8a21-cc09147a6e87",
      "name": "Assess if a message needs a reply and identify the language",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1140,
        220
      ],
      "parameters": {
        "prompt": "=Subject: {{ $json.subject }}\nMessage:\n{{ $json.textAsHtml }} ",
        "messages": {
          "messageValues": [
            {
              "message": "Your task is to :\n- identify the language of the message and set the value to field \"message_language\" : \"English\", \"Japanese\" or \"Other\"\n- assess if the message requires a response and set the value to field \"needsReply\" : true if it does, false otherwise.\nReturn in JSON format.\nMarketing emails don't require a response."
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "7e8a17a4-fc57-4f8f-9755-3984547bfcce",
      "name": "Parser Result",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1300,
        420
      ],
      "parameters": {
        "jsonSchema": "={\n  \"type\": \"array\",\n  \"items\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"needsReply\": {\n        \"type\": \"boolean\"\n      },\n      \"message_language\": {\n        \"type\": \"string\"\n      }\n    },\n    \"required\": [\"needsReply\", \"message_language\"]\n  }\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "79600a11-8038-48d7-a7a5-5c0ffdb6d412",
      "name": "OpenAI GPT 4o - For English",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2100,
        580
      ],
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e0e0ef36-5a52-4d77-ba51-270693ce893f",
      "name": "OpenAI GPT-4o - for Japanese",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2060,
        300
      ],
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d9b8e365-5baa-47e6-bafb-8b138266a6f7",
  "connections": {
    "Gmail trigger": {
      "main": [
        [
          {
            "node": "Assess if a message needs a reply and identify the language",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4o": {
      "ai_languageModel": [
        [
          {
            "node": "Assess if a message needs a reply and identify the language",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Parser Result": {
      "ai_outputParser": [
        [
          {
            "node": "Assess if a message needs a reply and identify the language",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "If Needs Reply": {
      "main": [
        [
          {
            "node": "Switch based on email language",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT 4o - For English": {
      "ai_languageModel": [
        [
          {
            "node": "Generate email reply for an English client",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4o - for Japanese": {
      "ai_languageModel": [
        [
          {
            "node": "Generate email for a Japanese client",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Switch based on email language": {
      "main": [
        [
          {
            "node": "Generate email for a Japanese client",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate email reply for an English client",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate email for a Japanese client": {
      "main": [
        [
          {
            "node": "Gmail - Create Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate email reply for an English client": {
      "main": [
        [
          {
            "node": "Gmail - Create Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Assess if a message needs a reply and identify the language": {
      "main": [
        [
          {
            "node": "If Needs Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}