{
  "meta": {
    "instanceId": "e24f19d897fbcfb06d96c9173e7c8dc910053690edc62df56555ef40299436c1"
  },
  "nodes": [
    {
      "id": "6f8e86fd-652b-4237-ac27-5b137fe504de",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -608,
        256
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "credential-id",
          "name": "openAiApi Credential"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "50c59889-41c7-49bf-a84c-b4249e9dfa07",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -464,
        256
      ],
      "parameters": {
        "sessionKey": "={{ $('Webhook').item.json.body.object.message.from_id }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 20
      },
      "typeVersion": 1.3
    },
    {
      "id": "e36e0c70-6201-4c28-9558-143e90d1b497",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -2016,
        64
      ],
      "webhookId": "2e543095-cf07-4b5e-9ea5-20a5e8d868c6",
      "parameters": {
        "path": "testvkwildbots",
        "options": {
          "responseData": "Here_is_yours_code"
        },
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "52054156-b1e3-4841-b27b-2d502dab2cd1",
      "name": "Transcribe",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -1136,
        176
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe"
      },
      "credentials": {
        "openAiApi": {
          "id": "credential-id",
          "name": "openAiApi Credential"
        }
      },
      "typeVersion": 1.6
    },
    {
      "id": "9601a615-ef8b-4acd-b75b-c97c13e44c95",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueErrorOutput",
      "position": [
        -608,
        48
      ],
      "parameters": {
        "text": "={{ $json.prompt }}",
        "options": {
          "systemMessage": "=You are a helpful assistant that responds to user messages in the VK community \"Wildbots Test Ground for Youtube\". Your name is Betsy. You love to chat and are very friendly.\n\n## Latest reminders\n- Current date and time: {{$now}}",
          "passthroughBinaryImages": false
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "a5120bfd-6f89-4c93-8942-ca386c68fb4d",
      "name": "Send to VK",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -144,
        32
      ],
      "parameters": {
        "url": "https://api.vk.com/method/messages.send?v=5.199&p1=v1",
        "method": "POST",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "user_id",
              "value": "={{ $('Webhook').item.json.body.object.message.peer_id }}"
            },
            {
              "name": "random_id",
              "value": "={{ $('Webhook').item.json.body.object.message.random_id }}"
            },
            {
              "name": "message",
              "value": "={{ $json.output }}"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "id": "credential-id",
          "name": "httpBearerAuth Credential"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ed3357a9-36e9-49e7-8076-4885e708e7b4",
      "name": "Get URL",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1328,
        176
      ],
      "parameters": {
        "url": "={{ $('Webhook').item.json.body.object.message.attachments[0].audio_message.link_mp3 }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "29cbe0fa-9d1b-48ce-9502-f59c5ec43f5f",
      "name": "bring it to the form",
      "type": "n8n-nodes-base.set",
      "position": [
        -848,
        48
      ],
      "parameters": {
        "options": {
          "dotNotation": false
        },
        "assignments": {
          "assignments": [
            {
              "id": "09bbe290-fba2-46b3-8c76-1116ab6a456d",
              "name": "prompt",
              "type": "string",
              "value": "={{ $json.text != null ? $json.text : $('Webhook').item.json.body?.object?.message?.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ef6ecc40-826e-4519-811e-578e4227eb6d",
      "name": "Filter Dubles",
      "type": "n8n-nodes-base.filter",
      "position": [
        -1792,
        64
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c04ae197-8e7d-4019-b175-25238bda50f0",
              "operator": {
                "type": "number",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.headers['x-retry-counter'] }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "c443d16d-b10f-4b3b-aca1-15d6fc86adb6",
      "name": "Voice/Text",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1568,
        64
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "8c844924-b2ed-48b0-935c-c66a8fd0c778",
                    "operator": {
                      "type": "string",
                      "operation": "notEmpty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $('Webhook').item.json.body.object.message.text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Voice",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "63e2c3b6-110d-4af6-8061-31677041a4c4",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $('Webhook').item.json.body.object.message.attachments[0].audio_message.link_mp3 }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "ignoreCase": true,
          "allMatchingOutputs": false
        },
        "looseTypeValidation": true
      },
      "typeVersion": 3.2
    },
    {
      "id": "36df7d43-4da6-4533-a2bd-411a7efaf19b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2576,
        -176
      ],
      "parameters": {
        "width": 512,
        "height": 592,
        "content": "## VK AI Chatbot with Voice Support\n\nBuild a smart chatbot for your VK community that understands both text and voice messages, powered by OpenAI's GPT-4.\n\n### How it works\n\nWhen someone messages your VK community, this workflow receives it and checks if it's text or voice. Voice messages get converted to text automatically. Then the AI generates a friendly response, remembering your previous conversations. The reply is sent back to VK instantly.\n\n### Setup steps\n\n1. **Connect your accounts:** Click on \"OpenAI Chat Model\" and \"Transcribe\" nodes - add your OpenAI API key. Then click \"Send to VK\" and \"Error\" nodes - add your VK community access token.\n2. **Link VK to n8n:** Copy the webhook URL from the Webhook node. In VK, go to your Community Settings → Manage → API Usage → Callback API → Add server. Paste the URL. VK will ask you to confirm - change the Webhook node's Response Data to the confirmation code VK gives you, then switch it back to `ok` after confirming.\n3. **Make it yours:** Open the \"AI Agent\" node and change the bot's name and personality in the system message.\n4. **Try it out:** Send a message to your VK community - the bot should reply!"
      },
      "typeVersion": 1
    },
    {
      "id": "ececf4c2-7817-4fbd-932b-5d781210342f",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1840,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 448,
        "content": "## Receive & Filter\nGets messages from VK and removes duplicates."
      },
      "typeVersion": 1
    },
    {
      "id": "ed749754-8fa0-4182-989e-bec3d3299b14",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1392,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 448,
        "content": "## Voice to Text\nConverts voice messages into text you can read."
      },
      "typeVersion": 1
    },
    {
      "id": "596a6e49-5689-448e-80d0-89a87ba2c10e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -720,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 480,
        "content": "## Smart Replies\nAI creates responses and remembers your chat history. Customize the personality here!"
      },
      "typeVersion": 1
    },
    {
      "id": "79706b92-c6a5-4f47-bdf2-dbba311c65cb",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 352,
        "height": 480,
        "content": "## Send Back\nDelivers the AI's answer to your VK community."
      },
      "typeVersion": 1
    },
    {
      "id": "cd35c747-fa83-4924-9552-464a44ee36ad",
      "name": "Error VK",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -128,
        192
      ],
      "parameters": {
        "url": "https://api.vk.com/method/messages.send?v=5.199&p1=v1",
        "method": "POST",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "user_id",
              "value": "={{ $('Webhook').item.json.body.object.message.peer_id }}"
            },
            {
              "name": "random_id",
              "value": "={{ $('Webhook').item.json.body.object.message.random_id }}"
            },
            {
              "name": "message",
              "value": "=An error has occurred. Try to repeat your request again."
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "id": "credential-id",
          "name": "httpBearerAuth Credential"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "2c9c9877-9e08-4154-95ef-b2e396b48209",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        -288
      ],
      "parameters": {
        "color": 5,
        "width": 352,
        "height": 208,
        "content": "@[youtube](Gg652GlP5lI)"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Get URL": {
      "main": [
        [
          {
            "node": "Transcribe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Filter Dubles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send to VK",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error VK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe": {
      "main": [
        [
          {
            "node": "bring it to the form",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Voice/Text": {
      "main": [
        [
          {
            "node": "bring it to the form",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Dubles": {
      "main": [
        [
          {
            "node": "Voice/Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "bring it to the form": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}