AutomationFlowsEmail & Gmail › Org-ai Dept General

Org-ai Dept General

org-ai Dept General. Uses httpRequest, gmail. Webhook trigger; 9 nodes.

Webhook trigger★★★★☆ complexity9 nodesHTTP RequestGmail
Email & Gmail Trigger: Webhook Nodes: 9 Complexity: ★★★★☆ Added:

This workflow follows the Gmail → HTTP Request 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 →

Download .json
{
  "name": "org-ai Dept General",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "dept-general",
        "responseMode": "onReceived",
        "authentication": "headerAuth",
        "options": {}
      },
      "id": "trigger",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.body.logUrl }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "x-webhook-token",
              "value": "={{ $env.N8N_WEBHOOK_AUTH_TOKEN || 'org-ai-n8n-secret-token' }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "taskId",
              "value": "={{ $json.body.taskId }}"
            },
            {
              "name": "message",
              "value": "\u6c4e\u7528 (General) \u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u958b\u59cb"
            },
            {
              "name": "level",
              "value": "INFO"
            }
          ]
        },
        "options": {}
      },
      "id": "log-start",
      "name": "Log Start",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const rd = $('Webhook').item.json.body;\nconst input = (rd.input ?? '').toLowerCase();\nconst hint = (rd.taskType ?? '').toLowerCase();\nconst kw = (words) => words.some(w => input.includes(w.toLowerCase()) || hint.includes(w.toLowerCase()));\n\nlet taskMode = 'general';\nif (kw(['\u30e1\u30fc\u30eb','email','mail','\u9001\u4fe1','\u9001\u3063\u3066'])) taskMode = 'email';\n\nconst prompts = {\n  email: `\u3042\u306a\u305f\u306f\u79d8\u66f8AI\u3067\u3059\u3002\u6c4e\u7528\u30d3\u30b8\u30cd\u30b9\u30e1\u30fc\u30eb\u3092\u4e01\u5be7\u306b\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002\\nJSON: {\"taskType\":\"email\",\"to\":\"\",\"cc\":\"\",\"subject\":\"\",\"body\":\"\"}`,\n  general: `\u3042\u306a\u305f\u306f\u512a\u79c0\u306a\u30d3\u30b8\u30cd\u30b9\u30a2\u30b7\u30b9\u30bf\u30f3\u30c8\u3067\u3059\u3002\u30e6\u30fc\u30b6\u30fc\u306e\u8cea\u554f\u306b\u5b9f\u7528\u7684\u306b\u56de\u7b54\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u30d7\u30ec\u30fc\u30f3\u30c6\u30ad\u30b9\u30c8\u3067\u8fd4\u3057\u3066\u304f\u3060\u3055\u3044\u3002`\n};\nconst systemPrompt = prompts[taskMode] ?? prompts.general;\nconst useJsonMode = taskMode === 'email';\nconst messages = [\n  { role: 'system', content: systemPrompt },\n  { role: 'user', content: rd.input }\n];\nreturn [{ json: { messages, taskMode, useJsonMode, department: 'GENERAL', org_id: rd.orgId, plan: rd.plan ?? 'STARTER', aiEngineUrl: rd.aiEngineUrl ?? 'http://ai-engine:8000' } }];"
      },
      "id": "build-prompt",
      "name": "Build Prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $json.aiEngineUrl }}/llm/chat",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "={{ JSON.stringify({ messages: $json.messages, department: $json.department, org_id: $json.org_id, plan: $json.plan, json_mode: $json.useJsonMode }) }}",
        "options": {}
      },
      "id": "ai-chat",
      "name": "AI Engine Chat",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": false,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('Build Prompt').item.json.taskMode }}",
                    "rightValue": "email",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "email"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "id": "switch-mode",
      "name": "Switch Email vs Other",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        1120,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const raw = $json.content ?? '';\nlet parsed = {};\ntry { parsed = JSON.parse(raw); } catch { parsed = { to: '', subject: '(AI \u51fa\u529b\u3092JSON\u30d1\u30fc\u30b9\u5931\u6557)', body: raw }; }\nreturn [{ json: { ...parsed, _ai: $json } }];"
      },
      "id": "parse-email",
      "name": "Parse Email JSON",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1340,
        200
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.to }}",
        "subject": "={{ $json.subject }}",
        "emailType": "text",
        "message": "={{ $json.body }}",
        "options": {
          "ccList": "={{ $json.cc || '' }}",
          "appendAttribution": false
        }
      },
      "id": "send-email",
      "name": "Send Email (Gmail)",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1560,
        200
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Webhook').item.json.body.callbackUrl }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "x-webhook-token",
              "value": "={{ $env.N8N_WEBHOOK_AUTH_TOKEN || 'org-ai-n8n-secret-token' }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "taskId",
              "value": "={{ $('Webhook').item.json.body.taskId }}"
            },
            {
              "name": "status",
              "value": "DONE"
            },
            {
              "name": "output",
              "value": "={{ JSON.stringify({ taskType: 'email', sentTo: $('Parse Email JSON').item.json.to, subject: $('Parse Email JSON').item.json.subject }) }}"
            },
            {
              "name": "workflowId",
              "value": "={{ $workflow.id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "callback-email",
      "name": "Callback (Email Done)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1780,
        200
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Webhook').item.json.body.callbackUrl }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "x-webhook-token",
              "value": "={{ $env.N8N_WEBHOOK_AUTH_TOKEN || 'org-ai-n8n-secret-token' }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "taskId",
              "value": "={{ $('Webhook').item.json.body.taskId }}"
            },
            {
              "name": "status",
              "value": "DONE"
            },
            {
              "name": "output",
              "value": "={{ $('AI Engine Chat').item.json.content }}"
            },
            {
              "name": "workflowId",
              "value": "={{ $workflow.id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "callback-other",
      "name": "Callback (Other Done)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1340,
        400
      ]
    }
  ],
  "connections": {
    "Log Start": {
      "main": [
        [
          {
            "node": "Build Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Prompt": {
      "main": [
        [
          {
            "node": "AI Engine Chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Engine Chat": {
      "main": [
        [
          {
            "node": "Switch Email vs Other",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch Email vs Other": {
      "main": [
        [
          {
            "node": "Parse Email JSON",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Callback (Other Done)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Email JSON": {
      "main": [
        [
          {
            "node": "Send Email (Gmail)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email (Gmail)": {
      "main": [
        [
          {
            "node": "Callback (Email Done)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Log Start",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true
  },
  "staticData": null
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

org-ai Dept General. Uses httpRequest, gmail. Webhook trigger; 9 nodes.

Source: https://github.com/hamahiro1668/org-ai-platform/blob/f36c4297a8e19382d8bbceeac39baf13028094d2/apps/n8n-workflows/dept-general.json — original creator credit. Request a take-down →

More Email & Gmail workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Email & Gmail

Automate WhatsApp communication for recruitment agencies with an interactive, structured customer experience. This workflow handles pricing inquiries, request submissions, tracking, complaints, and hu

HTTP Request, Google Sheets, Gmail +1
Email & Gmail

This template turns Podium's conversation inbox into a full sales CRM with a custom funnel, AI message classification, automated drip follow-ups, daily admin reports, and a live Kanban dashboard. Six

HTTP Request, Google Sheets, Gmail
Email & Gmail

Suspicious_login_detection. Uses postgres, httpRequest, noOp, html. Webhook trigger; 43 nodes.

Postgres, HTTP Request, Gmail +1
Email & Gmail

This n8n workflow is designed for security monitoring and incident response when suspicious login events are detected. It can be initiated either manually from within the n8n UI for testing or automat

Postgres, HTTP Request, Gmail +1
Email & Gmail

This workflow automates a document approval process using Supabase and Gmail. Teams that need structured multi-level document approvals. Companies managing policies, contracts, or proposals. Medical d

Supabase, Crypto, Gmail +3