{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "7436eb20-9360-4219-8c2b-8b56eb3843ec",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        -80,
        160
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9601c9d7-41c0-44da-8a9c-97956711bd07",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -80,
        -20
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "You are a helpful, friendly, assistant. \n\nYou always respond only nicely formatted markdown where appropriate."
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "23df5bee-5095-4c8d-9f78-c62119734332",
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -60,
        440
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "0442b3d9-2149-49b6-9cc8-af92d1ed036c",
      "name": "On Message Received",
      "type": "n8n-nodes-base.slackTrigger",
      "position": [
        -860,
        80
      ],
      "parameters": {
        "options": {
          "resolveIds": false
        },
        "trigger": [
          "message"
        ],
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_APPS_CHANNEL_ID"
        }
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d9efc43e-b1c1-48c0-8c68-42304c752645",
      "name": "Check If User",
      "type": "n8n-nodes-base.if",
      "position": [
        -480,
        80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ab6c4d27-4daf-4c6f-9ad5-866f6cb62758",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.bot_id }}",
              "rightValue": ""
            },
            {
              "id": "211e32ac-a544-46f4-8ce9-9a41674c4184",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.text }}",
              "rightValue": ""
            },
            {
              "id": "6160af99-6beb-4858-95e6-16e808c22581",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.type }}",
              "rightValue": "message"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "99ccfdff-4fd1-4cff-99e0-7a2620735ff8",
      "name": "Set Thinking Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        0,
        -400
      ],
      "parameters": {
        "url": "https://slack.com/api/assistant.threads.setStatus",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "channel_id",
              "value": "={{ $json.channel }}"
            },
            {
              "name": "status",
              "value": "is thinking..."
            },
            {
              "name": "thread_ts",
              "value": "={{ $json.thread_ts }}"
            }
          ]
        },
        "genericAuthType": "httpBearerAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f1bbe14d-9274-4e7a-804a-dd65b6efca24",
      "name": "Send Reply",
      "type": "n8n-nodes-base.slack",
      "position": [
        560,
        60
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "select": "channel",
        "blocksUi": "={\n \"blocks\": [\n   { \n    \"type\": \"markdown\", \n    \"text\": {{ JSON.stringify($json.output) }}\n    }\n ]\n}\n\n",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('On Message Received').item.json.channel }}"
        },
        "messageType": "block",
        "otherOptions": {
          "mrkdwn": true,
          "thread_ts": {
            "replyValues": {
              "thread_ts": "={{ $('On Message Received').item.json.ts }}"
            }
          },
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "484b674d-be92-49a9-9a0d-a4f9747dc5bb",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -940,
        -40
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 280,
        "content": "## Listen for a DM\n\n**IMPORTANT**: Enter your Slack app's ID in the \"Channel to Watch\" field."
      },
      "typeVersion": 1
    },
    {
      "id": "fdd9665d-b7c1-4a1d-b84d-6113ffb88a55",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        -40
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 280,
        "content": "## Filter out noise\n\nWe only care about user messages."
      },
      "typeVersion": 1
    },
    {
      "id": "c7cc385d-189f-4fb0-9901-8acbd4696e0c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        -560
      ],
      "parameters": {
        "color": 7,
        "width": 360,
        "height": 360,
        "content": "## Activate loading UI\n\nThis HTTP POST request will trigger the \"three dots\" thinking UI in the message thread. Slack automatically removes this UI when our app responds."
      },
      "typeVersion": 1
    },
    {
      "id": "07c2ebc0-bc20-4584-bf87-31788aa1646d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -140
      ],
      "parameters": {
        "color": 7,
        "width": 440,
        "height": 460,
        "content": "## Customize your agent here\n\nThe agent is the brains of your chatbot. Customize the prompts and tooling however you need."
      },
      "typeVersion": 1
    },
    {
      "id": "242fa108-e421-4428-814d-b4ebf967f12d",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        60,
        160
      ],
      "parameters": {
        "tableName": "chat_histories",
        "sessionKey": "={{ $('On Message Received').item.json.thread_ts }}",
        "sessionIdType": "customKey"
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If User": {
      "main": [
        [
          {
            "node": "Set Thinking Status",
            "type": "main",
            "index": 0
          },
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On Message Received": {
      "main": [
        [
          {
            "node": "Check If User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}