{
  "name": "My workflow 4",
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Credenciais').item.json.baseUrl }}/message/sendText/{{ $('Credenciais').item.json.instancia }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Credenciais').item.json.apikey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"number\": \"{{ $('Credenciais').item.json.WhatsApp }}\",\n  \"text\": \"{{ $json.output.replace(/\\n/g, '\\\\n').replace(/\\\"/g, '\\\\\\\\\"').replace(/\\*/g, '').replace(/\\s+/g, ' ').trim() }}\"\n}\n",
        "options": {}
      },
      "id": "9f2a6bb4-ee4e-4c79-bc3f-39b75765c21b",
      "name": "Enviar Mensagem WhatsApp Lead6",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1880,
        1005.6948770610335
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2f8e1fbf-9134-4b48-be29-066509e021f5",
              "name": "telefone",
              "value": "={{ $('Webhook').item.json.body.data.key.remoteJid }}",
              "type": "string"
            },
            {
              "id": "59fd3a53-08be-41db-b91e-9abccd7ef4ad",
              "name": "Audio",
              "value": "={{ $json.text || '' }}",
              "type": "string"
            },
            {
              "id": "1f3efabc-087b-4843-8766-742b9109e955",
              "name": "WhatsWeb",
              "value": "={{ $json.pergunta || ''}}",
              "type": "string"
            },
            {
              "id": "60d6b895-fea6-4d7f-932a-b8771c97242e",
              "name": "WhatsAppApp",
              "value": "={{ $json.mensagem || '' }}",
              "type": "string"
            },
            {
              "id": "f45d0d25-8456-4a53-9290-69eed044964e",
              "name": "Imagem",
              "value": "={{ $json.content || ''}}",
              "type": "string"
            },
            {
              "id": "0d9377f3-acbb-49ed-9254-ef9e3e561465",
              "name": "Documento",
              "value": "={{ $json.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "fe36776f-d6cd-4ea7-8f3d-8382a056a5b7",
      "name": "Filtra Webhook",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        200,
        725.6948770610335
      ]
    },
    {
      "parameters": {
        "amount": 6
      },
      "id": "f5ab21ec-dd4b-4284-b970-360e28585177",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        480,
        725.6948770610335
      ],
      "webhookId": "d374af89-c5e3-41a6-8b3f-bfacfcd09870"
    },
    {
      "parameters": {
        "operation": "get",
        "propertyName": "mensagem",
        "key": "={{ $json.telefone }}",
        "options": {}
      },
      "id": "4e06ad13-eb3b-48e1-9d54-3a4b65917b1c",
      "name": "Puxar as Mensagens",
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        480,
        965.6948770610335
      ],
      "credentials": {
        "redis": {
          "id": "OiUMB4ciOVde7idb",
          "name": "Redis account 2"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "9e9b4155-e399-4936-a5db-2d79c8cb871f",
              "leftValue": "={{ $json.mensagem.last() }}",
              "rightValue": "={{ $('Filtra Webhook').item.json.Audio || $('Filtra Webhook').item.json.WhatsWeb || $('Filtra Webhook').item.json.WhatsAppApp || $('Filtra Webhook').item.json.Imagem }}",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "77ce7ba4-972b-4b98-90f8-965e65ba340d",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        640,
        845.6948770610335
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "bce70488-3d4e-412d-9c28-4858906bc722",
              "name": "mensagem",
              "value": "={{ $('Puxar as Mensagens').item.json.mensagem.join('\\n') }}",
              "type": "string"
            },
            {
              "id": "abca95c7-60a4-474b-95ed-a22557fa8af7",
              "name": "telefone",
              "value": "={{ $('Wait').item.json.telefone }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "404fde39-070b-4081-a998-6cd4acc9a290",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        800,
        725.6948770610335
      ]
    },
    {
      "parameters": {},
      "id": "9da2b775-ffa7-44c3-8bde-1356551d4de2",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        800,
        985.6948770610335
      ]
    },
    {
      "parameters": {
        "operation": "delete",
        "key": "={{ $json.telefone }}"
      },
      "id": "9201e0c6-bee5-4c2e-9b48-2bf442c3f7d1",
      "name": "Redis",
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        1000,
        825.6948770610335
      ],
      "credentials": {
        "redis": {
          "id": "OiUMB4ciOVde7idb",
          "name": "Redis account 2"
        }
      }
    },
    {
      "parameters": {},
      "id": "79f7e5f1-b597-4c63-8147-3cb18090bae4",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "typeVersion": 1,
      "position": [
        1360,
        925.6948770610335
      ]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "options": {}
      },
      "id": "6bbc5e6f-179b-4c8b-bcde-db3860940afa",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        1180,
        925.6948770610335
      ],
      "credentials": {
        "openAiApi": {
          "id": "2Wn4ZlGC30GW12Fg",
          "name": "OpenAi account 2"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "44362eda-a17c-4812-9090-a16de9fe4353",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1,
      "position": [
        1360,
        1165.6948770610334
      ],
      "credentials": {
        "openAiApi": {
          "id": "2Wn4ZlGC30GW12Fg",
          "name": "OpenAi account 2"
        }
      }
    },
    {
      "parameters": {},
      "id": "533543d7-5253-41d9-9f1c-863ff5f0cf67",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -580,
        1385.6948770610334
      ],
      "disabled": true
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "(url drive)",
          "mode": "url"
        },
        "options": {}
      },
      "id": "ee5544cb-69cc-472b-af64-7aa048dabeb8",
      "name": "Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -380,
        1385.6948770610334
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "hIf1ub4KefOVFb3d",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "dataType": "binary",
        "options": {}
      },
      "id": "2c660dba-d0b7-4ad0-ad9e-c8a21c8d2b68",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -120,
        1585.6948770610334
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "chunkSize": 3000,
        "chunkOverlap": 200,
        "options": {}
      },
      "id": "051b1f54-231f-4040-8aeb-a4573ff65b8a",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        -120,
        1725.6948770610334
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "7f8f16a6-6ac6-43da-9ccf-72daa3b37d76",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        -240,
        1625.6948770610334
      ],
      "typeVersion": 1,
      "credentials": {
        "openAiApi": {
          "id": "2Wn4ZlGC30GW12Fg",
          "name": "OpenAi account 2"
        }
      }
    },
    {
      "parameters": {
        "name": "dentista",
        "description": "Use essa ferramenta para buscar informações sobre procedimentos e serviços."
      },
      "id": "1de13218-64be-4a90-90b6-cd4ae6baa3c5",
      "name": "Vector Store Tool",
      "type": "@n8n/n8n-nodes-langchain.toolVectorStore",
      "typeVersion": 1,
      "position": [
        1440,
        925.6948770610335
      ]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "options": {}
      },
      "id": "2ed6bf04-7e3b-4e20-9a3e-fc29ed04a375",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        1660,
        1065.6948770610334
      ],
      "credentials": {
        "openAiApi": {
          "id": "2Wn4ZlGC30GW12Fg",
          "name": "OpenAi account 2"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Credenciais').item.json.baseUrl }}/chat/getBase64FromMediaMessage/{{ $('Credenciais').item.json.instancia }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $json.apikey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"message\": {\n        \"key\": {\n            \"id\":  \"{{ $json.body.data.key.id }}\"\n        }\n    },\n    \"convertToMp4\": true\n} ",
        "options": {}
      },
      "id": "4adef791-3f96-40c7-8927-cc97bd42e133",
      "name": "Mensagem de Audio",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        -300,
        485.6948770610335
      ],
      "retryOnFail": true,
      "maxTries": 2
    },
    {
      "parameters": {
        "operation": "toBinary",
        "sourceProperty": "base64",
        "options": {
          "fileName": "audio",
          "mimeType": "={{ $json.mimetype }}"
        }
      },
      "id": "54ab7029-3c2f-4196-adf6-e85eee19dd57",
      "name": "Converter Áudio",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        -160,
        485.6948770610335
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6b7bef37-abbe-4207-aae0-5447388019a3",
              "name": "baseUrl",
              "value": "( url evo )",
              "type": "string"
            },
            {
              "id": "67c50f2f-89e2-4a5c-84c2-c2ac76962f6e",
              "name": "apikey",
              "value": "( api key )",
              "type": "string"
            },
            {
              "id": "9177d222-437a-4284-a96f-115fba66662c",
              "name": "instancia",
              "value": "( instancia )",
              "type": "string"
            },
            {
              "id": "ab90e3ce-3657-4124-968d-37c0aaebd5ab",
              "name": "xi-api-key",
              "value": "( Api Elevenn  Voz)",
              "type": "string"
            },
            {
              "id": "8d6c586e-0f00-4100-bc40-231cda7f93b7",
              "name": "WhatsApp",
              "value": "={{ $json.body.data.key.remoteJid }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "942780de-4a8f-48d9-a0b8-27b2ee319044",
      "name": "Credenciais",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        -860,
        825.6948770610335
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "17694db0-6248-444f-afb9-ff7ed13996ef",
              "name": "pergunta",
              "value": "={{ $('Webhook').item.json.body.data.message.extendedTextMessage.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "9f17a90a-f625-4fa8-8c2f-395d185b45d3",
      "name": "Texto Web",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        -320,
        645.6948770610335
      ],
      "notesInFlow": false,
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2f8e1fbf-9134-4b48-be29-066509e021f5",
              "name": "telefone",
              "value": "={{ $('Webhook').item.json.body.data.key.remoteJid }}",
              "type": "string"
            },
            {
              "id": "a6004904-d9e1-4627-be79-d2a5b073d44f",
              "name": "mensagem",
              "value": "={{ $json.body.data.message.conversation }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "94f8ed9e-3ffb-4e8f-8177-188d2a3977f2",
      "name": "Filta Msg App",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -320,
        805.6948770610335
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Credenciais').item.json.baseUrl }}/chat/getBase64FromMediaMessage/{{ $('Credenciais').item.json.instancia }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Credenciais').item.json.apikey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"message\": {\n        \"key\": {\n            \"id\":  \"{{ $json.body.data.key.id }}\"\n        }\n    },\n    \"convertToMp4\": true\n} ",
        "options": {}
      },
      "id": "902f5a04-8ec6-4ae0-aaa1-fdbb4c346f19",
      "name": "Envio de Imagens",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        -320,
        945.6948770610335
      ],
      "retryOnFail": true,
      "maxTries": 2
    },
    {
      "parameters": {
        "operation": "toBinary",
        "sourceProperty": "base64",
        "options": {
          "fileName": "image",
          "mimeType": ""
        }
      },
      "id": "66e4065a-e7f7-44bd-9fa0-5c35c21735e3",
      "name": "Converter Imagem",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        -180,
        945.6948770610335
      ]
    },
    {
      "parameters": {
        "operation": "push",
        "list": "={{ $json.telefone }}",
        "messageData": "={{ $json.Audio || $json.WhatsWeb || $json.WhatsAppApp || $json.Imagem || $json.mensagem}}",
        "tail": true
      },
      "id": "cb6d39bd-59a5-4283-9b9b-9235859d5dfb",
      "name": "Lista Mensagens1",
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        240,
        965.6948770610335
      ],
      "credentials": {
        "redis": {
          "id": "OiUMB4ciOVde7idb",
          "name": "Redis account 2"
        }
      }
    },
    {
      "parameters": {
        "operation": "pdf",
        "options": {}
      },
      "id": "f22f53e6-fc4f-4c49-aeda-02ca07530123",
      "name": "Extrair Dados",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        0,
        1105.6948770610334
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Credenciais').item.json.baseUrl }}/chat/getBase64FromMediaMessage/{{ $('Credenciais').item.json.instancia }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Credenciais').item.json.apikey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"message\": {\n        \"key\": {\n            \"id\":  \"{{ $json.body.data.key.id }}\"\n        }\n    },\n    \"convertToMp4\": true\n} ",
        "options": {}
      },
      "id": "33671805-1a86-4a5a-9dc4-f178422b01a2",
      "name": "Envio de Documentos1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        -320,
        1105.6948770610334
      ],
      "retryOnFail": true,
      "maxTries": 2
    },
    {
      "parameters": {
        "operation": "toBinary",
        "sourceProperty": "base64",
        "options": {
          "fileName": "=image {{ $('Switch').item.json.body.data.message.documentMessage.fileName }}",
          "mimeType": "={{ $('Switch').item.json.body.data.message.documentMessage.mimetype }}"
        }
      },
      "id": "32d9d81c-e0a0-4e9d-99b4-a969b811d18e",
      "name": "Converter Arquivo1",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        -160,
        1105.6948770610334
      ]
    },
    {
      "parameters": {
        "content": "Filtra as Mensagens",
        "height": 830.5893065371872,
        "width": 1227.62534007333,
        "color": 5
      },
      "id": "103d8c87-23a6-4ead-bb2e-183f25480136",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1040,
        465.6948770610335
      ]
    },
    {
      "parameters": {
        "content": "Concatenação de Mensagens",
        "height": 830.15644164636,
        "width": 952.7060569889857,
        "color": 6
      },
      "id": "5c790449-1b2b-43d1-8cb3-903e87412d8d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        180,
        465.6948770610335
      ]
    },
    {
      "parameters": {
        "content": "IA",
        "height": 828.8267661669029,
        "width": 1031.7647951328638,
        "color": 4
      },
      "id": "b78db5e0-1c9b-4277-8b7d-2fb7b998fe40",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1129.3625961643438,
        465.6948770610335
      ]
    },
    {
      "parameters": {
        "content": "Database Informações",
        "height": 517.6827039739503,
        "width": 864.1985100368698,
        "color": 3
      },
      "id": "45f46768-8271-4b54-8624-58e87a298f49",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -652.8221285273413,
        1345.6948770610334
      ]
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.telefone }}"
      },
      "id": "eb6212c7-587d-462a-87fe-24dc8fcd6a47",
      "name": "Redis Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "typeVersion": 1.3,
      "position": [
        1280,
        925.6948770610335
      ],
      "credentials": {
        "redis": {
          "id": "OiUMB4ciOVde7idb",
          "name": "Redis account 2"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "101c3ff7-e997-43bb-8e99-fe82746c5993",
                    "leftValue": "={{ $json.body.data.message.audioMessage }}",
                    "rightValue": "",
                    "operator": {
                      "type": "object",
                      "operation": "notEmpty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "audioMessage"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "4b94d2ac-53e5-4153-9377-4cc6db20cb1c",
                    "leftValue": "={{ $json.body.data.message.extendedTextMessage }}",
                    "rightValue": "",
                    "operator": {
                      "type": "object",
                      "operation": "notEmpty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "extendedTextMessage"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "38226af4-80fe-4155-9ceb-2379f44e29ed",
                    "leftValue": "={{ $json.body.data.message.conversation }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "conversation"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "300366d9-2416-4cf4-93c3-e48c8761c60f",
                    "leftValue": "={{ $json.body.data.message.imageMessage }}",
                    "rightValue": "",
                    "operator": {
                      "type": "object",
                      "operation": "notEmpty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "imageMessage"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "f33566fd-3eb9-45f4-934a-3a39e2adca6c",
                    "leftValue": "={{ $json.body.data.message.documentWithCaptionMessage.message.documentMessage }}",
                    "rightValue": "",
                    "operator": {
                      "type": "object",
                      "operation": "notEmpty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "documentMessage"
            }
          ]
        },
        "options": {
          "fallbackOutput": "none"
        }
      },
      "id": "f2f456c8-a3e5-44f2-bbd4-8960975959dd",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        -680,
        805.6948770610335
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.elevenlabs.io/v1/text-to-speech/onwK4e9ZLuTAKqWW03F9",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "audio/mpeg"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "xi-api-key",
              "value": "={{ $('Credenciais').item.json['xi-api-key'] }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"text\": \"{{ $json.output.replace(/\\n/g, '\\\\n').replace(/\\\"/g, '\\\\\\\\\"').replace(/\\*/g, '').replace(/\\s+/g, ' ').trim() }}\",\n    \"model_id\": \"eleven_multilingual_v2\",\n    \"voice_settings\": {\n        \"stability\": 0.5,\n        \"similarity_boost\": 0.5\n    }\n}",
        "options": {}
      },
      "id": "ee895f83-6fe2-4291-b0bc-ed1e70ae6dd2",
      "name": "ElevenLabs",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1640,
        645.6948770610335
      ]
    },
    {
      "parameters": {
        "operation": "binaryToPropery",
        "options": {}
      },
      "id": "12030b5a-4fdc-48f6-890a-602c1956e8da",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        1820,
        645.6948770610335
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Credenciais').item.json.baseUrl }}/message/sendWhatsAppAudio/{{ $('Credenciais').item.json.instancia }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Credenciais').item.json.apikey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n\t\"number\": \"{{ $('Webhook').item.json.body.data.key.remoteJid }}\",\n\t\"options\": {\n\t\t\"delay\": 1200,\n\t\t\"presence\": \"recording\",\n        \"encoding\": true\n\t},\n\t\"audioMessage\": {\n\t\t\"audio\": \"{{ $json.data }}\"\n\t}\n}",
        "options": {}
      },
      "id": "0850964b-4a87-49c0-b401-c19b7aacc269",
      "name": "sendWhatsAppAudio",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        2000,
        645.6948770610335
      ]
    },
    {
      "parameters": {
        "content": "## Responde em Áudio\n",
        "height": 239.1747914011388,
        "width": 543.7432906480047,
        "color": 3
      },
      "id": "89074a3e-f035-4a4c-9d1f-e72262037d2a",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1600,
        565.6948770610335
      ]
    },
    {
      "parameters": {
        "content": "## Responde em Texto\n",
        "height": 239.1747914011388,
        "width": 249.0313820540327
      },
      "id": "83635652-ebe5-45f7-9871-4e160be42c3b",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1820,
        905.6948770610335
      ]
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "options": {}
      },
      "id": "5c056fc1-af2a-455c-9bdd-31ade9ed8c80",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.3,
      "position": [
        0,
        485.6948770610335
      ],
      "credentials": {
        "openAiApi": {
          "id": "2Wn4ZlGC30GW12Fg",
          "name": "OpenAi account 2"
        }
      }
    },
    {
      "parameters": {
        "pineconeIndex": {
          "__rl": true,
          "value": "dentista",
          "mode": "list",
          "cachedResultName": "dentista"
        },
        "options": {}
      },
      "id": "b49b7faa-a0e5-4f0d-86f8-0ffad7389ae6",
      "name": "Pinecone Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "typeVersion": 1,
      "position": [
        1400,
        1065.6948770610334
      ],
      "credentials": {
        "pineconeApi": {
          "id": "bjWgYyl8FrjyPXF3",
          "name": "PineconeApi account"
        }
      }
    },
    {
      "parameters": {
        "toolDescription": "use essa ferramenta para enviar imagem de como passar fio dental",
        "method": "POST",
        "url": "(baseurl)/message/sendMedia/(instancia)",
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {
              "name": "apikey",
              "valueProvider": "fieldValue",
              "value": "(apikey)"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"number\": \"{{ $json.telefone }}\",\n    \"mediatype\": \"image\",\n    \"mimetype\": \"image/jpeg\",\n    \"media\": \"https://i.postimg.cc/bYxh0sr4/e385fd5d-f94f-4a87-af28-69452ddd0750.jpg\",\n    \"fileName\": \"Imagem.jpg\"\n}"
      },
      "id": "bf9b1fb7-347e-4c64-b449-c12a28998d76",
      "name": "HTTP Request",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [
        1360,
        305.6948770610335
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.mensagem }}",
        "options": {
          "systemMessage": "=<IA_Atendente>\n  <Clinica>\n    <Nome>Clínica Sorriso Perfeito</Nome>\n    <Endereço>Rua das Flores, 123 - São Paulo, SP</Endereço>\n    <WhatsApp>+55 11 98765-4321</WhatsApp>\n    <Instagram>@clinicasorrisoperfeito</Instagram>\n    <HorarioAtendimento>Segunda a Sexta, das 9h às 18h</HorarioAtendimento>\n  </Clinica>\n\n  <Atendimento>\n    <Aquecimento>\n      <PerguntarNome>Oi, que bom que você entrou em contato! 😁 Eu sou a assistente virtual da Clínica Sorriso Perfeito. Qual o seu nome?</PerguntarNome>\n      <ConectarEmocionalmente>\n        Muito prazer, [NOME]! Aqui na Clínica Sorriso Perfeito, nós acreditamos que um sorriso bonito vai além da estética—ele muda vidas! 😄\n        Vejo que você está interessado(a) em lentes de porcelana ou resina. Esse é um passo incrível para elevar sua autoestima e transformar sua confiança. 🦷✨\n      </ConectarEmocionalmente>\n      <PerguntarObjetivo>\n        Conta pra mim, [NOME], o que você mais deseja para o seu sorriso? Quer realçar, alinhar ou transformar completamente? Estamos aqui para te ajudar a alcançar o sorriso dos seus sonhos! 😍\n      </PerguntarObjetivo>\n    </Aquecimento>\n\n    <CriacaoDeValor>\n      <MostrarAutoridade>\n        Na Clínica Sorriso Perfeito, trabalhamos com os melhores profissionais, como o Dr. Marcos Silva, que já ajudou mais de 1.500 pessoas a conquistarem sorrisos perfeitos. E o melhor: utilizamos materiais de alta qualidade, os mesmos aprovados pelos líderes da odontologia. 💼\n      </MostrarAutoridade>\n      <ExplicarBeneficios>\n        As lentes de porcelana são super resistentes e oferecem uma aparência natural, enquanto as de resina são mais acessíveis e garantem resultados incríveis! Além disso, todos os nossos procedimentos são feitos de maneira totalmente personalizada, pensando no que é melhor para VOCÊ. 😉\n      </ExplicarBeneficios>\n      <CriarUrgencia>\n        Ah, e uma ótima notícia: temos um horário especial para avaliações gratuitas! É uma oportunidade perfeita para entender o que seria ideal para o seu caso. O que acha de agendar? 📅✨\n      </CriarUrgencia>\n    </CriacaoDeValor>\n\n    <GerenciarRespostas>\n      <Posicao1>\n        <Resposta>\n          Sim, quero saber mais e agendar uma consulta.\n        </Resposta>\n        <Agradecer>\n          Que ótimo, [NOME]! Vamos marcar uma avaliação gratuita com o Dr. Marcos Silva, ele vai te orientar pessoalmente e avaliar o melhor tratamento para o seu sorriso. 😊 Para isso, vou precisar de algumas informações suas. Podemos começar com seu WhatsApp e um horário que seja bom para você? 📱\n        </Agradecer>\n        <ColetaDeDados>\n          Poderia me passar seu número de WhatsApp e o melhor horário para a consulta? 📲\n        </ColetaDeDados>\n      </Posicao1>\n\n      <Posicao2>\n        <Resposta>\n          Eu só queria saber o valor primeiro.\n        </Resposta>\n        <GerarValor>\n          Entendo perfeitamente, [NOME]. 😊 O valor pode variar de acordo com o tipo de lente (porcelana ou resina) e as suas necessidades específicas. Por isso, o ideal é fazermos uma avaliação, onde o Dr. Marcos Silva vai te orientar e passar todas as informações com detalhes, incluindo os valores. Assim, você toma a melhor decisão com segurança. Que tal? 😁\n        </GerarValor>\n      </Posicao2>\n\n      <Posicao3>\n        <Resposta>\n          Estou só pesquisando por enquanto.\n        </Resposta>\n        <ConstruirRelacao>\n          Super compreensível, [NOME]! Fazer uma pesquisa é sempre um bom começo. 😉 Aproveita e segue a gente no Instagram (@clinicasorrisoperfeito), lá você vai encontrar dicas incríveis e muitos casos de antes e depois para se inspirar. 💬 E se tiver qualquer dúvida, estarei por aqui para te ajudar!\n        </ConstruirRelacao>\n      </Posicao3>\n    </GerenciarRespostas>\n  </Atendimento>\n\n  <Instrucoes>\n    <Responder>\n      - Perguntar o nome para criar uma conexão emocional logo de início.\n      - Não mencionar valores na primeira interação; foque em destacar os benefícios e autoridade.\n      - Oferecer uma avaliação gratuita para conhecer melhor o cliente e suas necessidades.\n      - Adaptar o tom e estilo de conversa conforme as respostas do cliente, mantendo uma abordagem informal, acolhedora e dinâmica.\n      - Se o cliente insistir no valor, explique que ele pode variar e incentive a consulta para mais detalhes.\n      - Use emojis de forma equilibrada para tornar a conversa leve e amigável.\n - Analise as imagens dos clientes\n- Responde as última mensagens\n- Use a ferramenta Vector Stoore tool para pega informações do banco de dados\n- Use a ferrramenta Http Request Tool para enviar imagens\n    </Responder>\n  </Instrucoes>\n</IA_Atendente>\n"
        }
      },
      "id": "ca693a36-208c-4934-879a-e67dfead64a3",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.6,
      "position": [
        1300,
        645.6948770610335
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "acc18ed4-0840-4ea3-98be-207cfa2f7618",
        "options": {}
      },
      "id": "7dd0c1a1-b082-4390-a2a5-8d4b90bdfe95",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -1040,
        825.6948770610335
      ],
      "webhookId": "acc18ed4-0840-4ea3-98be-207cfa2f7618"
    },
    {
      "parameters": {
        "resource": "image",
        "operation": "analyze",
        "text": "Analise essa imagem, oque tem nela?",
        "inputType": "base64",
        "options": {}
      },
      "id": "04c6e76b-981f-4d34-bd6e-b803a18b37ee",
      "name": "OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.3,
      "position": [
        -40,
        945.6948770610335
      ],
      "credentials": {
        "openAiApi": {
          "id": "2Wn4ZlGC30GW12Fg",
          "name": "OpenAi account 2"
        }
      }
    },
    {
      "parameters": {
        "content": "Exemplo de Tool de envio de imagem\n",
        "height": 205.69487706103345
      },
      "id": "e405ac5c-3c0d-44c6-832b-b491ed82837f",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1280,
        240
      ]
    },
    {
      "parameters": {
        "mode": "insert",
        "pineconeIndex": {
          "__rl": true,
          "value": "dentista",
          "mode": "list",
          "cachedResultName": "dentista"
        },
        "options": {
          "clearNamespace": true
        }
      },
      "id": "a04ca95c-68ff-49f7-b42e-4e11d59beb18",
      "name": "Insert into Pinecone vector store",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        -180,
        1385.6948770610334
      ],
      "typeVersion": 1,
      "credentials": {
        "pineconeApi": {
          "id": "bjWgYyl8FrjyPXF3",
          "name": "PineconeApi account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Filtra Webhook": {
      "main": [
        [
          {
            "node": "Lista Mensagens1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Puxar as Mensagens",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Puxar as Mensagens": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Redis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redis": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive": {
      "main": [
        [
          {
            "node": "Insert into Pinecone vector store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Insert into Pinecone vector store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Insert into Pinecone vector store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Vector Store Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Vector Store Tool",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Mensagem de Audio": {
      "main": [
        [
          {
            "node": "Converter Áudio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Converter Áudio": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Credenciais": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Texto Web": {
      "main": [
        [
          {
            "node": "Filtra Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filta Msg App": {
      "main": [
        [
          {
            "node": "Filtra Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Envio de Imagens": {
      "main": [
        [
          {
            "node": "Converter Imagem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Converter Imagem": {
      "main": [
        [
          {
            "node": "OpenAI1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lista Mensagens1": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extrair Dados": {
      "main": [
        [
          {
            "node": "Filtra Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Envio de Documentos1": {
      "main": [
        [
          {
            "node": "Converter Arquivo1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Converter Arquivo1": {
      "main": [
        [
          {
            "node": "Extrair Dados",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redis Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Mensagem de Audio",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Texto Web",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Filta Msg App",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Envio de Imagens",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Envio de Documentos1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ElevenLabs": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "sendWhatsAppAudio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "Filtra Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store": {
      "ai_vectorStore": [
        [
          {
            "node": "Vector Store Tool",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Enviar Mensagem WhatsApp Lead6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Credenciais",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI1": {
      "main": [
        [
          {
            "node": "Filtra Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "21e0394e-9aa1-4775-af19-ad4609c722b4",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "079e33df96811355e9a4b4196df7f240b7f4dcb46102b91d26bb671e95971058"
  },
  "id": "AVbfeyGZ9sBjKvAB",
  "tags": []
}