{
  "nodes": [
    {
      "parameters": {
        "updates": [
          "messages"
        ],
        "options": {}
      },
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        -960,
        208
      ],
      "id": "6a3a7d43-739d-4e2e-a729-6a70d4dd0d11",
      "name": "WhatsApp Trigger",
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.messages[0].text.body }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "id": "00aa1a12-64d0-4436-933c-dcc83a3a4eb8"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "text"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "53d5a502-e76d-4d51-85d4-c0dc54b25abd",
                    "leftValue": "={{ $json.messages[0].audio }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "voice"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "90fbc1ff-fa1c-491f-a0e0-82c7b2318ff4",
                    "leftValue": "={{ $json.messages[0].image }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "image"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "83ecda86-0247-4699-89c2-162922d93d09",
                    "leftValue": "",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -528,
        176
      ],
      "id": "e3d97ea6-61ea-4769-baac-b27d809d5350",
      "name": "Switch"
    },
    {
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].audio.id }}"
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        -224,
        288
      ],
      "id": "e7fc621a-cefa-42d4-936a-1ce32073ecf1",
      "name": "Download media",
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpBearerAuth",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -48,
        288
      ],
      "id": "e2dd26f1-ca46-43f3-9cfb-3e671c74ff13",
      "name": "HTTP Request",
      "retryOnFail": true,
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "1064834993383405",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}",
        "textBody": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        1088,
        144
      ],
      "id": "c81bc43c-aa01-4c06-b557-a251ce76df5d",
      "name": "Send message",
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/audio/transcriptions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": []
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "whisper-large-v3-turbo"
            },
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        144,
        288
      ],
      "id": "56b9db25-af4a-4672-958e-991df555d6cb",
      "name": "HTTP Request2",
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].image.id }}"
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        -240,
        560
      ],
      "id": "f075d669-262e-4d8d-88e8-9cf129c60527",
      "name": "Download media1",
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpBearerAuth",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -32,
        560
      ],
      "id": "0d7c1988-6435-4600-842b-6582728eb5f0",
      "name": "HTTP Request4",
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "image",
        "operation": "analyze",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4O-MINI"
        },
        "text": "=Describe what is in this image in detail. Reply in Arabic.\n\nThe user also asked: {{ $('WhatsApp Trigger').item.json.messages[0].image.caption || 'No specific question provided.' }}",
        "inputType": "base64",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        160,
        560
      ],
      "id": "62301a61-52f2-4c7c-bdae-5e61057ff4c3",
      "name": "Analyze image",
      "credentials": {}
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e5e8f375-25a1-465c-a357-a5e3965c1eff",
              "name": "message",
              "value": "={{ $json.messages[0].text.body }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        96,
        0
      ],
      "id": "06dbbb49-416c-4f21-b517-d5b5677081f1",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e5e8f375-25a1-465c-a357-a5e3965c1eff",
              "name": "message",
              "value": "={{ $json.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        368,
        288
      ],
      "id": "7d4cb7b4-cdaa-4683-94d0-de564a7b9ab5",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e5e8f375-25a1-465c-a357-a5e3965c1eff",
              "name": "message",
              "value": "={{ $json['0'].content[0].text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        416,
        560
      ],
      "id": "8c0596bb-edc6-4bf7-b909-44d442aa78bf",
      "name": "Edit Fields2"
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "use this tool  to check the email of any person if you need to know  the email of him before sending the email",
        "documentId": {
          "__rl": true,
          "value": "1-6H0qZtnDMauZB0R6h9H82K6sAxEHq_o8wRvm0XiVak",
          "mode": "list",
          "cachedResultName": "Contacts",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-6H0qZtnDMauZB0R6h9H82K6sAxEHq_o8wRvm0XiVak/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 1344258259,
          "mode": "list",
          "cachedResultName": "Contacts",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-6H0qZtnDMauZB0R6h9H82K6sAxEHq_o8wRvm0XiVak/edit#gid=1344258259"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        992,
        512
      ],
      "id": "84854a2a-b28f-4df9-b29b-eda3df93ddaa",
      "name": "Get row(s) in sheet in Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "=You are a fast-acting WhatsApp AI Assistant.\nYou respond in the same language the user writes in.\n\n## CORE RULE \u2014 ACT FIRST, NEVER ASK PERMISSION\nYou MUST take action immediately without asking the user if they want you to do something.\nIf the user asks you to search \u2192 search immediately.\nIf the user asks you to send an email \u2192 find the contact from googlw sheets and send immediately by Gmail.\nIf the user asks about a price \u2192 search immediately without asking.\nNEVER say \"\u0647\u0644 \u062a\u0631\u064a\u062f \u0623\u0646 \u0623\u0628\u062d\u062b\u061f\" or \"\u0647\u0644 \u062a\u0648\u062f \u0627\u0644\u0645\u062a\u0627\u0628\u0639\u0629\u061f\" or any similar phrase.\nNEVER ask for confirmation before using a tool.\n\n## YOUR TOOLS\n\n### 1. SerpAPI Search Tool\n- Use this tool AUTOMATICALLY and IMMEDIATELY whenever:\n  \u2022 User asks about prices (\u0623\u0633\u0639\u0627\u0631\u060c \u0633\u0639\u0631\u060c \u0628\u0643\u0627\u0645\u060c how much)\n  \u2022 User asks about current news or recent events in the last 7 days\n  \u2022 User asks about product specs or comparisons\n  \u2022 User asks any question needing up-to-date information\n- DO NOT ask the user if they want you to search \u2014 just search.\n- DO NOT say \"\u064a\u0645\u0643\u0646\u0646\u064a \u0645\u0633\u0627\u0639\u062f\u062a\u0643 \u0641\u064a \u0627\u0644\u0628\u062d\u062b\" \u2014 just do it.\n- Search query must be specific: include product name + country + current year.\n\n### 2. Google Sheets Tool\n- Use this to look up email addresses before sending any email.\n- Search by the person's name mentioned by the user.\n- If not found \u2192 tell the user the contact was not found and ask for their email.\n\n### 3. Gmail Tool\n- Use this to send emails on behalf of the user.\n- Always look up the email in Google Sheets first.\n- Send the email immediately after finding the contact \u2014 do not ask for confirmation.\n\n### 4. Image Analysis\n- When the user sends an image, you receive a detailed description of it.\n- The description is prefixed with [\u062a\u062d\u0644\u064a\u0644 \u0627\u0644\u0635\u0648\u0631\u0629].\n- Use this description to answer any question about the image.\n- If the user also asks about a price or specs of what is in the image \u2192 search immediately using SerpAPI.\n\n## BEHAVIOR RULES\n- Reply in the same language the user uses (Arabic \u2192 Arabic, English \u2192 English).\n- Be concise and direct \u2014 no unnecessary filler phrases.\n- Never make up email addresses.\n- Never ask \"\u0647\u0644 \u062a\u0631\u064a\u062f\u061f\" or \"\u0647\u0644 \u062a\u0648\u062f\u061f\" \u2014 just execute.\n- If a task requires multiple steps (find email \u2192 send) \u2192 do all steps automatically.\n\n## EXAMPLES OF CORRECT BEHAVIOR\nUser: \"\u0627\u0628\u062d\u062b \u0639\u0646 \u0633\u0639\u0631 iPhone 16 \u0641\u064a \u0645\u0635\u0631\"\n\u2705 Correct: [searches immediately and returns results]\n\u274c Wrong: \"\u0647\u0644 \u062a\u0631\u064a\u062f \u0645\u0646\u064a \u0627\u0644\u0628\u062d\u062b \u0639\u0646 \u0633\u0639\u0631 iPhone 16\u061f\"\n\nUser: \"\u0625\u064a\u0647 \u0627\u0644\u0644\u064a \u0641\u064a \u0627\u0644\u0635\u0648\u0631\u0629 \u0648\u0643\u0627\u0645 \u0633\u0639\u0631\u0647 \u0641\u064a \u0645\u0635\u0631\u061f\"\n\u2705 Correct: [describes image then searches price immediately]\n\u274c Wrong: \"\u064a\u0645\u0643\u0646\u0646\u064a \u0645\u0633\u0627\u0639\u062f\u062a\u0643 \u0641\u064a \u0627\u0644\u0628\u062d\u062b\u060c \u0647\u0644 \u062a\u0648\u062f \u0627\u0644\u0645\u062a\u0627\u0628\u0639\u0629\u061f\"\n\nUser: \"\u0627\u0628\u0639\u062a \u0625\u064a\u0645\u064a\u0644 \u0644\u0623\u062d\u0645\u062f \u0639\u0646 \u0627\u0644\u0627\u062c\u062a\u0645\u0627\u0639\"\n\u2705 Correct: [looks up Ahmed in Sheets \u2192 sends email immediately]\n\u274c Wrong: \"\u0647\u0644 \u062a\u0631\u064a\u062f \u0645\u0646\u064a \u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0628\u0631\u064a\u062f \u0627\u0644\u0625\u0644\u0643\u062a\u0631\u0648\u0646\u064a\u061f\"\n\n_if there is an image here is the user question with it to answer it according to the image description:\n{{ $('WhatsApp Trigger').item.json.messages[0].image.caption }}",
          "maxIterations": 15
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        720,
        144
      ],
      "id": "fe7a3a5b-3d70-490c-9f26-d66ff494bb77",
      "name": "AI Agent1"
    },
    {
      "parameters": {
        "sendTo": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('To', ``, 'string') }}",
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', `use this tool to send messages`, 'string') }}",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.2,
      "position": [
        896,
        672
      ],
      "id": "aaeb9eb2-e527-462f-a61d-fb1bd63d1a6f",
      "name": "Send a message in Gmail",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Text\n",
        "height": 144
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "typeVersion": 1,
      "id": "6cd45584-458f-4bb2-9275-8a330c7d3747",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## voice",
        "height": 192,
        "width": 816
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        240
      ],
      "typeVersion": 1,
      "id": "4682f0b3-2cd7-4ed7-a398-130e968b74e2",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "  ##                                 Image\n",
        "height": 224,
        "width": 880
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        496
      ],
      "typeVersion": 1,
      "id": "eec2f22d-d2d8-40e2-b836-488481ad7ba9",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 3
          },
          "conditions": [
            {
              "id": "f0797766-4a37-4a2a-bc55-50d8909aff61",
              "leftValue": "={{ $json.messages[0].from }}",
              "rightValue": "={{ $vars.phone }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        -768,
        208
      ],
      "id": "18bbd332-1782-4637-8d02-cf96c3a8b6a7",
      "name": "If"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -672,
        400
      ],
      "id": "fc7b4256-d01b-4048-9ccd-4baf332c97bd",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.toolSerpApi",
      "typeVersion": 1,
      "position": [
        1152,
        416
      ],
      "id": "448f950f-6213-41dd-9b8e-b6199ef9bd88",
      "name": "SerpAPI",
      "credentials": {
        "serpApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        784,
        400
      ],
      "id": "167a2e38-6da5-4c5d-a092-0f36ec046d2f",
      "name": "Simple Memory1"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        656,
        640
      ],
      "id": "be3190e8-efca-4be3-9ced-c04bae1ca261",
      "name": "OpenAI Chat Model",
      "credentials": {}
    }
  ],
  "connections": {
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download media",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download media1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download media": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request2": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download media1": {
      "main": [
        [
          {
            "node": "HTTP Request4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request4": {
      "main": [
        [
          {
            "node": "Analyze image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze image": {
      "main": [
        [
          {
            "node": "Edit Fields2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields2": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message in Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SerpAPI": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory1": {
      "ai_memory": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}