{
  "id": "Kpusm0QnNZ0kYww1",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "instagram chatbot for n8n creator",
  "tags": [
    {
      "id": "D6tQppX8lqvIgBeF",
      "name": "Murat",
      "createdAt": "2025-12-11T14:45:20.081Z",
      "updatedAt": "2025-12-11T14:45:20.081Z"
    }
  ],
  "nodes": [
    {
      "id": "fd3f6017-2837-438f-ba19-543a2ff8cc93",
      "name": "Instagram Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -400,
        176
      ],
      "parameters": {
        "path": "instagram-message",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "4de714d5-a2c9-41e5-9778-20801762baf6",
      "name": "Extract Sender & Text",
      "type": "n8n-nodes-base.set",
      "position": [
        -208,
        176
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "29e8d63e-88c6-47d5-a0fd-de0e01b15924",
      "name": "Is Voice Message?",
      "type": "n8n-nodes-base.if",
      "position": [
        272,
        176
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "conditions": [
            {
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.body.entry[0].messaging[0].message.attachments[0].type }}",
              "rightValue": "audio"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "b5451385-0b0e-4b3a-86ac-5056da71ea23",
      "name": "Download Voice Audio",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        496,
        96
      ],
      "parameters": {
        "url": "={{ $json.body.entry[0].messaging[0].message.attachments[0].payload.url }}",
        "options": {}
      },
      "typeVersion": 4
    },
    {
      "id": "b6270f32-48f9-4834-ac39-12e744f3b2ec",
      "name": "Transcribe Voice Message",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        720,
        96
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe"
      },
      "typeVersion": 1
    },
    {
      "id": "cfab60c5-c521-4fc7-a6c6-f198bcae6b25",
      "name": "Normalize User Message",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        160
      ],
      "parameters": {
        "jsCode": "return $input.all().map(item => {\n  let userMessage = item.json.text || item.json.message || \"\";\n  return { json: { userMessage: userMessage.trim() } };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "2b9d7079-4ad4-4678-b08e-49482ea8942e",
      "name": "FAQs (Google Docs)",
      "type": "n8n-nodes-base.googleDocsTool",
      "position": [
        2272,
        528
      ],
      "parameters": {
        "operation": "get",
        "documentURL": "https://docs.google.com/document/d/YOUR_DOC_ID/edit"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "e57e2758-48fe-4bee-a8be-6101b8a62d6c",
      "name": "Get Current Date & Time",
      "type": "n8n-nodes-base.dateTimeTool",
      "position": [
        2096,
        528
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "a5efa131-7622-4b95-90a3-0ccd416ab466",
      "name": "Check Date Availability",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1936,
        512
      ],
      "parameters": {
        "options": {},
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "operation": "getAll"
      },
      "typeVersion": 1
    },
    {
      "id": "06cc1c22-a6a1-44a7-aa73-26a0c1e365e6",
      "name": "Create Calendar Reservation",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1808,
        512
      ],
      "parameters": {
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "additionalFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "72cf4246-56e0-4732-9f2d-15c43024b84b",
      "name": "Send Confirmation Email",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        1664,
        512
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "408a3ee5-d541-4d40-86bc-367c0d824ab8",
      "name": "Send Instagram Reply",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2288,
        160
      ],
      "parameters": {
        "url": "https://graph.instagram.com/v21.0/me/messages",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ { \"recipient\": { \"id\": $('Extract Sender & Text').item.json.sender }, \"message\": { \"text\": $json.output } } }}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4
    },
    {
      "id": "06a5feef-903d-499e-9fb8-939aa64b9284",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1536,
        528
      ],
      "parameters": {
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "6a045093-3458-4bb0-930c-c096b63bdc7d",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1424,
        496
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8e19082e-449c-4d23-88ed-64aadb3a5906",
      "name": "Check is_ecco",
      "type": "n8n-nodes-base.if",
      "position": [
        -16,
        176
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f396031f-2c81-4498-a866-565c18ea60fd",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('Webhook').item.json.body.entry[0].messaging[0].message.is_echo }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "2fd54844-2763-40a9-9bec-68d84bd2b676",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 352,
        "content": "## Preparing incoming messages\n**Extracts the incoming Instagram message and ensures it is the user\u2019s message, not an echo or system response** "
      },
      "typeVersion": 1
    },
    {
      "id": "f736f6d9-28c8-4373-8775-06f6f3c37072",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        192,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 752,
        "height": 352,
        "content": "## Handling Voice messages\n**Filters voice messages, downloads the audio, and transcribes it into text**"
      },
      "typeVersion": 1
    },
    {
      "id": "d3d338fb-2fd9-40a5-ba4d-2f8ac1b1ef9f",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        960,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 352,
        "content": "## Preparing final message\n**Normalizes the message so both text and voice inputs follow the same format before AI processing**"
      },
      "typeVersion": 1
    },
    {
      "id": "3d3acf67-30f2-4258-89c3-957e2ced75bd",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 1184,
        "height": 672,
        "content": "## Main message processing\n**Handles customer questions using the business FAQ, checks availability for appointments, creates calendar bookings, and sends confirmation emails**"
      },
      "typeVersion": 1
    },
    {
      "id": "bd1d57c0-390e-4652-8d91-38f36716dedb",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -912,
        -480
      ],
      "parameters": {
        "width": 288,
        "height": 1104,
        "content": "## How it works\n\nThis workflow creates an AI assistant for Instagram direct messages.\n\nIncoming messages are received through a webhook. Text and voice messages are handled in the same flow. Voice messages are downloaded and transcribed before processing.\n\nAn AI agent then decides how to respond:\n- General questions are answered using the connected Google Docs FAQ only.\n- Booking requests trigger a guided appointment flow that checks availability, creates a calendar event, and sends a confirmation email.\n\nIf information is not found in the FAQ document, the agent does not guess or generate answers.\n\n## Setup steps\n\n1. Connect your Instagram webhook and add your access token in the HTTP Request node.\n2. Connect your OpenAI credentials for chat replies and voice transcription.\n3. Replace the Google Docs URL with your own FAQ document.\n4. Connect Google Calendar for availability checks and booking creation.\n5. Connect Gmail for sending confirmation emails.\n6. Set your business timezone in n8n settings.\n\nAfter setup, test the workflow by sending a text or voice message to your Instagram account.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9da0479b-0841-4ea7-ae6c-cb5ea16b2bde",
      "name": "Instagram AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1680,
        160
      ],
      "parameters": {
        "text": "={{ $json.userMessage }}",
        "options": {
          "systemMessage": "Instagram Beauty Assistant system message (sanitized template)"
        },
        "promptType": "define"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ff9ba656-a068-4d5e-ab2f-2db68fdc69da",
  "connections": {
    "Check is_ecco": {
      "main": [
        [],
        [
          {
            "node": "Is Voice Message?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Instagram AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Is Voice Message?": {
      "main": [
        [
          {
            "node": "Download Voice Audio",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Normalize User Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Instagram AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "FAQs (Google Docs)": {
      "ai_tool": [
        [
          {
            "node": "Instagram AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Instagram AI Agent": {
      "main": [
        [
          {
            "node": "Send Instagram Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Voice Audio": {
      "main": [
        [
          {
            "node": "Transcribe Voice Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Sender & Text": {
      "main": [
        [
          {
            "node": "Check is_ecco",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize User Message": {
      "main": [
        [
          {
            "node": "Instagram AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Date Availability": {
      "ai_tool": [
        [
          {
            "node": "Instagram AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Current Date & Time": {
      "ai_tool": [
        [
          {
            "node": "Instagram AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Send Confirmation Email": {
      "ai_tool": [
        [
          {
            "node": "Instagram AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Voice Message": {
      "main": [
        [
          {
            "node": "Normalize User Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Instagram Webhook Trigger": {
      "main": [
        [
          {
            "node": "Extract Sender & Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Calendar Reservation": {
      "ai_tool": [
        [
          {
            "node": "Instagram AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}