{
  "name": "Agente AI Direct Instagram",
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "d1770d24-931f-4262-8438-db21aae3664c",
              "name": "meuid",
              "value": "={{ $json.body.entry[0].id }}",
              "type": "string"
            },
            {
              "id": "fb434719-13e2-4250-87a2-0d48f8abd45f",
              "name": "senderid",
              "value": "={{ $json.body.entry[0].messaging[0].sender.id }}",
              "type": "string"
            },
            {
              "id": "a9011b07-7fd9-4f4a-93b7-4f5ef916007f",
              "name": "recipientid",
              "value": "={{ $json.body.entry[0].messaging[0].recipient.id }}",
              "type": "string"
            },
            {
              "id": "3ba472ac-ffe3-40dc-b064-2afd0c9552b1",
              "name": "messageid",
              "value": "={{ $json.body.entry[0].messaging[0].message.mid }}",
              "type": "string"
            },
            {
              "id": "67c9ce6d-c8c4-4e99-8177-0d61efa74b8f",
              "name": "message",
              "value": "={{ $json.body.entry[0].messaging[0].message.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "db0c9342-c7af-41c4-8781-a40a3bd2cd6f",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        320,
        200
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "09b4b0ca-ad68-4183-9475-341d43eb3d07",
              "leftValue": "={{ $json.senderid }}",
              "rightValue": "={{ $json.meuid }}",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "bdd42115-7a09-4185-9823-dfdea4b7747a",
      "name": "Filter",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        520,
        200
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "7c9b24a6-93df-4fef-8b00-51e082c82287",
      "name": "Groq Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "typeVersion": 1,
      "position": [
        720,
        420
      ],
      "credentials": {
        "groqApi": {
          "id": "eBOZ4U7URIEz51EZ",
          "name": "Groq account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.instagram.com/v21.0/17841445787622448/messages",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer IGQWRPMFppVEZAvZA3YzZAjJZAdnVPX3JzeFhTRmtiemUweGhLY05ZAOENER2lUcWVDR0dyU0pueURKaGprQkhEVW1zWjRLbFlVNmF0SlJsbGlYZA1NtNTRXMXFQSnhYUHgyZAnlHWVNucW9uX3hDRnJRMDlkZAHNKMDBKN1EZD"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "recipient.id",
              "value": "={{ $('Filter').item.json.senderid }}"
            },
            {
              "name": "message.text",
              "value": "={{ $json.output }}"
            }
          ]
        },
        "options": {}
      },
      "id": "60d75759-fc4a-42ee-abe5-70ba291b0f89",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1040,
        200
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "You are a helpful assistant, responda até 500 caracteres."
        }
      },
      "id": "0adbb81a-e5a8-421b-9305-91cdf2161747",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        720,
        200
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "instagram",
        "options": {}
      },
      "id": "e19b77bb-b1fe-474a-9a17-ad3f2f019bf4",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        100,
        200
      ],
      "webhookId": "9a26ef9c-daef-4a03-93cd-7f8610e700e6"
    }
  ],
  "pinData": {
    "Webhook": [
      {
        "json": {
          "headers": {
            "host": "mywebhook.mywebagencia.com.br",
            "user-agent": "facebookexternalua",
            "content-length": "1069",
            "accept": "*/*",
            "accept-encoding": "deflate, gzip",
            "content-type": "application/json",
            "instagram-api-version": "v21.0",
            "x-forwarded-for": "173.252.95.3",
            "x-forwarded-host": "mywebhook.mywebagencia.com.br",
            "x-forwarded-port": "443",
            "x-forwarded-proto": "https",
            "x-forwarded-server": "0b8c87f7af73",
            "x-hub-signature": "sha1=29040df6f12500b3c877d5981947d8694371b47d",
            "x-hub-signature-256": "sha256=a9c30a9d03277b1bb22771c3b771f7f2703e01de161699eaf1894740492c9a4c",
            "x-real-ip": "173.252.95.3"
          },
          "params": {},
          "query": {},
          "body": {
            "object": "instagram",
            "entry": [
              {
                "time": 1732217870370,
                "id": "17841445787622448",
                "messaging": [
                  {
                    "sender": {
                      "id": "17841445787622448"
                    },
                    "recipient": {
                      "id": "6395444230476471"
                    },
                    "timestamp": 1732217870207,
                    "message": {
                      "mid": "aWdfZAG1faXRlbToxOklHTWVzc2FnZAUlEOjE3ODQxNDQ1Nzg3NjIyNDQ4OjM0MDI4MjM2Njg0MTcxMDMwMTI0NDI1ODcyMDAzMzQ0MDY0MTc2ODozMTk1Mzc3OTczMTYyMzQxMDA0NTE1MTAyNDg4NDIxOTkwNAZDZD",
                      "text": "A Patagônia é uma região geográfica localizada no sul da América do Sul, que abrange uma área de mais de 2 milhões de km². Está dividida entre dois países:\n\n* A Patagônia argentina, que é uma província da Argentina, localizada no sul do país.\n* A Patagônia chilena, que é uma região do Chile, localizada no sul e oeste do país.\n\nA Patagônia é caracterizada por suas paisagens naturais únicas, incluindo penínsulas, fiordes, glaciares e montanhas. É também uma região rica em recursos naturais, como madeira, minerais e petróleo.",
                      "is_echo": true
                    }
                  }
                ]
              }
            ]
          },
          "webhookUrl": "https://mywebhook.mywebagencia.com.br/webhook/instagram",
          "executionMode": "production"
        }
      }
    ]
  },
  "connections": {
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7759370b-5db7-43fd-a308-6125b6b22d75",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "442495cea8a57bd70857f3db797d80d9e6ac88a3eb23a4f48f1d184aca572e09"
  },
  "id": "Xhk3CqqIgAuG9L6r",
  "tags": []
}