AutomationFlowsData & Sheets › Chat History Lookup

Chat History Lookup

Chat History Lookup. Uses executeWorkflowTrigger, mongoDb. Event-driven trigger; 4 nodes.

Event trigger★★★★☆ complexity4 nodesExecute Workflow TriggerMongoDB
Data & Sheets Trigger: Event Nodes: 4 Complexity: ★★★★☆ Added:

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": "Chat History Lookup",
  "nodes": [
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "sessionID"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        0
      ],
      "id": "995980f3-1644-4da4-993c-cd44b7fd60ec",
      "name": "Chat History Lookup"
    },
    {
      "parameters": {
        "operation": "aggregate",
        "collection": "sessions",
        "query": "=[\n  {\n    \"$match\": {\n      \"sessionID\": \"{{$json.sessionID}}\"\n    }\n  },\n  {\n    \"$lookup\": {\n      \"from\": \"messages\",\n      \"localField\": \"sessionID\",\n      \"foreignField\": \"sessionId\",\n      \"as\": \"messages\"\n    }\n  }\n]"
      },
      "type": "n8n-nodes-base.mongoDb",
      "typeVersion": 1.1,
      "position": [
        220,
        0
      ],
      "id": "3c1dd21e-74a4-436f-a923-080b569eaa04",
      "name": "MongoDB",
      "credentials": {
        "mongoDb": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Get the session with messages\nconst session = $input.first().json;\nconst messages = session.messages || [];\n\n// Extract some basic stats that might be useful\nconst userEmail = messages.reduce((email, msg) => {\n  if (email) return email; // Already found\n  if (msg.role !== 'user') return email;\n  \n  const matches = msg.content.match(/\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b/g);\n  return matches ? matches[0] : email;\n}, '');\n\nreturn {\n  sessionID: session.sessionID,\n  messages: messages,\n  messageCount: messages.length,\n  firstMessageTime: messages.length > 0 ? messages[0].createdAt : null,\n  lastMessageTime: messages.length > 0 ? messages[messages.length - 1].createdAt : null,\n  extractedUserEmail: userEmail\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ],
      "id": "383c86dc-2927-4879-934d-c49751f2774b",
      "name": "Code"
    },
    {
      "parameters": {
        "content": "## Ability for the AI Chatbot to lookup chats",
        "height": 460,
        "width": 900
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -180,
        -300
      ],
      "id": "201086af-00e2-4e43-b826-14324bff4d63",
      "name": "Sticky Note"
    }
  ],
  "connections": {
    "Chat History Lookup": {
      "main": [
        [
          {
            "node": "MongoDB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e1c29c76-a045-4806-8e69-2be596393dce",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "EV5EqlN4pOhKjubg",
  "tags": []
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

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

About this workflow

Chat History Lookup. Uses executeWorkflowTrigger, mongoDb. Event-driven trigger; 4 nodes.

Source: https://github.com/Eventyret/support-bot/blob/8380366fd086919c67a01fce642062e388bef2e8/N8N/Chat_History_Lookup.json — original creator credit. Request a take-down →

More Data & Sheets workflows → · Browse all categories →

Related workflows

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

Data & Sheets

This n8n template provides a production-ready, memory-safe pipeline for ingesting large Hugging Face datasets into MongoDB using batch pagination. It is designed as a reusable data ingestion layer for

Execute Workflow Trigger, HTTP Request, MongoDB
Data & Sheets

Reagendamiento_v2. Uses executeWorkflowTrigger, redis, httpRequest, n8n-nodes-evolution-api. Event-driven trigger; 89 nodes.

Execute Workflow Trigger, Redis, HTTP Request +3
Data & Sheets

Agendamiento_v2. Uses n8n-nodes-evolution-api, redis, httpRequest, executeWorkflowTrigger. Event-driven trigger; 59 nodes.

N8N Nodes Evolution Api, Redis, HTTP Request +3
Data & Sheets

Cancelacion_v2. Uses executeWorkflowTrigger, redis, httpRequest, n8n-nodes-evolution-api. Event-driven trigger; 46 nodes.

Execute Workflow Trigger, Redis, HTTP Request +3
Data & Sheets

This enables webhooks for nearly realtime updates (every 5 seconds) from Notion Databases.

Notion, Supabase, Execute Workflow Trigger +1