{
  "id": "3UYpKpNGvAhavb0g",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "WhatsApp Fact-Checking Bot",
  "tags": [],
  "nodes": [
    {
      "id": "5a66e287-a2c6-48bc-ad4b-9812fdf0c19a",
      "name": "Receive Whatsapp Messages",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -384,
        -48
      ],
      "parameters": {
        "path": "whatsapp-inbound",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "a81de7f9-1bdc-40c8-8f51-2f13f70fe08e",
      "name": "Confirm news with Citations",
      "type": "n8n-nodes-base.perplexity",
      "position": [
        -48,
        -48
      ],
      "parameters": {
        "model": "sonar",
        "options": {},
        "messages": {
          "message": [
            {
              "role": "system",
              "content": "You are a cautious and objective AI fact-checker for a WhatsApp service. Your task is to verify the news or claim provided by the user.\n\n1. Analyze the user's query to understand the core claim being made.\n2. Perform a web search to find information from multiple reliable, neutral sources (like major news outlets, scientific journals, and fact-checking organizations).\n3. Based on the search results, provide a clear, one-phrase verdict at the very beginning of your response. Use one of the following: \"\u2705 Likely True\", \"\u274c Likely False\", \"\u26a0\ufe0f Misleading\", or \"\u2753 Unverified\".\n4. After the verdict, write a brief, neutral summary (2-3 sentences) explaining your findings in simple language suitable for a WhatsApp message.\n5. You MUST include citations for your key sources as provided by your search results. This is critical for user trust."
            },
            {
              "content": "={{ $json.body.Body }}"
            }
          ]
        },
        "simplify": true,
        "requestOptions": {}
      },
      "credentials": {
        "perplexityApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0f57741e-9a02-47b1-8908-147d7651e7bc",
      "name": "Send Summary to whatsapp",
      "type": "n8n-nodes-base.twilio",
      "position": [
        288,
        -48
      ],
      "parameters": {
        "to": "={{ $('Receive Whatsapp Messages').item.json.body.From.replace('whatsapp:', '')  }}",
        "from": "={{ $('Receive Whatsapp Messages').item.json.body.To.replace('whatsapp:', '') }}",
        "message": "={{$json.message}}\n\n---\n\n*Sources:*\n{{ $json.citations.map((url, index) => `[${index + 1}] ${url}`).join('\\n') }}",
        "options": {},
        "toWhatsapp": true
      },
      "credentials": {
        "twilioApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "eb925e9f-f154-4b84-8405-b5a0a9881930",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        -368
      ],
      "parameters": {
        "width": 320,
        "height": 512,
        "content": "\n### \ud83d\udcec **WhatsApp Gateway**\n\nThis node is our digital front door! It patiently listens for incoming WhatsApp messages from a user.\n\n* **Triggers on:** A new message.\n* **Outputs:** The user's message (`Body`) and their phone number (`From`)."
      },
      "typeVersion": 1
    },
    {
      "id": "cb07fac9-16cb-4be9-94c2-537623eb43a8",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "height": 512,
        "content": "### \ud83e\udd16 **The Digital Detective**\n\nThis is where the magic happens! We hand the user's question over to our AI detective. It follows strict instructions to scour the web for facts.\n\n* **Input:** The user's raw text from the webhook.\n* **Action:** Fact-checks the claim against reliable sources.\n* **Output:** A structured response with a verdict, a simple summary, and source citations."
      },
      "typeVersion": 1
    },
    {
      "id": "fa055749-49e5-452d-ab25-5aa6475a3f70",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        176,
        -368
      ],
      "parameters": {
        "color": 3,
        "width": 320,
        "height": 512,
        "content": "### \ud83d\udcf2 **WhatsApp Reply Service**\n\nMission complete! This node takes the carefully crafted answer from our AI detective and sends it directly back to the user.\n\n* **Input:** The AI's formatted verdict, summary, and citations.\n* **Action:** Delivers the final message to the original user via Twilio."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6e1e2210-99c2-422e-ade8-41bfc6645333",
  "connections": {
    "Receive Whatsapp Messages": {
      "main": [
        [
          {
            "node": "Confirm news with Citations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Confirm news with Citations": {
      "main": [
        [
          {
            "node": "Send Summary to whatsapp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}