{
  "createdAt": "2025-02-07T01:25:28.896Z",
  "updatedAt": "2025-06-04T01:15:04.442Z",
  "id": "1011",
  "name": "QuepasaAutomatic",
  "active": true,
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"contacts\" (\"name\", \"identifier\", \"account_id\", \"created_at\", \"updated_at\", \"last_activity_at\") VALUES ('{{ $(\"EXECDATA\").item.json.bottitle }}', '{{ $(\"EXECDATA\").item.json.contact }}', {{ $json.account }}, NOW(), NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "14ea38aa-9955-4737-bc13-693c559fe6ea",
      "name": "Cria o Contato",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        160
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"automation_rules\" (\"account_id\", \"name\", \"description\", \"event_name\", \"conditions\", \"actions\", \"created_at\", \"updated_at\", \"active\") VALUES ({{$json.account }}, '{{ $(\"EXECDATA\").item.json.bottitle }}', '{{ $(\"EXECDATA\").item.json.bottitle }}', 'message_created', '[{\"values\": [\"{{ $(\"EXECDATA\").item.json.contact }}\"], \"attribute_key\": \"identifier\", \"query_operator\": \"and\", \"filter_operator\": \"equal_to\", \"custom_attribute_type\": \"\"}, {\"values\": [\"outgoing\"], \"attribute_key\": \"message_type\", \"query_operator\": \"and\", \"filter_operator\": \"equal_to\", \"custom_attribute_type\": \"\"}, {\"values\": [\"/qrcode\",\"/paircode\",\"/login\"], \"attribute_key\": \"content\", \"filter_operator\": \"contains\", \"custom_attribute_type\": \"\"}]', '[{\"action_name\": \"send_webhook_event\", \"action_params\": [\"{{ $(\"EXECDATA\").item.json.n8nurl }}/webhook/quepasa\"]}]', NOW(), NOW(), 'true');",
        "additionalFields": {}
      },
      "id": "6688e1d4-4562-4b9d-93a3-de62199bccc8",
      "name": "Cria Automa\u00e7\u00e3o",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        460,
        0
      ],
      "alwaysOutputData": false,
      "notesInFlow": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" LEFT JOIN \"automation_rules\" ON \"accounts\".\"id\" = \"automation_rules\".\"account_id\" AND \"automation_rules\".\"name\" = '{{ $('EXECDATA').item.json.bottitle }}' WHERE \"automation_rules\".\"name\" IS NULL;",
        "additionalFields": {}
      },
      "id": "af616edf-5e3c-488c-bff4-3ae7b1952469",
      "name": "Missing Automations",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        -20
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" LEFT JOIN \"contacts\" ON \"accounts\".\"id\" = \"contacts\".\"account_id\" AND \"contacts\".\"identifier\" = '{{ $(\"EXECDATA\").item.json.contact }}' WHERE \"contacts\".\"identifier\" IS NULL;",
        "additionalFields": {}
      },
      "id": "f9c523f3-ab25-4ff8-af17-b3f9782c61a2",
      "name": "Missing Quepasa Contact",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        160
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"custom_attribute_definitions\" WHERE \"account_id\" = \"accounts\".\"id\" AND \"attribute_key\" = 'skipgreetings' AND \"attribute_model\" = 1);",
        "additionalFields": {}
      },
      "id": "1ca9aab5-8c42-4b21-a3d4-4663a045f5b6",
      "name": "Missing Greetings For Contact",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        1120
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"custom_attribute_definitions\" (\"attribute_display_name\", \"attribute_key\", \"attribute_display_type\", \"attribute_model\", \"account_id\", \"attribute_description\", \"attribute_values\", \"updated_at\", \"created_at\") VALUES ('Skip Greetings', 'skipgreetings', 7, 1, {{ $json.account }}, 'N\u00e3o utilizar a sauda\u00e7\u00e3o programada para este contato', '[]', NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "0c6618b6-f25d-43a8-90a3-8624ee48c05e",
      "name": "Insert Skip Greetings Attribute",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        1120
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "id": "3ab76b33-2f55-4baa-a849-6799904ed9c7",
      "name": "Schedule Daily",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        -1280,
        1120
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"custom_attribute_definitions\" WHERE \"account_id\" = \"accounts\".\"id\" AND \"attribute_key\" = 'skipevaluation' AND \"attribute_model\" = 1);",
        "additionalFields": {}
      },
      "id": "4bd46ca5-af74-425d-a6ff-3b75c060dd9a",
      "name": "Missing Evaluation For Contact",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        1320
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"custom_attribute_definitions\" (\"attribute_display_name\", \"attribute_key\", \"attribute_display_type\", \"attribute_model\", \"account_id\", \"attribute_description\", \"attribute_values\", \"updated_at\", \"created_at\") VALUES ('Skip Evaluation', 'skipevaluation', 7, 1, {{ $json.account }}, 'N\u00e3o utilizar sistema de avalia\u00e7\u00e3o ou protocolo para este contato !', '[]', NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "587ac412-99ad-45f9-93de-1827c5058f11",
      "name": "Insert Skip Evaluation For Contact Attribute",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        1320
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "content": "## (1.0.11) Updates\n* skip automation, to avoid typebot",
        "width": 425.48157586978226
      },
      "id": "3dfb6245-0627-4e26-9348-1bd84748c2af",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1340,
        720
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"custom_attribute_definitions\" (\"attribute_display_name\", \"attribute_key\", \"attribute_display_type\", \"attribute_model\", \"account_id\", \"attribute_description\", \"attribute_values\", \"updated_at\", \"created_at\") VALUES ('Skip Agent Title', 'skipagenttitle', 7, 1, {{ $json.account }}, 'N\u00e3o incluir o titulo do agente antes da mensagem para este contato', '[]', NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "dd0d518e-270d-4593-9a9d-8f86e88aaa79",
      "name": "Insert Skip Agent Title Attribute",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        920
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"custom_attribute_definitions\" WHERE \"account_id\" = \"accounts\".\"id\" AND \"attribute_key\" = 'skipagenttitle' AND \"attribute_model\" = 1);",
        "additionalFields": {}
      },
      "id": "638cba04-d3a3-49dd-a87a-6e65c114a591",
      "name": "Missing Agent Title For Contact",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        920
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "fieldToSplitOut": "={{ $json }}",
        "options": {}
      },
      "id": "0b70dcb7-4aa0-4a6d-9674-7b528713a84b",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        280,
        -100
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "08fabf93-0038-48cb-abf2-013a924db497",
              "leftValue": "={{ $json instanceof JSONArray }}",
              "rightValue": "=",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "cafc4385-327c-44ea-8c04-e9e688b7deeb",
      "name": "If Array",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        80,
        -20
      ]
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "tableName": {
          "__rl": true,
          "value": "accounts",
          "mode": "list",
          "cachedResultName": "accounts"
        },
        "additionalFields": {},
        "options": {}
      },
      "id": "4a8d35c5-8381-4a53-afb0-de340e8aca66",
      "name": "Postgres Trigger",
      "type": "n8n-nodes-base.postgresTrigger",
      "typeVersion": 1,
      "position": [
        -1280,
        920
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "tableName": {
          "__rl": true,
          "value": "channel_api",
          "mode": "list",
          "cachedResultName": "channel_api"
        },
        "firesOn": "DELETE",
        "additionalFields": {},
        "options": {}
      },
      "id": "f354b585-155b-476e-a301-e9e291da6757",
      "name": "When API Inbox Deleted",
      "type": "n8n-nodes-base.postgresTrigger",
      "typeVersion": 1,
      "position": [
        -1200,
        3280
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "={{ $json.extra.qphost }}/info",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-QUEPASA-TOKEN",
              "value": "={{ $json.payload.identifier }}"
            }
          ]
        },
        "options": {}
      },
      "id": "1332c031-4a9b-43d5-825c-c7b6ada09f50",
      "name": "Delete Quepasa Inbox If Exists",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        -280,
        3300
      ],
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "workflowId": "={{ $env['C8Q_CHATWOOTEXTRA'] ?? \"iiEsUj7ybtzEZAFj\" }}",
        "options": {}
      },
      "id": "328ba4bb-b22c-4ff3-8ce5-6ed09b983d85",
      "name": "Execute ChatWootExtra Workflow",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1,
      "position": [
        -720,
        3360
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "multiplex",
        "options": {}
      },
      "id": "564c4b8a-05e7-4d6a-8194-06991bbd73c2",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        -540,
        3300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9890dc5d-f10d-41fd-9d0f-35db8d2c6cb2",
              "name": "event",
              "value": "api_inbox_delete",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "b3e11512-4caf-46c9-a67c-7ec323eede4a",
      "name": "Set Event Name",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        -900,
        3280
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"custom_attribute_definitions\" WHERE \"account_id\" = \"accounts\".\"id\" AND \"attribute_key\" = 'skipcontact' AND \"attribute_model\" = 1);",
        "additionalFields": {}
      },
      "id": "b8c9eba0-6e93-49f3-b269-35c77c77c4a8",
      "name": "Missing Skip For Contact",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        1520
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"custom_attribute_definitions\" (\"attribute_display_name\", \"attribute_key\", \"attribute_display_type\", \"attribute_model\", \"account_id\", \"attribute_description\", \"attribute_values\", \"updated_at\", \"created_at\") VALUES ('Skip Contact', 'skipcontact', 7, 1, {{ $json.account }}, 'N\u00e3o utilizar este contato ! Ignora a cria\u00e7\u00e3o de novas conversas.', '[]', NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "9f8b74bb-be62-40d1-9f05-9661e1f930a2",
      "name": "Insert Skip For Contact",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        1520
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"custom_attribute_definitions\" (\"attribute_display_name\", \"attribute_key\", \"attribute_display_type\", \"attribute_model\", \"account_id\", \"attribute_description\", \"attribute_values\", \"updated_at\", \"created_at\") VALUES ('Skip Evaluation', 'skipevaluation', 7, 0, {{ $json.account }}, 'N\u00e3o utilizar sistema de avalia\u00e7\u00e3o ou protocolo para esta conversa !', '[]', NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "0c2436a3-0c4b-4f4b-9216-d82abf800476",
      "name": "Insert Skip Evaluation For Conversation Attribute",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        2360
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"custom_attribute_definitions\" WHERE \"account_id\" = \"accounts\".\"id\" AND \"attribute_key\" = 'skipevaluation' AND \"attribute_model\" = 0);",
        "additionalFields": {}
      },
      "id": "f2b4f62f-f354-4ed7-aba7-ffd749b84719",
      "name": "Missing Evaluation For Conversation",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        2360
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"custom_attribute_definitions\" WHERE \"account_id\" = \"accounts\".\"id\" AND \"attribute_key\" = 'skipaudiotranscript' AND \"attribute_model\" = 1);",
        "additionalFields": {}
      },
      "id": "d43562e1-5697-45ff-8ffd-023508aeb999",
      "name": "Missing Audio Transcript For Contact",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        1720
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"custom_attribute_definitions\" (\"attribute_display_name\", \"attribute_key\", \"attribute_display_type\", \"attribute_model\", \"account_id\", \"attribute_description\", \"attribute_values\", \"updated_at\", \"created_at\") VALUES ('Skip Audio Transcript', 'skipaudiotranscript', 7, 1, {{ $json.account }}, 'N\u00e3o utilizar sistema de transcri\u00e7\u00e3o de \u00e1udio para este contato !', '[]', NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "c586c06e-48fb-40d2-913a-5bc8b7ae7483",
      "name": "Insert Skip Audio Transcript For Contact Attribute",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        1720
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"custom_attribute_definitions\" (\"attribute_display_name\", \"attribute_key\", \"attribute_display_type\", \"attribute_model\", \"account_id\", \"attribute_description\", \"attribute_values\", \"updated_at\", \"created_at\") VALUES ('TypeBot Session Id', 'typebot_session', 0, 0, {{ $json.account }}, 'TypeBot session id, used for logs', '[]', NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "6a4ef857-5b45-4927-ba42-e745143ebbd7",
      "name": "Insert TypeBot Session Id For Conversation",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        2560
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"custom_attribute_definitions\" WHERE \"account_id\" = \"accounts\".\"id\" AND \"attribute_key\" = 'typebot_session' AND \"attribute_model\" = 0);",
        "additionalFields": {}
      },
      "id": "5d849e98-c298-4662-8dbb-76019e503a6f",
      "name": "Missing TypeBot Session Id For Conversation",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        2560
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"account_users\" WHERE \"user_id\" = {{ $('EXECDATA').item.json.superuser_id }} AND \"account_id\" = \"accounts\".\"id\");",
        "additionalFields": {}
      },
      "id": "0d549f80-b1ee-422f-914c-1a473ac2904a",
      "name": "Missing Super User",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        360
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "n8nurl",
              "value": "={{ ($env[\"C8Q_N8N_HOST\"] ?? $env[\"WEBHOOK_URL\"] ?? \"http://127.0.0.1:5678\").replace(/\\&+$/, '')\u00a0}}"
            },
            {
              "name": "bottitle",
              "value": "={{ $env['C8Q_QP_BOTTITLE'] ?? 'Quepasa Control' }}"
            },
            {
              "name": "contact",
              "value": "={{ $env['C8Q_QP_CONTACT'] ?? 'control@quepasa.io' }}"
            },
            {
              "name": "superuser_name",
              "value": "={{ $env['C8Q_SUPERUSER_NAME'] ?? \"Super User Agent\" }}"
            }
          ],
          "number": [
            {
              "name": "=superuser_id",
              "value": "={{ $env['C8Q_SUPERUSER_ID'] ?? 1 }}"
            }
          ]
        },
        "options": {}
      },
      "id": "d0ba8934-672b-4e83-b398-cd35fa23681b",
      "name": "EXECDATA",
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [
        -1060,
        1020
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"account_users\" (\"account_id\", \"user_id\", \"role\", \"inviter_id\", \"availability\", \"auto_offline\", \"custom_role_id\", \"updated_at\", \"created_at\", \"active_at\") VALUES ({{ $json.account }}, {{ $('EXECDATA').item.json.superuser_id }}, 1, NULL, 0, true, NULL, NOW(), NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "bf5f94f5-c1ec-45b9-8174-c4e918a01afc",
      "name": "Insert Super User",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        360
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=UPDATE \"users\" SET \"name\" = '{{ $('EXECDATA').item.json.superuser_name }}' WHERE \"id\" = {{ $('EXECDATA').item.json.superuser_id }};",
        "additionalFields": {}
      },
      "id": "97a4e5e8-831f-4129-8e61-35801f7e36a9",
      "name": "Update Super User Name",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        540
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"custom_attribute_definitions\" WHERE \"account_id\" = \"accounts\".\"id\" AND \"attribute_key\" = 'typebot_status' AND \"attribute_model\" = 0);",
        "additionalFields": {}
      },
      "id": "8cfbee37-ad90-414e-a5f5-ddddba59028a",
      "name": "Missing TypeBot Session Status For Conversation",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        2760
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"custom_attribute_definitions\" (\"attribute_display_name\", \"attribute_key\", \"attribute_display_type\", \"attribute_model\", \"account_id\", \"attribute_description\", \"attribute_values\", \"updated_at\", \"created_at\") VALUES ('TypeBot Status', 'typebot_status', 0, 0, {{ $json.account }}, 'TypeBot session status', '[]', NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "53a8aa11-3b0e-40e2-8651-8e9a5971b581",
      "name": "Insert TypeBot Session Status For Conversation",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        2760
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {},
      "id": "d4970526-ece6-4833-817e-ab7ce3411f93",
      "name": "Contact Attributes",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -600,
        1240
      ]
    },
    {
      "parameters": {},
      "id": "490f1f84-ef0c-4929-b160-2321fd31ad4c",
      "name": "System",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -600,
        260
      ]
    },
    {
      "parameters": {},
      "id": "7e074596-9c94-4899-8897-3ca122bebe5d",
      "name": "Conversation Attributes",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -560,
        2560
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=SELECT DISTINCT \"accounts\".\"id\" AS \"account\" FROM \"accounts\" WHERE NOT EXISTS (SELECT NULL FROM \"custom_attribute_definitions\" WHERE \"account_id\" = \"accounts\".\"id\" AND \"attribute_key\" = 'skipautomation' AND \"attribute_model\" = 1);",
        "additionalFields": {}
      },
      "id": "a5fd8573-dd54-40ba-b3ba-99acae2c23ad",
      "name": "Missing Skip Automation Contact",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        -160,
        1920
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO \"custom_attribute_definitions\" (\"attribute_display_name\", \"attribute_key\", \"attribute_display_type\", \"attribute_model\", \"account_id\", \"attribute_description\", \"attribute_values\", \"updated_at\", \"created_at\") VALUES ('Skip Automation', 'skipautomation', 7, 1, {{ $json.account }}, 'N\u00e3o utilizar sistema de automa\u00e7\u00e3o de atendimento para este contato !', '[]', NOW(), NOW());",
        "additionalFields": {}
      },
      "id": "74d14c4d-5f5f-4c1b-8460-ed9f1a534a0e",
      "name": "Insert Skip Automation Contact Attribute",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        80,
        1920
      ],
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "notes": "Sucesso"
    }
  ],
  "connections": {
    "Missing Automations": {
      "main": [
        [
          {
            "node": "If Array",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing Quepasa Contact": {
      "main": [
        [
          {
            "node": "Cria o Contato",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing Greetings For Contact": {
      "main": [
        [
          {
            "node": "Insert Skip Greetings Attribute",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Daily": {
      "main": [
        [
          {
            "node": "EXECDATA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing Evaluation For Contact": {
      "main": [
        [
          {
            "node": "Insert Skip Evaluation For Contact Attribute",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing Agent Title For Contact": {
      "main": [
        [
          {
            "node": "Insert Skip Agent Title Attribute",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Cria Automa\u00e7\u00e3o",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Array": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Cria Automa\u00e7\u00e3o",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Trigger": {
      "main": [
        [
          {
            "node": "EXECDATA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When API Inbox Deleted": {
      "main": [
        [
          {
            "node": "Set Event Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute ChatWootExtra Workflow": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Delete Quepasa Inbox If Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Event Name": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "Execute ChatWootExtra Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing Skip For Contact": {
      "main": [
        [
          {
            "node": "Insert Skip For Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing Evaluation For Conversation": {
      "main": [
        [
          {
            "node": "Insert Skip Evaluation For Conversation Attribute",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing Audio Transcript For Contact": {
      "main": [
        [
          {
            "node": "Insert Skip Audio Transcript For Contact Attribute",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing TypeBot Session Id For Conversation": {
      "main": [
        [
          {
            "node": "Insert TypeBot Session Id For Conversation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "EXECDATA": {
      "main": [
        [
          {
            "node": "System",
            "type": "main",
            "index": 0
          },
          {
            "node": "Contact Attributes",
            "type": "main",
            "index": 0
          },
          {
            "node": "Conversation Attributes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing Super User": {
      "main": [
        [
          {
            "node": "Insert Super User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing TypeBot Session Status For Conversation": {
      "main": [
        [
          {
            "node": "Insert TypeBot Session Status For Conversation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Contact Attributes": {
      "main": [
        [
          {
            "node": "Missing Skip For Contact",
            "type": "main",
            "index": 0
          },
          {
            "node": "Missing Evaluation For Contact",
            "type": "main",
            "index": 0
          },
          {
            "node": "Missing Greetings For Contact",
            "type": "main",
            "index": 0
          },
          {
            "node": "Missing Agent Title For Contact",
            "type": "main",
            "index": 0
          },
          {
            "node": "Missing Audio Transcript For Contact",
            "type": "main",
            "index": 0
          },
          {
            "node": "Missing Skip Automation Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "System": {
      "main": [
        [
          {
            "node": "Missing Quepasa Contact",
            "type": "main",
            "index": 0
          },
          {
            "node": "Missing Automations",
            "type": "main",
            "index": 0
          },
          {
            "node": "Missing Super User",
            "type": "main",
            "index": 0
          },
          {
            "node": "Update Super User Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Attributes": {
      "main": [
        [
          {
            "node": "Missing Evaluation For Conversation",
            "type": "main",
            "index": 0
          },
          {
            "node": "Missing TypeBot Session Id For Conversation",
            "type": "main",
            "index": 0
          },
          {
            "node": "Missing TypeBot Session Status For Conversation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Missing Skip Automation Contact": {
      "main": [
        [
          {
            "node": "Insert Skip Automation Contact Attribute",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1"
  },
  "staticData": {
    "node:Schedule Daily": {
      "recurrenceRules": []
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "versionId": "ff03d710-a54b-4311-82b4-5798c515d1d2",
  "triggerCount": 3,
  "tags": [
    {
      "createdAt": "2022-10-13T15:26:11.519Z",
      "updatedAt": "2023-08-25T18:50:53.269Z",
      "id": "5",
      "name": "quepasa"
    },
    {
      "createdAt": "2023-05-18T18:59:53.449Z",
      "updatedAt": "2023-05-18T18:59:53.449Z",
      "id": "7",
      "name": "EngajamentoFlow"
    },
    {
      "createdAt": "2023-05-19T22:54:38.266Z",
      "updatedAt": "2023-05-19T22:54:38.266Z",
      "id": "13",
      "name": "github.com/nocodeleaks"
    }
  ],
  "versao-qp": "3.25.524.0013",
  "Workflow-Nome": "QuepasaAutomatic"
}