{
  "active": true,
  "connections": {
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "post_Schedule": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "post_Name": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "post_Procedure": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Notion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion": {
      "main": [
        [
          {
            "node": "Date & Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notion1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields2": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Notion1": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_Schedule": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory1": {
      "ai_memory": [
        [
          {
            "node": "Chat Memory Manager",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time": {
      "main": [
        [
          {
            "node": "Date & Time1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \"Test workflow\"": {
      "main": [
        [
          {
            "node": "Chat Memory Manager",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time1": {
      "main": [
        [
          {
            "node": "Edit Fields2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "createdAt": "2024-02-20T04:51:47.432Z",
  "id": "eskQYvZkZVdKTflm",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Clinic.AI",
  "nodes": [
    {
      "parameters": {
        "sessionKey": "={{ $('If1').item.json.whatsapp }}",
        "contextWindowLength": 30
      },
      "id": "1f43aed3-5676-4ccc-91e4-8a265d56b7a9",
      "name": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.1,
      "position": [
        1420,
        680
      ]
    },
    {
      "parameters": {
        "name": "post_ToSchedule",
        "description": "here we will schedule the patient's appointment with the date and time of the appointment.",
        "workflowId": "v7Xib2cl56a2in53",
        "fields": {
          "values": [
            {
              "name": "cus_cel",
              "stringValue": "={{ $('If1').item.json.whatsapp }}"
            }
          ]
        }
      },
      "id": "d2883792-3dfd-49e2-953d-ef711d944af6",
      "name": "post_Schedule",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 1,
      "position": [
        1680,
        680
      ]
    },
    {
      "parameters": {
        "name": "post_Name",
        "description": "save user name to spreadsheet",
        "workflowId": "938MfMGZrn14VJNP",
        "fields": {
          "values": [
            {
              "name": "cus_cel",
              "stringValue": "={{ $('If1').item.json.whatsapp }}"
            }
          ]
        }
      },
      "id": "3b3b7bc4-11f6-47c4-ab39-86a06e20409b",
      "name": "post_Name",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 1,
      "position": [
        1540,
        680
      ]
    },
    {
      "parameters": {
        "name": "get_Schedule",
        "description": "call a function to check which times are available this week",
        "workflowId": "g0VoeC7g7LSTtOn8",
        "fields": {
          "values": [
            {
              "name": "cel",
              "stringValue": "={{ $('If1').item.json.whatsapp }}"
            }
          ]
        }
      },
      "id": "ea122eec-6ca4-4048-99be-9f054ca07a4c",
      "name": "get_Schedule",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 1,
      "position": [
        1960,
        680
      ]
    },
    {
      "parameters": {
        "name": "post_Procedure",
        "description": "save the procedure that the customer is interested in",
        "workflowId": "rxGBOvSC9J5dhmOX",
        "fields": {
          "values": [
            {
              "name": "cus_cel",
              "stringValue": "={{ $('If1').item.json.whatsapp }}"
            }
          ]
        }
      },
      "id": "bdbe4d12-54c5-420e-a27b-c690db1e0eee",
      "name": "post_Procedure",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 1,
      "position": [
        1820,
        680
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": {
          "__rl": true,
          "value": "ca15ab7c-783f-404e-a5a3-c19991af4a89",
          "mode": "list",
          "cachedResultName": "Leads CRM",
          "cachedResultUrl": "https://www.notion.so/ca15ab7c783f404ea5a3c19991af4a89"
        },
        "filterType": "manual",
        "matchType": "allFilters",
        "filters": {
          "conditions": [
            {
              "key": "Whatsapp|rich_text",
              "condition": "equals",
              "richTextValue": "={{ $json.whats }}"
            }
          ]
        },
        "options": {}
      },
      "id": "56cd109e-e320-4a2a-beed-48f46486bccd",
      "name": "Notion",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.1,
      "position": [
        100,
        320
      ],
      "alwaysOutputData": true,
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "id": "efcf85f3-c228-4789-8350-90cec217e229",
      "name": "When clicking \"Test workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        620,
        20
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "1f1101e4-30ff-4751-86a9-abf3c759630a",
              "leftValue": "={{ $('Notion').item.json.property_whatsapp }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "dfee3b53-552c-4b4a-b0aa-2aeb360a231e",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1000,
        320
      ]
    },
    {
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "whats",
              "stringValue": "={{ $json.body.phone }}"
            },
            {
              "name": "input1",
              "stringValue": "={{ $json.body.message }}"
            }
          ]
        },
        "options": {}
      },
      "id": "122de62a-1410-4618-8a39-8ed89161fb72",
      "name": "Edit Fields1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        -60,
        320
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "ca15ab7c-783f-404e-a5a3-c19991af4a89",
          "mode": "list",
          "cachedResultName": "Leads CRM",
          "cachedResultUrl": "https://www.notion.so/ca15ab7c783f404ea5a3c19991af4a89"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Whatsapp|rich_text",
              "textContent": "={{ $json.whatsapp }}"
            }
          ]
        },
        "options": {}
      },
      "id": "811470f9-fc5c-46d2-ade8-bca5135acbc4",
      "name": "Notion1",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.1,
      "position": [
        1200,
        460
      ],
      "alwaysOutputData": true,
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "whatsapp",
              "stringValue": "={{ $('Edit Fields1').item.json.whats }}"
            },
            {
              "name": "input",
              "stringValue": "={{ $('Edit Fields1').item.json.input1 }}"
            }
          ]
        },
        "options": {}
      },
      "id": "0b938e6d-019e-4bac-ad06-47c7da72b3af",
      "name": "Edit Fields2",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        740,
        320
      ]
    },
    {
      "parameters": {
        "model": "gpt-3.5-turbo-16k",
        "options": {}
      },
      "id": "edf8ea8b-aedb-492a-b9c7-be59404358c9",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        1320,
        680
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "clinic-ai",
        "options": {}
      },
      "id": "acb121d0-fe7d-4750-88c4-a92387055d15",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [
        -260,
        320
      ]
    },
    {
      "parameters": {
        "mode": "delete",
        "deleteMode": "all"
      },
      "id": "8f01b41a-c320-4d12-952a-77fba9855de5",
      "name": "Chat Memory Manager",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "typeVersion": 1,
      "position": [
        820,
        20
      ]
    },
    {
      "parameters": {
        "sessionKey": "=556696188393",
        "contextWindowLength": "={{ 30 }}"
      },
      "id": "c8d770b3-1ab5-45ed-8e53-e0ce270fcd26",
      "name": "Window Buffer Memory1",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.1,
      "position": [
        900,
        160
      ]
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ new Date() }}",
        "format": "yyyy-MM-dd",
        "outputFieldName": "today",
        "options": {
          "timezone": true
        }
      },
      "id": "bcf1a84b-7c2b-47b9-aa19-668b46501493",
      "name": "Date & Time",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        280,
        320
      ]
    },
    {
      "parameters": {
        "operation": "formatDate",
        "date": "={{ new Date() }}",
        "format": "custom",
        "customFormat": "HH-mm",
        "outputFieldName": "todayHours",
        "options": {
          "timezone": true
        }
      },
      "id": "2ef4bdd4-af53-4e15-93c8-0bdee69e2c72",
      "name": "Date & Time1",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "position": [
        520,
        320
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Obtenha a data atual\nconst todayDate = $('Date & Time').item.json.today\nconst today = new Date(todayDate)\n\n// Obtenha o dia da semana (0 a 6)\nconst dayOfWeek = today.getDay();\n\n// Mapeie o n\u00famero do dia da semana para o nome do dia\nconst weekdays = ['Domingo', 'Segunda-feira', 'Ter\u00e7a-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'S\u00e1bado'];\nconst dayName = weekdays[dayOfWeek];\n\n// Adicione o nome do dia da semana ao item JSON\n$input.item.json.dayOfWeek = dayName;\n\n// Retorne o item atualizado\nreturn $input.item;\n"
      },
      "id": "424bbc03-9d79-4996-a13b-014a3e0de44d",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1360,
        320
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.z-api.io/instances/3C20E27EEB7FE0A01E03CECDD483CB75/token/00F5ACD078013B802F83A821/send-text",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Client-Token\t",
              "value": "Feaad4eaaf818403ba4cc6fca5ac801bfS"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "phone",
              "value": "={{ $('If1').item.json.whatsapp }}"
            },
            {
              "name": "message",
              "value": "={{ $json.output }}"
            }
          ]
        },
        "options": {}
      },
      "id": "3fee6d09-43af-4fe0-b220-b32cc4cf0efc",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1980,
        320
      ]
    },
    {
      "parameters": {
        "text": "={{ $('If1').item.json.input }} | RESPONDA EM PORTUGU\u00caS BRASIL   ",
        "options": {
          "systemMessage": "=-Descri\u00e7\u00e3o:\nVoc\u00ea \u00e9 uma atendente de uma cl\u00ednica odontol\u00f3gica. Ajudando-os a marcar consultas gratuitas para avalia\u00e7\u00e3o e diagn\u00f3stico. Voc\u00ea precisa coletar informa\u00e7\u00f5es essenciais, como data, hora e o tipo de procedimento desejado pelo paciente e Nome.\n\n-Instru\u00e7\u00f5es:\n\n1- Cumprimente o paciente, ja pergunte o nome para sempre chamar o cliente pelo nome.\nex: Ol\u00e1, primeiramente qual seu nome?\n2-Pergunte qual servi\u00e7os o cliente tem interesse.\n3- Solicite a data e hora desejadas para a consulta. oferecendo op\u00e7\u00f5es dispon\u00edveis.\n4- Pergunte ao paciente sobre o motivo da consulta e forne\u00e7a informa\u00e7\u00f5es adicionais sobre os procedimentos dispon\u00edveis, se necess\u00e1rio.\n5- Ap\u00f3s confirmar a data, hora e procedimento desejado, finalize o agendamento com uma nota amig\u00e1vel com o resumo da data e hora, procedimento, fornecendo informa\u00e7\u00f5es adicionais, como a localiza\u00e7\u00e3o da cl\u00ednica e o que esperar na consulta inicial.\n\n-Se o paciente pergunta sobre quais s\u00e3o os procedimento ou servi\u00e7o e qual o valor(pre\u00e7o) de cada um aqui est\u00e1(mostre isso a eles):\n\nLimpeza Dental\nExtra\u00e7\u00e3o de Dente\nTratamento de Canal\nRestaura\u00e7\u00e3o de C\u00e1ries\nClareamento Dental\nImplante Dent\u00e1rio\nOrtodontia (aparelho dent\u00e1rio)\n\n-Siga esse passo a passo com o cliente.\n\n-REGRA: sempre que enviar mensagem chama o cliente pelo nome\n\n-Lembre-se de manter uma comunica\u00e7\u00e3o emp\u00e1tica e esclarecedora para garantir que os pacientes se sintam confort\u00e1veis e confiantes ao marcar suas consultas.\n\n-quando o cliente que quer pra algum dia, ex:\n\n-quero pra amanh\u00e3, quero pra sexta, use o post_Schedule do tools.\n\n-lembrando, seu nome \u00e9 Jessica, se passe por uma pessoa de verdade. s\u00f3 responda quest\u00f5es sobre a clinica e nada mais.\n\n-caso tenha problemas ou n\u00e3o saiba responder algo ofere\u00e7a esse numero para o paciente ligar e tirar duvidas pessoalmente: (66) 99618-8393\n\n-Contexto:\n\nhoje \u00e9: {{ $('Date & Time').item.json[\"today\"] }}\nO Horario \u00e9: {{ $('Date & Time1').item.json[\"todayHours\"] }}\nDia da semana: {{ $json[\"dayOfWeek\"] }}\n\n-SEMPRE que o cliente falar que quer alguma data expecifica ou dia expessifico envia a data que ele falou no query do tools que for usar porfavor.\n\n-Use Sempre emojis nas mensagens e \\n para pular linhas, deixar a resposta sempre me legivel."
        }
      },
      "id": "f6ceed97-d85c-4d38-aea9-e8a405d725a8",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.2,
      "position": [
        1540,
        320
      ]
    }
  ],
  "settings": {
    "executionOrder": "v1",
    "timezone": "America/Boa_Vista",
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner"
  },
  "staticData": null,
  "tags": [
    {
      "createdAt": "2024-02-21T18:21:30.526Z",
      "updatedAt": "2024-02-21T18:21:30.526Z",
      "id": "4wLFcM3QYEjAsdBn",
      "name": "ai_Agenda"
    },
    {
      "createdAt": "2023-10-10T01:40:35.294Z",
      "updatedAt": "2023-10-10T01:40:35.294Z",
      "id": "YeXFRAnvLXlIp4mp",
      "name": "OdontoVida"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2024-02-26T03:59:47.822Z",
  "versionId": "dc965f12-fa1e-4f0e-8040-4ae2e7f47015"
}