{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "a5c3ebce-f05b-4985-96ef-b98b8db66a22",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -1440,
        5440
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "38e231b6-a4d3-4694-8527-7e6411ece665",
      "name": "Sticky Note21",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1952,
        5120
      ],
      "parameters": {
        "width": 400,
        "height": 928,
        "content": "\n\n## \u2699\ufe0f Setup Instructions\n\n### 1\ufe0f\u20e3 Set Up OpenAI Connection\n1. Go to [OpenAI Platform](https://platform.openai.com/api-keys)  \n2. Navigate to [OpenAI Billing](https://platform.openai.com/settings/organization/billing/overview)  \n3. Add funds to your billing account  \n4. Copy your API key into the **OpenAI credentials** in n8n  \n\n### 2\ufe0f\u20e3 Set Up Outlook Connection\n1. In n8n \u2192 **Credentials \u2192 New \u2192 Microsoft Outlook OAuth2 API**  \n2. Log in with your Outlook account & approve access  \n3. Attach this credential to the **Search Outlook** node in the workflow  \n4. (Optional) Change the `limit` parameter in the node if you want more/less than 5 results  \n\n---\n\n## \ud83d\udcec Contact Information\nNeed help customizing this workflow or building similar automations?  \n\n\ud83d\udce7 [robert@ynteractive.com](mailto:robert@ynteractive.com)  \n\ud83d\udd17 [Robert Breen](https://www.linkedin.com/in/robert-breen-29429625/)  \n\ud83c\udf10 [ynteractive.com](https://ynteractive.com)  \n"
      },
      "typeVersion": 1
    },
    {
      "id": "451b2735-ce3a-4e10-98ea-a46b872f93be",
      "name": "Sticky Note22",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1520,
        5120
      ],
      "parameters": {
        "color": 7,
        "width": 1936,
        "height": 928,
        "content": "# \ud83d\udce7 Outlook Email Search Assistant (n8n + OpenAI)\n\nThis workflow allows you to **search your Outlook mailbox with natural language**. You type what you\u2019re looking for (e.g., \u201cinvoice from last week\u201d), and the workflow:  \n1. Uses **OpenAI** to generate a search query.  \n2. Searches Outlook emails and ranks them by relevance.  \n3. Outputs results in a simple table with **score + link** to each email.  \n"
      },
      "typeVersion": 1
    },
    {
      "id": "5f29e431-f35e-43d1-a22c-b27f7630539b",
      "name": "OpenAI Chat Model5",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -368,
        5888
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "872318b9-07c0-4434-8258-8264c5ebcfff",
      "name": "Sticky Note23",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1456,
        5664
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 304,
        "content": "### 1\ufe0f\u20e3 Set Up OpenAI Connection\n1. Go to [OpenAI Platform](https://platform.openai.com/api-keys)  \n2. Navigate to [OpenAI Billing](https://platform.openai.com/settings/organization/billing/overview)  \n3. Add funds to your billing account  \n4. Copy your API key into the **OpenAI credentials** in n8n  "
      },
      "typeVersion": 1
    },
    {
      "id": "bc36ba09-b088-45c3-9ab6-4c19e8dd4aa4",
      "name": "OpenAI Chat Model6",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1344,
        5856
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b7e5a86b-9534-4a1c-8134-f0cdc92a40c5",
      "name": "Simple Memory1",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -1040,
        5696
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "b765f576-4cce-4264-8cd0-eb42bcfe0b3b",
      "name": "Structured Output Parser3",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -880,
        5728
      ],
      "parameters": {
        "jsonSchemaExample": "{\n\t\"search\": \"search term\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "9dd5c86f-8d6d-4b94-a7b7-08d81aac3749",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        -640,
        5648
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineAll"
      },
      "typeVersion": 3.2
    },
    {
      "id": "ac3539fb-842d-4922-9ca7-42397cfb7143",
      "name": "Structured Output Parser5",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -144,
        5904
      ],
      "parameters": {
        "jsonSchemaExample": "{\n\t\"score\": \"score\",\n\t\"url\": \"url\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "4bf1962a-009e-457d-95a9-243b64bd9a79",
      "name": "OpenAI Chat Model7",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        144,
        5664
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "68610127-4f8e-4c97-819f-7c47c0d4c93f",
      "name": "Generate Search Term",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1136,
        5408
      ],
      "parameters": {
        "options": {
          "systemMessage": "Take in a search that someone wants to search their outlook for a specific mail. Once they tell you what they wnat, output a search term. \n\nOutput like this. \n\n{\n\t\"search\": \"search term\"\n}"
        },
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "6045e6b4-1f1a-4a94-bdc5-b4cca9dbb167",
      "name": "Search Outlook",
      "type": "n8n-nodes-base.microsoftOutlook",
      "position": [
        -384,
        5456
      ],
      "parameters": {
        "limit": 5,
        "output": "raw",
        "options": {},
        "filtersUI": {
          "values": {
            "search": "={{ $json.output.search }} -from:rbreen@ynteractive.com\n",
            "filterBy": "search"
          }
        },
        "operation": "getAll"
      },
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "90182205-aef1-465d-a271-16c63b9a4942",
      "name": "Score if email is relevent to search",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -304,
        5664
      ],
      "parameters": {
        "text": "=User question: {{ $json.chatInput }} Email content: {{ $json.body.content }}  sender: {{ $json.sender.emailAddress.address }}  url: {{ $json.webLink }}",
        "options": {
          "systemMessage": "take in the user question and give a number 1-100 on how likely this is the email they are looking for. output like this: "
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "7b73107e-a3e7-4c4d-95c3-7f53c858c5e0",
      "name": "Output as table for user",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        96,
        5408
      ],
      "parameters": {
        "text": "={{ $json.data }}",
        "options": {
          "systemMessage": "write this data into a table output with two columns. score, then url. "
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "eb49ccbb-5951-4774-b42d-22822317fc3f",
      "name": "Convert to one Output",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -64,
        5408
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "010f5610-caad-493f-afc6-55a9f0aaf7c2",
      "name": "Sticky Note24",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        5232
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 336,
        "content": "### 2\ufe0f\u20e3 Set Up Outlook Connection\n1. In n8n \u2192 **Credentials \u2192 New \u2192 Microsoft Outlook OAuth2 API**  \n2. Log in with your Outlook account & approve access  \n3. Attach this credential to the **Search Outlook** node in the workflow  \n4. (Optional) Change the `limit` parameter in the node if you want more/less than 5 results "
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Score if email is relevent to search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Outlook": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory1": {
      "ai_memory": [
        [
          {
            "node": "Generate Search Term",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model5": {
      "ai_languageModel": [
        [
          {
            "node": "Score if email is relevent to search",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model6": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Search Term",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model7": {
      "ai_languageModel": [
        [
          {
            "node": "Output as table for user",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Generate Search Term": {
      "main": [
        [
          {
            "node": "Search Outlook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to one Output": {
      "main": [
        [
          {
            "node": "Output as table for user",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser3": {
      "ai_outputParser": [
        [
          {
            "node": "Generate Search Term",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser5": {
      "ai_outputParser": [
        [
          {
            "node": "Score if email is relevent to search",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Generate Search Term",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Score if email is relevent to search": {
      "main": [
        [
          {
            "node": "Convert to one Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}