{
  "name": "WhatsApp AI Agent Supabase Audio (6)",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "messages"
        ]
      },
      "id": "77ee6494-4898-47dc-81d9-35daf6f0beea",
      "name": "WhatsApp Trigger",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        2360,
        500
      ],
      "webhookId": "aaa71f03-f7af-4d18-8d9a-0afb86f1b554",
      "typeVersion": 1,
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "MwUC6bDV20nydurN",
          "name": "WhatsApp OAuth account"
        }
      }
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "id": "57210e27-1f89-465a-98cc-43f890a4bf58",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        4480,
        640
      ],
      "typeVersion": 1,
      "credentials": {
        "openAiApi": {
          "id": "UZmx7xgMogsQiPuG",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "ee78320b-d407-49e8-b4b8-417582a44709",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        5040,
        740
      ],
      "typeVersion": 1,
      "credentials": {
        "openAiApi": {
          "id": "UZmx7xgMogsQiPuG",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "466179296585433",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}",
        "textBody": "={{ $json.output }}",
        "additionalFields": {
          "previewUrl": false
        },
        "requestOptions": {}
      },
      "id": "1ae5a311-36d7-4454-ab14-6788d1331780",
      "name": "Reply To User",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        5140,
        460
      ],
      "typeVersion": 1,
      "credentials": {
        "whatsAppApi": {
          "id": "RS7BQokKJtMQJ7xj",
          "name": "WhatsApp account"
        }
      }
    },
    {
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.audio.id }}",
        "requestOptions": {}
      },
      "id": "d0c61337-ae5e-46bf-9809-0cdd5f3e6e49",
      "name": "Get Audio URL",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        3200,
        400
      ],
      "typeVersion": 1,
      "credentials": {
        "whatsAppApi": {
          "id": "3rsrJoB5EOYCOd3q",
          "name": "WhatsApp account 2"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi",
        "options": {}
      },
      "id": "12d324b7-918f-4cb3-a08e-5ac73923dc82",
      "name": "Download Audio",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3360,
        400
      ],
      "typeVersion": 4.2,
      "credentials": {
        "whatsAppApi": {
          "id": "3rsrJoB5EOYCOd3q",
          "name": "WhatsApp account 2"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-002:generateContent",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googlePalmApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{\n{\n  \"contents\": [{\n    \"parts\":[\n      {\"text\": \"Transcribe this audio\"},\n      {\"inlineData\": {\n        \"mimeType\": `audio/${$binary.data.fileExtension}`,\n        \"data\": $input.item.binary.data.data }\n      }\n    ]\n  }]\n}\n}}",
        "options": {}
      },
      "id": "c19de4f0-49da-4df3-8b98-b1592e9a7cfd",
      "name": "Google Gemini Audio",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3720,
        280
      ],
      "typeVersion": 4.2,
      "credentials": {
        "googlePalmApi": {
          "id": "WvGYR9mnDUUJ3eJu",
          "name": "Google Gemini(PaLM) Api account 2"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2ec0e573-373b-4692-bfae-86b6d3b9aa9a",
              "name": "text",
              "type": "string",
              "value": "={{ $json.candidates[0].content.parts[0].text }}"
            }
          ]
        },
        "options": {}
      },
      "id": "fcf33ea1-84ef-44e5-b851-9c46ac5e31cd",
      "name": "Format Response1",
      "type": "n8n-nodes-base.set",
      "position": [
        4000,
        280
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "fieldToSplitOut": "messages",
        "options": {}
      },
      "id": "7fe349f2-a976-423d-bd1b-e7ca1054257e",
      "name": "Split Out Message Parts",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        2580,
        500
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "d990cbd6-a408-4ec4-a889-41be698918d9",
              "name": "message_type",
              "type": "string",
              "value": "={{ $('Split Out Message Parts').item.json.type }}"
            },
            {
              "id": "23b785c3-f38e-4706-80b7-51f333bba3bd",
              "name": "message_text",
              "type": "string",
              "value": "={{ $json.text }}"
            },
            {
              "id": "6e83f9a7-cf75-4182-b2d2-3151e8af76b9",
              "name": "from",
              "type": "string",
              "value": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}"
            },
            {
              "id": "da4b602a-28ca-4b0d-a747-c3d3698c3731",
              "name": "message_caption",
              "type": "string",
              "value": "={{ $('Redirect Message Types').item.json.video && $('Redirect Message Types').item.json.video.caption || '' }}\n{{ $('Redirect Message Types').item.json.image && $('Redirect Message Types').item.json.image.caption || ''}}\n{{ $('Redirect Message Types').item.json.audio && $('Redirect Message Types').item.json.audio.caption || ''}}"
            },
            {
              "id": "43c6efe2-1691-4f90-a27c-3be8518fe1ff",
              "name": "sessionId",
              "value": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "8a1afe6c-acc2-4397-a11f-9f94d008656a",
      "name": "Get User's Message",
      "type": "n8n-nodes-base.set",
      "position": [
        4240,
        440
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "amount": 0
      },
      "id": "fef3891c-d5d3-483b-9cc8-0337c1e82476",
      "name": "Get Text",
      "type": "n8n-nodes-base.wait",
      "position": [
        3280,
        680
      ],
      "webhookId": "99b49c83-d956-46d2-b8d3-d65622121ad9",
      "typeVersion": 1.1
    },
    {
      "parameters": {
        "name": "Adaptify_AI_Knowlege_Base",
        "description": "Call this tool to query the Adaptify AI knowledge base. "
      },
      "id": "3dcf9b03-fa01-458c-8f35-cd2f5d40d90b",
      "name": "Vector Store Tool",
      "type": "@n8n/n8n-nodes-langchain.toolVectorStore",
      "position": [
        4820,
        580
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "chunkOverlap": 200,
        "options": {}
      },
      "id": "0ff4e07a-65c4-4ea5-b299-0b5f7f85387a",
      "name": "Recursive Character Text Splitter2",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "typeVersion": 1,
      "position": [
        3540,
        1240
      ]
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "1N91XEgHgA253HJ1Nb-Q6bSWHbLVZKWfL3ff7bRQxTdg",
          "mode": "list",
          "cachedResultName": "Adaptify AI Knowledge Base",
          "cachedResultUrl": "https://docs.google.com/document/d/1N91XEgHgA253HJ1Nb-Q6bSWHbLVZKWfL3ff7bRQxTdg/edit?usp=drivesdk"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "application/pdf"
            }
          }
        }
      },
      "id": "e2e1e8e8-42b8-44ab-b50f-b734b624fe14",
      "name": "Google Drive2",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        3060,
        900
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "REPmELdYz9UjkwcW",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "dataType": "binary",
        "options": {}
      },
      "id": "45383245-c333-4c64-bbb0-a97628a76311",
      "name": "Default Data Loader2",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1,
      "position": [
        3620,
        1080
      ]
    },
    {
      "parameters": {},
      "id": "88f0a5c8-7a22-40ce-a40d-c35af100a13d",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "typeVersion": 1.1,
      "position": [
        4660,
        580
      ],
      "credentials": {
        "postgres": {
          "id": "DBJgKvKCAzIYYWkn",
          "name": "Postgres account 7"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "1312a137-7acf-41b5-ad9d-60c7b1473e47",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.1,
      "position": [
        4720,
        940
      ],
      "credentials": {
        "openAiApi": {
          "id": "UZmx7xgMogsQiPuG",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {},
      "id": "898074be-3e60-4919-bf83-c84698d57479",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        2900,
        900
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "975abfbb-ee71-4bd4-a8d5-5f05267fbcea",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.1,
      "position": [
        3440,
        1100
      ],
      "credentials": {
        "openAiApi": {
          "id": "UZmx7xgMogsQiPuG",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.type == 'audio' && Boolean($json.audio) }}",
                    "rightValue": "audio"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Audio Message"
            }
          ]
        },
        "looseTypeValidation": true,
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Text Message"
        }
      },
      "id": "470bf6d3-ccdb-490f-a961-e9a3b270dd37",
      "name": "Redirect Message Types",
      "type": "n8n-nodes-base.switch",
      "position": [
        2800,
        500
      ],
      "typeVersion": 3.2
    },
    {
      "parameters": {
        "mode": "insert",
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "options": {
          "queryName": "match_documents"
        }
      },
      "id": "b671167f-1416-4391-a4b0-73f294318a2c",
      "name": "Supabase Vector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1,
      "position": [
        3520,
        900
      ],
      "credentials": {
        "supabaseApi": {
          "id": "LoWkUUvEz4f7lZcJ",
          "name": "Supabase account 3"
        }
      }
    },
    {
      "parameters": {
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "options": {}
      },
      "id": "674aa270-f887-405a-b22e-b3e97137afc7",
      "name": "Supabase Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1,
      "position": [
        4720,
        760
      ],
      "credentials": {
        "supabaseApi": {
          "id": "LoWkUUvEz4f7lZcJ",
          "name": "Supabase account 3"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message_text }}{{ $json.sessionId}}",
        "options": {
          "systemMessage": "You are an expert assistant representing Adaptify AI.\n\nYou will use a vector database to retrieve the relevant information and respond to user queries.\n\nYour primary role is to assist users by providing accurate, factual, and relevant information about Adaptify AI's offerings and how they can address specific user needs.\n\nIf the user inquires about a service, guide them on how to explore or engage with Adaptify AI's solutions, providing appropriate URLs, contact details, or additional resources if necessary.\nYour goal is to educate and assist, not facilitate direct sales, ensuring users feel informed and empowered to make their decisions.\n\nIf cannot retrieve the information from the knowledge base and do not know the answer or, be transparent and let the user know. Always strive to maintain clarity and helpfulness in your responses."
        }
      },
      "id": "a36524d0-22a6-48cc-93fe-b4571cec428a",
      "name": "AI Sales Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        4660,
        340
      ],
      "typeVersion": 1.6
    }
  ],
  "pinData": {},
  "connections": {
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "Split Out Message Parts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Sales Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Vector Store Tool",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Audio URL": {
      "main": [
        [
          {
            "node": "Download Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Audio": {
      "main": [
        [
          {
            "node": "Google Gemini Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Audio": {
      "main": [
        [
          {
            "node": "Format Response1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Response1": {
      "main": [
        [
          {
            "node": "Get User's Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Text": {
      "main": [
        [
          {
            "node": "Get User's Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Message Parts": {
      "main": [
        [
          {
            "node": "Redirect Message Types",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Vector Store Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Sales Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter2": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader2",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive2": {
      "main": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Sales Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Google Drive2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader2": {
      "ai_document": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Get User's Message": {
      "main": [
        [
          {
            "node": "AI Sales Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redirect Message Types": {
      "main": [
        [
          {
            "node": "Get Audio URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store": {
      "ai_vectorStore": [
        [
          {
            "node": "Vector Store Tool",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "AI Sales Agent": {
      "main": [
        [
          {
            "node": "Reply To User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "versionId": "3031259f-c51f-49ec-abd9-f8bb589365e5",
  "meta": {
    "templateId": "2465",
    "templateCredsSetupCompleted": true,
    "instanceId": "d1853d6d92799d2de46a947c80ac9a5af91665397cc93a1b568769b332366e37"
  },
  "id": "0khxsr8Wm3aRmHcG",
  "tags": []
}