{
  "name": "Keyword Search with Email Notifications",
  "nodes": [
    {
      "parameters": {
        "resource": "tender",
        "operation": "searchByKeyword",
        "keywords": "engenharia civil ponte infraestrutura",
        "startDate": "2025-01-01",
        "endDate": "2025-12-31",
        "returnAll": false,
        "limit": 50
      },
      "id": "keyword-search",
      "name": "Search Infrastructure Tenders",
      "type": "n8n-nodes-aec-tenders.aecTenders",
      "typeVersion": 1,
      "position": [
        300,
        200
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "high-value-filter",
              "leftValue": "={{ $json.estimatedTotalValue }}",
              "rightValue": 1000000,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            },
            {
              "id": "critical-urgency",
              "leftValue": "={{ $json._urgencyLevel }}",
              "rightValue": "critical",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "filter-high-value",
      "name": "Filter High-Value Critical Tenders",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2,
      "position": [
        500,
        200
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "format-notification",
              "name": "emailSubject",
              "value": "\ud83d\udea8 High-Value Infrastructure Tender Alert: {{ $json.procuringEntityName }}",
              "type": "string"
            },
            {
              "id": "format-body",
              "name": "emailBody",
              "value": "New high-value infrastructure tender found:\n\n\ud83d\udccb **Tender Details:**\n- Entity: {{ $json.procuringEntityName }}\n- Object: {{ $json.tenderObject }}\n- Value: R$ {{ $json.estimatedTotalValue.toLocaleString('pt-BR') }}\n- Category: {{ $json._category }}\n- Risk Score: {{ $json._riskScore }}/100\n- Urgency: {{ $json._urgencyLevel }}\n\n\ud83d\udcc5 **Important Dates:**\n- Publication: {{ $json.publicationDate }}\n- Proposal Opening: {{ $json.proposalOpeningDate }}\n\n\ud83d\udd17 **Portal Link:** {{ $json.portalUrl }}\n\n---\nGenerated by n8n AEC Tenders Node",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "format-notification",
      "name": "Format Email Notification",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        700,
        200
      ]
    },
    {
      "parameters": {
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "nodeCredentialType": "gmailOAuth2Api",
        "requestMethod": "POST",
        "url": "https://gmail.googleapis.com/gmail/v1/users/me/messages/send",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "raw",
              "value": "={{ $json.emailSubject + '\\n\\n' + $json.emailBody }}"
            }
          ]
        },
        "options": {}
      },
      "id": "send-email-alert",
      "name": "Send Email Alert",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        200
      ],
      "credentials": {
        "gmailOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "create",
        "table": "tender_alerts",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "pncp_id": "={{ $json.pncpId }}",
            "entity_name": "={{ $json.procuringEntityName }}",
            "tender_object": "={{ $json.tenderObject }}",
            "estimated_value": "={{ $json.estimatedTotalValue }}",
            "category": "={{ $json._category }}",
            "risk_score": "={{ $json._riskScore }}",
            "urgency_level": "={{ $json._urgencyLevel }}",
            "portal_url": "={{ $json.portalUrl }}",
            "publication_date": "={{ $json.publicationDate }}",
            "proposal_opening_date": "={{ $json.proposalOpeningDate }}",
            "alert_sent_at": "={{ new Date().toISOString() }}"
          }
        },
        "options": {}
      },
      "id": "log-to-database",
      "name": "Log to Database",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.4,
      "position": [
        700,
        400
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Search Infrastructure Tenders": {
      "main": [
        [
          {
            "node": "Filter High-Value Critical Tenders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter High-Value Critical Tenders": {
      "main": [
        [
          {
            "node": "Format Email Notification",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log to Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Email Notification": {
      "main": [
        [
          {
            "node": "Send Email Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "example-v1.0.0",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "id": "keyword-search-with-notifications",
  "tags": [
    "aec",
    "tenders",
    "alerts",
    "email",
    "database",
    "monitoring"
  ]
}