{
  "updatedAt": "2026-04-10T04:03:38.735Z",
  "createdAt": "2026-04-07T20:52:37.183Z",
  "id": "qEkpfit2dcWHbYol",
  "name": "Somar.IA SaaS - Agente Aut\u00f4nomo WhatsApp (Din\u00e2mico)",
  "description": null,
  "active": true,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "whatsapp-agent-webhook",
        "options": {}
      },
      "id": "webhook-evolution",
      "name": "Webhook WhatsApp",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        96,
        336
      ]
    },
    {
      "parameters": {
        "url": "https://synka.somar.ia.br/api/n8n/clinic-info",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "tenantId",
              "value": "={{ $('Webhook WhatsApp').item.json.body.tenantId || $('Webhook WhatsApp').item.json.tenantId || 'demo-synka-master' }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "synka132504fE@"
            }
          ]
        },
        "options": {}
      },
      "id": "fetch-context",
      "name": "Carregar Contexto Cl\u00ednica",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        304,
        304
      ]
    },
    {
      "parameters": {
        "text": "={{ $('Webhook WhatsApp').item.json.body.mensagem || $('Webhook WhatsApp').item.json.mensagem }}",
        "options": {
          "systemMessage": "={{ `Voc\u00ea \u00e9 a Assistente Virtual inteligente da ${$node[\"Carregar Contexto Cl\u00ednica\"].json.data.nome}.\nSeu objetivo \u00e9 ser extremamente amig\u00e1vel e garantir que o cliente agende um hor\u00e1rio de forma simples.\n\n\ud83c\udfe5 Hor\u00e1rio: ${$node[\"Carregar Contexto Cl\u00ednica\"].json.data.horarioFuncionamento}\n\ud83d\udd17 Link direto (Plano B): ${$node[\"Carregar Contexto Cl\u00ednica\"].json.data.linkAgendamento}\n\nDIRETRIZES DE OURO:\n1. PRIORIDADE WHATSAPP: Se o cliente quiser agendar, voc\u00ea DEVE fazer por aqui usando suas Ferramentas (Ver Hor\u00e1rios e Criar Agendamento).\n2. FLUXO DE COLETA: Para agendar aqui, voc\u00ea precisa de: Nome, Servi\u00e7o, Profissional, Data e Hora. Pergunte um por um de forma natural. \n3. RESPOSTAS CURTAS: Como no WhatsApp real, responda em no m\u00e1ximo 1 ou 2 frases curtas.\n4. CONFIRMA\u00c7\u00c3O OBRIGAT\u00d3RIA: Antes de finalizar qualquer agendamento, resuma os dados e pe\u00e7a um \"SIM\" do cliente.\n5. LINK ALTERNATIVO: S\u00f3 ofere\u00e7a o link direto se o cliente pedir para agendar sozinho ou se voc\u00ea perceber que ele est\u00e1 com muita pressa.\n\nINSTRU\u00c7\u00d5ES CR\u00cdTICAS:\n- Data atual: ${new Date().toLocaleDateString('pt-BR', {timeZone:'America/Fortaleza'})} (ano 2026)\n- Use SEMPRE o campo \"id\" retornado pelas ferramentas para servicoId e profissionalId. NUNCA invente IDs.\n- Para ver hor\u00e1rios, chame PRIMEIRO Listar Op\u00e7\u00f5es para obter o servicoId real, depois Ver Hor\u00e1rios.` }}"
        }
      },
      "id": "ai-agent-main",
      "name": "Agente Aut\u00f4nomo Especializado",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1,
      "position": [
        512,
        304
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "gemini-model",
      "name": "Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        464,
        512
      ],
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "contextWindowLength": 10
      },
      "id": "buffer-memory",
      "name": "Mem\u00f3ria da Conversa",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1,
      "position": [
        608,
        512
      ]
    },
    {
      "parameters": {
        "url": "={{ \"https://synka.somar.ia.br/api/n8n/list-metadata?_key=\" + synka132504fE@ + \"&tenantId=\" + $('Carregar Contexto Cl\u00ednica').item.json.data.tenantId }}",
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {
              "name": "tipo"
            }
          ]
        },
        "sendHeaders": false,
        "toolDescription": "Lista servi\u00e7os, profissionais ou especialidades da cl\u00ednica. Par\u00e2metro tipo: \"servicos\", \"profissionais\" ou \"especialidades\". Retorna lista com campo \"id\" que DEVE ser usado nas outras ferramentas."
      },
      "id": "tool-list",
      "name": "Ferramenta: Listar Op\u00e7\u00f5es",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1,
      "position": [
        752,
        432
      ]
    },
    {
      "parameters": {
        "url": "={{ \"https://synka.somar.ia.br/api/n8n/professionals-by-service?_key=\" + synka132504fE@ + \"&tenantId=\" + $('Carregar Contexto Cl\u00ednica').item.json.data.tenantId }}",
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {
              "name": "servicoId"
            }
          ]
        },
        "sendHeaders": false,
        "toolDescription": "Lista os profissionais que atendem um servi\u00e7o espec\u00edfico. Par\u00e2metro servicoId: usar o campo \"id\" retornado pela ferramenta Listar Op\u00e7\u00f5es."
      },
      "id": "tool-list-by-service",
      "name": "Ferramenta: Profissionais por Servi\u00e7o",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1,
      "position": [
        912,
        480
      ]
    },
    {
      "parameters": {
        "url": "={{ \"https://synka.somar.ia.br/api/n8n/client-info?_key=\" + synka132504fE@ + \"&tenantId=\" + $('Carregar Contexto Cl\u00ednica').item.json.data.tenantId }}",
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {
              "name": "whatsapp"
            }
          ]
        },
        "sendHeaders": false
      },
      "id": "tool-client-info",
      "name": "Ferramenta: Info do Cliente",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1,
      "position": [
        1056,
        544
      ]
    },
    {
      "parameters": {
        "url": "={{ \"https://synka.somar.ia.br/api/n8n/agenda/disponibilidade?_key=\" + synka132504fE@ + \"&tenantId=\" + $('Carregar Contexto Cl\u00ednica').item.json.data.tenantId }}",
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {
              "name": "data"
            },
            {
              "name": "servicoId"
            },
            {
              "name": "profissionalId"
            }
          ]
        },
        "sendHeaders": false,
        "toolDescription": "Consulta hor\u00e1rios dispon\u00edveis de um profissional em uma data espec\u00edfica. Par\u00e2metros: data (YYYY-MM-DD, ano SEMPRE 2026 ou posterior), servicoId (ID do servi\u00e7o \u2014 usar o campo \"id\" retornado pela ferramenta Listar Op\u00e7\u00f5es), profissionalId (ID do profissional \u2014 usar o campo \"id\" retornado pela ferramenta Listar Op\u00e7\u00f5es, NUNCA inventar)."
      },
      "id": "tool-availability",
      "name": "Ferramenta: Ver Hor\u00e1rios",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1,
      "position": [
        1200,
        432
      ]
    },
    {
      "parameters": {
        "url": "={{ \"https://synka.somar.ia.br/api/n8n/cliente/buscar?_key=\" + synka132504fE@ + \"&tenantId=\" + $('Carregar Contexto Cl\u00ednica').item.json.data.tenantId }}",
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {
              "name": "telefone"
            }
          ]
        },
        "sendHeaders": false
      },
      "id": "tool-get-appointments",
      "name": "Ferramenta: Consultar Agendamentos",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1,
      "position": [
        1056,
        624
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ \"https://synka.somar.ia.br/api/n8n/agenda/criar?_key=\" + synka132504fE@ + \"&tenantId=\" + $('Carregar Contexto Cl\u00ednica').item.json.data.tenantId }}",
        "sendHeaders": false,
        "sendBody": true,
        "parametersBody": {
          "values": [
            {
              "name": "nome"
            },
            {
              "name": "dataHora"
            },
            {
              "name": "pacienteTelefone"
            },
            {
              "name": "servicoId"
            },
            {
              "name": "profissionalId"
            },
            {
              "name": "tenantId"
            }
          ]
        },
        "toolDescription": "Cria um agendamento. Usar apenas ap\u00f3s confirma\u00e7\u00e3o expl\u00edcita do cliente (SIM). IMPORTANTE: usar os IDs reais de servicoId e profissionalId retornados pelas ferramentas."
      },
      "id": "tool-book",
      "name": "Ferramenta: Criar Agendamento",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1,
      "position": [
        1360,
        480
      ]
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "={{ \"https://synka.somar.ia.br/api/n8n/agenda/cancelar?_key=\" + synka132504fE@ + \"&tenantId=\" + $('Carregar Contexto Cl\u00ednica').item.json.data.tenantId }}",
        "sendHeaders": false,
        "sendBody": true,
        "parametersBody": {
          "values": [
            {
              "name": "id"
            },
            {
              "name": "status"
            },
            {
              "name": "dataHora"
            },
            {
              "name": "tenantId"
            }
          ]
        }
      },
      "id": "tool-update",
      "name": "Ferramenta: Remarcar ou Cancelar",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1,
      "position": [
        1360,
        608
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $('Webhook WhatsApp').item.json.body.mensagem.trim().toLowerCase().normalize('NFD').replace(/[\\u0300-\\u036f]/g, '') }}",
              "operation": "regex",
              "value2": "^(sim|s|confirmo|confirmar)[!?.]*$"
            }
          ]
        }
      },
      "id": "if-sim",
      "name": "\u00c9 SIM?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        304,
        160
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $('Webhook WhatsApp').item.json.body.mensagem.trim().toLowerCase().normalize('NFD').replace(/[\\u0300-\\u036f]/g, '') }}",
              "operation": "regex",
              "value2": "^(nao|n|cancelar|cancela|nao)[!?.]*$"
            }
          ]
        }
      },
      "id": "if-nao",
      "name": "\u00c9 NAO?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        304,
        480
      ]
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "https://synka.somar.ia.br/api/n8n/agenda/confirmar",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "synka132504fE@"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "bodyParameters": {
          "parameters": [
            {
              "name": "telefone",
              "value": "={{ $('Webhook WhatsApp').item.json.body.telefone }}"
            },
            {
              "name": "tenantId",
              "value": "={{ $('Carregar Contexto Cl\u00ednica').item.json.data.tenantId }}"
            }
          ]
        },
        "options": {}
      },
      "id": "http-confirmar",
      "name": "Confirmar Agendamento",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        512,
        160
      ]
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "https://synka.somar.ia.br/api/n8n/agenda/cancelar-por-telefone",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "synka132504fE@"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "bodyParameters": {
          "parameters": [
            {
              "name": "telefone",
              "value": "={{ $('Webhook WhatsApp').item.json.body.telefone }}"
            },
            {
              "name": "tenantId",
              "value": "={{ $('Carregar Contexto Cl\u00ednica').item.json.data.tenantId }}"
            }
          ]
        },
        "options": {}
      },
      "id": "http-cancelar-tel",
      "name": "Cancelar por Telefone",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        512,
        480
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.ultramsg.com/instance168762/messages/chat?token=xp3fx1lj7lsnozzg",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "to",
              "value": "={{ $('Webhook WhatsApp').item.json.body.telefone }}"
            },
            {
              "name": "body",
              "value": "={{ $json.data?.msgBot ?? 'Agendamento confirmado!' }}"
            }
          ]
        },
        "options": {}
      },
      "id": "send-wa-confirmar",
      "name": "Enviar Confirma\u00e7\u00e3o WA",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        720,
        160
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.ultramsg.com/instance168762/messages/chat?token=xp3fx1lj7lsnozzg",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "to",
              "value": "={{ $('Webhook WhatsApp').item.json.body.telefone }}"
            },
            {
              "name": "body",
              "value": "={{ $json.data?.msgBot ?? 'Agendamento cancelado.' }}"
            }
          ]
        },
        "options": {}
      },
      "id": "send-wa-cancelar",
      "name": "Enviar Cancelamento WA",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        720,
        480
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.ultramsg.com/instance168762/messages/chat?token=xp3fx1lj7lsnozzg",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "to",
              "value": "={{ $('Webhook WhatsApp').item.json.body.telefone }}"
            },
            {
              "name": "body",
              "value": "={{ $('Agente Aut\u00f4nomo Especializado').item.json.output }}"
            }
          ]
        },
        "options": {}
      },
      "id": "send-wa",
      "name": "Disparar Resposta WhatsApp",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1360,
        256
      ]
    },
    {
      "parameters": {
        "url": "https://synka.somar.ia.br/api/n8n/clinic-info",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "tenantId",
              "value": "={{ $('Webhook WhatsApp').item.json.body.tenantId }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "synka132504fE@"
            }
          ]
        },
        "options": {}
      },
      "id": "buscar-config-wa",
      "name": "Buscar Config WA",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        864,
        160
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.whatsappInstanceKey }}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "id": "if-wa-config",
      "name": "Tem inst\u00e2ncia pr\u00f3pria?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1072,
        160
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://wasenderapi.com/api/messages/send",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {}
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "to",
              "value": "={{ ($('Webhook WhatsApp').item.json.body.telefone || $('Webhook WhatsApp').item.json.telefone) }}"
            },
            {
              "name": "message",
              "value": "={{ $('Agente Aut\u00f4nomo Especializado').item.json.output }}"
            }
          ]
        },
        "options": {}
      },
      "id": "send-wasender",
      "name": "Disparar Resposta WaSender",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1312,
        64
      ]
    }
  ],
  "connections": {
    "Webhook WhatsApp": {
      "main": [
        [
          {
            "node": "Carregar Contexto Cl\u00ednica",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Carregar Contexto Cl\u00ednica": {
      "main": [
        [
          {
            "node": "\u00c9 SIM?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u00c9 SIM?": {
      "main": [
        [
          {
            "node": "Confirmar Agendamento",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\u00c9 NAO?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u00c9 NAO?": {
      "main": [
        [
          {
            "node": "Cancelar por Telefone",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Confirmar Agendamento": {
      "main": [
        [
          {
            "node": "Enviar Confirma\u00e7\u00e3o WA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cancelar por Telefone": {
      "main": [
        [
          {
            "node": "Enviar Cancelamento WA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agente Aut\u00f4nomo Especializado": {
      "main": [
        [
          {
            "node": "Buscar Config WA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini": {
      "ai_languageModel": [
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Mem\u00f3ria da Conversa": {
      "ai_memory": [
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Ferramenta: Listar Op\u00e7\u00f5es": {
      "ai_tool": [
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Ferramenta: Profissionais por Servi\u00e7o": {
      "ai_tool": [
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Ferramenta: Info do Cliente": {
      "ai_tool": [
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Ferramenta: Ver Hor\u00e1rios": {
      "ai_tool": [
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Ferramenta: Consultar Agendamentos": {
      "ai_tool": [
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Ferramenta: Criar Agendamento": {
      "ai_tool": [
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Ferramenta: Remarcar ou Cancelar": {
      "ai_tool": [
        [
          {
            "node": "Agente Aut\u00f4nomo Especializado",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Buscar Config WA": {
      "main": [
        [
          {
            "node": "Tem inst\u00e2ncia pr\u00f3pria?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tem inst\u00e2ncia pr\u00f3pria?": {
      "main": [
        [
          {
            "node": "Disparar Resposta WaSender",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Disparar Resposta WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "timeSavedMode": "fixed",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "versionId": "a1cba22f-cd23-4a96-8ab3-42e9d0367275",
  "activeVersionId": "a1cba22f-cd23-4a96-8ab3-42e9d0367275",
  "versionCounter": 453,
  "triggerCount": 1,
  "shared": [
    {
      "updatedAt": "2026-04-07T20:52:37.183Z",
      "createdAt": "2026-04-07T20:52:37.183Z",
      "role": "workflow:owner",
      "workflowId": "qEkpfit2dcWHbYol",
      "projectId": "U0Cc0yzoZfSkcbLi",
      "project": {
        "updatedAt": "2026-03-22T18:57:21.062Z",
        "createdAt": "2026-03-22T18:56:23.795Z",
        "id": "U0Cc0yzoZfSkcbLi",
        "name": "Barbosa somar.solucoes.suporte@gmail.com <somar.solucoes.suporte@gmail.com>",
        "type": "personal",
        "icon": null,
        "description": null,
        "creatorId": "a3a6fdbe-6d03-45f0-8c11-118eb7666e9a"
      }
    }
  ],
  "tags": [],
  "activeVersion": {
    "updatedAt": "2026-04-10T04:03:43.998Z",
    "createdAt": "2026-04-10T04:03:38.736Z",
    "versionId": "a1cba22f-cd23-4a96-8ab3-42e9d0367275",
    "workflowId": "qEkpfit2dcWHbYol",
    "nodes": [
      {
        "parameters": {
          "httpMethod": "POST",
          "path": "whatsapp-agent-webhook",
          "options": {}
        },
        "id": "webhook-evolution",
        "name": "Webhook WhatsApp",
        "type": "n8n-nodes-base.webhook",
        "typeVersion": 1,
        "position": [
          96,
          336
        ],
        "webhookId": "6f352cac-a2ea-4cb2-ad14-fca0077fdc11"
      },
      {
        "parameters": {
          "url": "https://synka.somar.ia.br/api/n8n/clinic-info",
          "sendQuery": true,
          "queryParameters": {
            "parameters": [
              {
                "name": "tenantId",
                "value": "={{ $('Webhook WhatsApp').item.json.body.tenantId || $('Webhook WhatsApp').item.json.tenantId || 'demo-synka-master' }}"
              }
            ]
          },
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "x-api-key",
                "value": "synka132504fE@"
              }
            ]
          },
          "options": {}
        },
        "id": "fetch-context",
        "name": "Carregar Contexto Cl\u00ednica",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          304,
          304
        ]
      },
      {
        "parameters": {
          "text": "={{ $('Webhook WhatsApp').item.json.body.mensagem || $('Webhook WhatsApp').item.json.mensagem }}",
          "options": {
            "systemMessage": "={{ `Voc\u00ea \u00e9 a Assistente Virtual inteligente da ${$node[\"Carregar Contexto Cl\u00ednica\"].json.nome}.\nSeu objetivo \u00e9 ser extremamente amig\u00e1vel e garantir que o cliente agende um hor\u00e1rio de forma simples.\n\n\ud83c\udfe5 Hor\u00e1rio: ${$node[\"Carregar Contexto Cl\u00ednica\"].json.horarioFuncionamento}\n\ud83d\udd17 Link direto (Plano B): ${$node[\"Carregar Contexto Cl\u00ednica\"].json.linkAgendamento}\n\nDIRETRIZES DE OURO:\n1. PRIORIDADE WHATSAPP: Se o cliente quiser agendar, voc\u00ea DEVE fazer por aqui usando suas Ferramentas (Ver Hor\u00e1rios e Criar Agendamento).\n2. FLUXO DE COLETA: Para agendar aqui, voc\u00ea precisa de: Nome, Servi\u00e7o, Profissional, Data e Hora. Pergunte um por um de forma natural. \n3. RESPOSTAS CURTAS: Como no WhatsApp real, responda em no m\u00e1ximo 1 ou 2 frases curtas.\n4. CONFIRMA\u00c7\u00c3O OBRIGAT\u00d3RIA: Antes de finalizar qualquer agendamento, resuma os dados e pe\u00e7a um \"SIM\" do cliente.\n5. LINK ALTERNATIVO: S\u00f3 ofere\u00e7a o link direto se o cliente pedir para agendar sozinho ou se voc\u00ea perceber que ele est\u00e1 com muita pressa.` }}"
          }
        },
        "id": "ai-agent-main",
        "name": "Agente Aut\u00f4nomo Especializado",
        "type": "@n8n/n8n-nodes-langchain.agent",
        "typeVersion": 1,
        "position": [
          512,
          304
        ]
      },
      {
        "parameters": {
          "options": {}
        },
        "id": "gemini-model",
        "name": "Google Gemini",
        "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
        "typeVersion": 1,
        "position": [
          464,
          512
        ],
        "credentials": {
          "googlePalmApi": {
            "id": "c5yCGVFQzwGrd3SF",
            "name": "Google Gemini(PaLM) Api account"
          }
        }
      },
      {
        "parameters": {
          "contextWindowLength": 10
        },
        "id": "buffer-memory",
        "name": "Mem\u00f3ria da Conversa",
        "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
        "typeVersion": 1,
        "position": [
          608,
          512
        ]
      },
      {
        "parameters": {
          "url": "https://api.somar.ia.br/api/n8n/list-metadata",
          "sendQuery": true,
          "parametersQuery": {
            "values": [
              {
                "name": "tenantId"
              },
              {
                "name": "tipo"
              }
            ]
          },
          "sendHeaders": true,
          "parametersHeaders": {
            "values": [
              {
                "name": "x-api-key"
              }
            ]
          }
        },
        "id": "tool-list",
        "name": "Ferramenta: Listar Op\u00e7\u00f5es",
        "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
        "typeVersion": 1,
        "position": [
          752,
          432
        ]
      },
      {
        "parameters": {
          "url": "https://api.somar.ia.br/api/n8n/professionals-by-service",
          "sendQuery": true,
          "parametersQuery": {
            "values": [
              {
                "name": "tenantId"
              },
              {
                "name": "servicoId"
              }
            ]
          },
          "sendHeaders": true,
          "parametersHeaders": {
            "values": [
              {
                "name": "x-api-key"
              }
            ]
          }
        },
        "id": "tool-list-by-service",
        "name": "Ferramenta: Profissionais por Servi\u00e7o",
        "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
        "typeVersion": 1,
        "position": [
          912,
          480
        ]
      },
      {
        "parameters": {
          "url": "https://api.somar.ia.br/api/n8n/client-info",
          "sendQuery": true,
          "parametersQuery": {
            "values": [
              {
                "name": "tenantId"
              },
              {
                "name": "whatsapp"
              }
            ]
          },
          "sendHeaders": true,
          "parametersHeaders": {
            "values": [
              {
                "name": "x-api-key"
              }
            ]
          }
        },
        "id": "tool-client-info",
        "name": "Ferramenta: Info do Cliente",
        "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
        "typeVersion": 1,
        "position": [
          1056,
          544
        ]
      },
      {
        "parameters": {
          "url": "https://synka.somar.ia.br/api/n8n/agenda/disponibilidade",
          "sendQuery": true,
          "parametersQuery": {
            "values": [
              {
                "name": "date"
              },
              {
                "name": "profissionalId"
              },
              {
                "name": "tenantId"
              }
            ]
          },
          "sendHeaders": true,
          "parametersHeaders": {
            "values": [
              {
                "name": "x-api-key"
              }
            ]
          }
        },
        "id": "tool-availability",
        "name": "Ferramenta: Ver Hor\u00e1rios",
        "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
        "typeVersion": 1,
        "position": [
          1200,
          432
        ]
      },
      {
        "parameters": {
          "url": "https://synka.somar.ia.br/api/n8n/cliente/buscar",
          "sendQuery": true,
          "parametersQuery": {
            "values": [
              {
                "name": "telefone"
              },
              {
                "name": "tenantId"
              }
            ]
          },
          "sendHeaders": true,
          "parametersHeaders": {
            "values": [
              {
                "name": "x-api-key"
              }
            ]
          }
        },
        "id": "tool-get-appointments",
        "name": "Ferramenta: Consultar Agendamentos",
        "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
        "typeVersion": 1,
        "position": [
          1056,
          624
        ]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://synka.somar.ia.br/api/n8n/agenda/criar",
          "sendHeaders": true,
          "parametersHeaders": {
            "values": [
              {
                "name": "x-api-key"
              }
            ]
          },
          "sendBody": true,
          "parametersBody": {
            "values": [
              {
                "name": "nome"
              },
              {
                "name": "dataHora"
              },
              {
                "name": "pacienteTelefone"
              },
              {
                "name": "servicoId"
              },
              {
                "name": "profissionalId"
              },
              {
                "name": "tenantId"
              }
            ]
          }
        },
        "id": "tool-book",
        "name": "Ferramenta: Criar Agendamento",
        "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
        "typeVersion": 1,
        "position": [
          1360,
          480
        ]
      },
      {
        "parameters": {
          "method": "PATCH",
          "url": "https://synka.somar.ia.br/api/n8n/agenda/cancelar",
          "sendHeaders": true,
          "parametersHeaders": {
            "values": [
              {
                "name": "x-api-key"
              }
            ]
          },
          "sendBody": true,
          "parametersBody": {
            "values": [
              {
                "name": "id"
              },
              {
                "name": "status"
              },
              {
                "name": "dataHora"
              },
              {
                "name": "tenantId"
              }
            ]
          }
        },
        "id": "tool-update",
        "name": "Ferramenta: Remarcar ou Cancelar",
        "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
        "typeVersion": 1,
        "position": [
          1360,
          608
        ]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://api.ultramsg.com/instance168762/messages/chat?token=xp3fx1lj7lsnozzg",
          "sendBody": true,
          "contentType": "form-urlencoded",
          "bodyParameters": {
            "parameters": [
              {
                "name": "to",
                "value": "={{ $('Webhook WhatsApp').item.json.body.telefone }}"
              },
              {
                "name": "body",
                "value": "={{ $('Agente Aut\u00f4nomo Especializado').item.json.output }}"
              }
            ]
          },
          "options": {}
        },
        "id": "send-wa",
        "name": "Disparar Resposta WhatsApp",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          1360,
          256
        ]
      },
      {
        "parameters": {
          "url": "https://synka.somar.ia.br/api/n8n/clinic-info",
          "sendQuery": true,
          "queryParameters": {
            "parameters": [
              {
                "name": "tenantId",
                "value": "={{ $('Webhook WhatsApp').item.json.body.tenantId }}"
              }
            ]
          },
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "x-api-key",
                "value": "synka132504fE@"
              }
            ]
          },
          "options": {}
        },
        "id": "buscar-config-wa",
        "name": "Buscar Config WA",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          864,
          160
        ]
      },
      {
        "parameters": {
          "conditions": {
            "string": [
              {
                "value1": "={{ $json.whatsappInstanceKey }}",
                "operation": "isNotEmpty"
              }
            ]
          }
        },
        "id": "if-wa-config",
        "name": "Tem inst\u00e2ncia pr\u00f3pria?",
        "type": "n8n-nodes-base.if",
        "typeVersion": 1,
        "position": [
          1072,
          160
        ]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "https://wasenderapi.com/api/messages/send",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {}
            ]
          },
          "sendBody": true,
          "bodyParameters": {
            "parameters": [
              {
                "name": "to",
                "value": "={{ ($('Webhook WhatsApp').item.json.body.telefone || $('Webhook WhatsApp').item.json.telefone) }}"
              },
              {
                "name": "message",
                "value": "={{ $('Agente Aut\u00f4nomo Especializado').item.json.output }}"
              }
            ]
          },
          "options": {}
        },
        "id": "send-wasender",
        "name": "Disparar Resposta WaSender",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          1312,
          64
        ]
      }
    ],
    "connections": {
      "Webhook WhatsApp": {
        "main": [
          [
            {
              "node": "Carregar Contexto Cl\u00ednica",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Carregar Contexto Cl\u00ednica": {
        "main": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Agente Aut\u00f4nomo Especializado": {
        "main": [
          [
            {
              "node": "Buscar Config WA",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Google Gemini": {
        "ai_languageModel": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "ai_languageModel",
              "index": 0
            }
          ]
        ]
      },
      "Mem\u00f3ria da Conversa": {
        "ai_memory": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "ai_memory",
              "index": 0
            }
          ]
        ]
      },
      "Ferramenta: Listar Op\u00e7\u00f5es": {
        "ai_tool": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "ai_tool",
              "index": 0
            }
          ]
        ]
      },
      "Ferramenta: Profissionais por Servi\u00e7o": {
        "ai_tool": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "ai_tool",
              "index": 0
            }
          ]
        ]
      },
      "Ferramenta: Info do Cliente": {
        "ai_tool": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "ai_tool",
              "index": 0
            }
          ]
        ]
      },
      "Ferramenta: Ver Hor\u00e1rios": {
        "ai_tool": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "ai_tool",
              "index": 0
            }
          ]
        ]
      },
      "Ferramenta: Consultar Agendamentos": {
        "ai_tool": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "ai_tool",
              "index": 0
            }
          ]
        ]
      },
      "Ferramenta: Criar Agendamento": {
        "ai_tool": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "ai_tool",
              "index": 0
            }
          ]
        ]
      },
      "Ferramenta: Remarcar ou Cancelar": {
        "ai_tool": [
          [
            {
              "node": "Agente Aut\u00f4nomo Especializado",
              "type": "ai_tool",
              "index": 0
            }
          ]
        ]
      },
      "Buscar Config WA": {
        "main": [
          [
            {
              "node": "Tem inst\u00e2ncia pr\u00f3pria?",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Tem inst\u00e2ncia pr\u00f3pria?": {
        "main": [
          [
            {
              "node": "Disparar Resposta WaSender",
              "type": "main",
              "index": 0
            }
          ],
          [
            {
              "node": "Disparar Resposta WhatsApp",
              "type": "main",
              "index": 0
            }
          ]
        ]
      }
    },
    "authors": "Barbosa somar.solucoes.suporte@gmail.com",
    "name": "Version a1cba22f",
    "description": "",
    "autosaved": true,
    "workflowPublishHistory": [
      {
        "createdAt": "2026-04-10T04:03:43.997Z",
        "id": 391,
        "workflowId": "qEkpfit2dcWHbYol",
        "versionId": "a1cba22f-cd23-4a96-8ab3-42e9d0367275",
        "event": "activated",
        "userId": "a3a6fdbe-6d03-45f0-8c11-118eb7666e9a"
      }
    ]
  }
}