AutomationFlowsAI & RAG › Find Aliexpress Affiliate Products via Telegram with Openai and Decodo

Find Aliexpress Affiliate Products via Telegram with Openai and Decodo

Byachiya @achiya on n8n.io

Build a Telegram bot that helps users find AliExpress products using natural language requests. The bot uses OpenAI to optimize search queries, Decodo to scrape product listings, and AI analysis to select the best options based on ratings, reviews, and price—then automatically…

Event trigger★★★★★ complexityAI-powered57 nodesTelegram TriggerOpenAITelegram@Decodo/N8N Nodes DecodoN8N Nodes Aliexpress AffiliateHTTP Request
AI & RAG Trigger: Event Nodes: 57 Complexity: ★★★★★ AI nodes: yes Added:
Find Aliexpress Affiliate Products via Telegram with Openai and Decodo — n8n workflow card showing Telegram Trigger, OpenAI, Telegram integration

This workflow corresponds to n8n.io template #12437 — we link there as the canonical source.

This workflow follows the HTTP Request → OpenAI recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "DAU5WFpBTz7nG32DbZg-n",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Find and share AliExpress affiliate products through Telegram",
  "tags": [],
  "nodes": [
    {
      "id": "7f079fe2-1137-4992-b14e-24330966e124",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1408,
        2304
      ],
      "parameters": {
        "updates": [
          "message",
          "callback_query"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7a8820af-a1dd-4502-8790-1a38e62ecb48",
      "name": "If2",
      "type": "n8n-nodes-base.if",
      "position": [
        288,
        1824
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c8246e95-f69d-41be-98d2-76249ef79ed2",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.result.status }}",
              "rightValue": "left"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "85cf82ed-c50d-45d6-89b4-aa6cebb7fead",
      "name": "If4",
      "type": "n8n-nodes-base.if",
      "position": [
        512,
        1728
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "14a0a153-4f9c-4928-9406-6c773f1d2c95",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.message.text }}",
              "rightValue": "\u05ea\u05de\u05e6\u05d0 \u05dc\u05d9"
            },
            {
              "id": "cdc7381c-24de-441f-8552-b357cd36db70",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.message.text }}",
              "rightValue": "\u05ea\u05d7\u05e4\u05e9 \u05dc\u05d9"
            },
            {
              "id": "048e53dc-bcba-476f-a650-93c27fa155ce",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.message.text }}",
              "rightValue": "\u05d7\u05e4\u05e9 \u05dc\u05d9"
            },
            {
              "id": "b0e935a4-0e71-4a1e-9a38-58e799172b9a",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.message.text }}",
              "rightValue": "\u05de\u05e6\u05d0 \u05dc\u05d9"
            },
            {
              "id": "a47a4cf9-3ffc-4445-87cd-604359ff6f94",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.message.text }}",
              "rightValue": "\u05ea\u05e9\u05dc\u05d7 \u05dc\u05d9"
            },
            {
              "id": "22cb197b-b0cf-45dc-a07b-63727181c85f",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.message.text }}",
              "rightValue": "\u05e9\u05dc\u05d7 \u05dc\u05d9"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0a32a3b9-0932-47cb-b0ca-61e44f4ee88f",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        2848,
        1552
      ],
      "parameters": {
        "jsCode": "const data = $input.all();\n// Check if there is at least one item with code 200\nconst hasSuccess = data.some(item => \n  item.json.aliexpress_affiliate_link_generate_response?.resp_result?.resp_code === 200\n);\nif (hasSuccess) {\n  return data;\n} else {\n  return [{ json: { result: 2 } }];\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "62406aad-2e3b-4932-8d34-f8700eb031a0",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -736,
        1920
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5.2",
          "cachedResultName": "GPT-5.2"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "={{ $json.message.text }}"
            },
            {
              "role": "system",
              "content": "=## **Role:**\nAutomatic moderator for groups - checks message content and prevents inappropriate content.\n\n---\n\n## **Objective:**\nIdentify requests or content related to actual illegal activity, sexual content, or links, and return a polite and clear rejection message.\n\n---\n\n## **Context & Assumptions:**\n- The context: WhatsApp/Telegram group\n- \"Illegal\" includes: drugs, real weapons, financial fraud, money laundering, incitement to violence, selling prescription drugs without a license\n- \"Sexual\" includes: pornography, sexual harassment, sharing inappropriate images, explicit sexual requests\n- \"Links\" includes: any URL (http://, https://, www., or URL of any kind)\n- **Looking for legitimate consumer products** (including imitations/fakes of brands) **Allowed** - This is a normal buying activity\n- Borderline content (e.g. light jokes) will **not** be considered problematic unless explicitly stated\n- Language: Hebrew\n\n---\n\n## **Input Format:**\n```\nUser message: [free text]\n```\n\n---\n\n## **Output Format:**\nIf the content is **correct:**\n```json\n{\n  \"status\": \"approved\",\n  \"message\": null\n}\n```\n\nIf the content is **problematic:**\n```json\n{\n  \"status\": \"rejected\",\n  \"reason\": \"[short reason]\",\n  \"message\": \"Your message is not appropriate for the group. We do not allow [topic]. Thank you for understanding.\"\n}\n```\n\n---\n\n## **Rules:**\n1. **Output language:** Hebrew only\n2. **Tone:** Polite, non-judgmental, but firm\n3. **It is forbidden:** to invent reasons, to label normal content as problematic (false positive), to extend transition beyond the need\n4. **Accuracy:** If there is any doubt \u2013 **Affirm** (a good lock from a bad engine)\n5. **No explanations beyond what is required** - a short and to the point message\n6. **Any link of any kind = automatic rejection**\n7. **Searching/buying consumer products (also imitations) = approved** - only actual criminal activity is rejected\n\n---\n\n## **Success Criteria:**\n\u2705 Accurate identification of real problematic content only  \n\u2705 Identification and blocking of each link  \n\u2705 **Legitimate product search confirmation** (including replica/fakes)  \n\u2705 A clear and polite message to the user  \n\u2705 There are no false positives (correct content is not rejected)  \n\u2705 The JSON output is correct and ready for use in n8n\n\n---\n\nOutput: {\"status\": \"approved\", \"message\": null}"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "3cbbfb07-44a8-4f9a-a6a8-c86dae9a12f1",
      "name": "Code in JavaScript1",
      "type": "n8n-nodes-base.code",
      "position": [
        -384,
        1920
      ],
      "parameters": {
        "jsCode": "// Extract the text from the structure\nconst rawText = $input.first().json.output[0].content[0].text;\n\n// Remove markdown and JSON compression\nconst cleanText = rawText.replace(/```json\\n?/g, '').replace(/```\\n?/g, '').trim();\nconst result = JSON.parse(cleanText);\n\n// return the result\nreturn result;"
      },
      "typeVersion": 2
    },
    {
      "id": "c9f1839f-b180-491a-9f51-26228bc95f80",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -960,
        2304
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "111deefc-310e-4300-8317-7f5432fe3ad3",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.callback_query.data }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "8011d518-88bb-433a-95ab-43573974da5e",
      "name": "If3",
      "type": "n8n-nodes-base.if",
      "position": [
        -160,
        2496
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c8246e95-f69d-41be-98d2-76249ef79ed2",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.result.status }}",
              "rightValue": "left"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d8fe0d8b-7ff0-4c77-a314-6e0c850d4a4d",
      "name": "If5",
      "type": "n8n-nodes-base.if",
      "position": [
        64,
        2400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "14a0a153-4f9c-4928-9406-6c773f1d2c95",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.message.reply_to_message.text }}",
              "rightValue": "\u05ea\u05de\u05e6\u05d0 \u05dc\u05d9"
            },
            {
              "id": "cdc7381c-24de-441f-8552-b357cd36db70",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.message.reply_to_message.text }}",
              "rightValue": "\u05ea\u05d7\u05e4\u05e9 \u05dc\u05d9"
            },
            {
              "id": "048e53dc-bcba-476f-a650-93c27fa155ce",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.message.reply_to_message.text }}",
              "rightValue": "\u05d7\u05e4\u05e9 \u05dc\u05d9"
            },
            {
              "id": "b0e935a4-0e71-4a1e-9a38-58e799172b9a",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.message.reply_to_message.text }}",
              "rightValue": "\u05de\u05e6\u05d0 \u05dc\u05d9"
            },
            {
              "id": "a47a4cf9-3ffc-4445-87cd-604359ff6f94",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.message.reply_to_message.text }}",
              "rightValue": "\u05ea\u05e9\u05dc\u05d7 \u05dc\u05d9"
            },
            {
              "id": "22cb197b-b0cf-45dc-a07b-63727181c85f",
              "operator": {
                "type": "string",
                "operation": "startsWith"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.callback_query.message.reply_to_message.text }}",
              "rightValue": "\u05e9\u05dc\u05d7 \u05dc\u05d9"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f4dbed57-121b-4463-a09b-0d83f03cd37a",
      "name": "Code in JavaScript2",
      "type": "n8n-nodes-base.code",
      "position": [
        2336,
        2016
      ],
      "parameters": {
        "jsCode": "const data = $input.all();\n// \u05d1\u05d3\u05d9\u05e7\u05d4 \u05d0\u05dd \u05d9\u05e9 \u05dc\u05e4\u05d7\u05d5\u05ea \u05d0\u05d9\u05d9\u05d8\u05dd \u05d0\u05d7\u05d3 \u05e2\u05dd \u05e7\u05d5\u05d3 200\nconst hasSuccess = data.some(item => \n  item.json.aliexpress_affiliate_link_generate_response?.resp_result?.resp_code === 200\n);\nif (hasSuccess) {\n  return data;\n} else {\n  return [{ json: { result: 2 } }];\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "d1e2148e-9ab9-4ffc-a3e5-bb467ef9945c",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        -160,
        2784
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "82046f73-87a9-4da1-8832-b0617aa4f573",
      "name": "Bot start filtering",
      "type": "n8n-nodes-base.filter",
      "position": [
        -1184,
        2304
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e6c0a529-58ad-4063-912f-1af3678a33b1",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.message.text }}",
              "rightValue": "/start"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "3f3c75e7-ad7a-4145-89e7-cf5916d81a8f",
      "name": "Only if the person who asked for more is the one who sent the original message",
      "type": "n8n-nodes-base.if",
      "position": [
        -672,
        2592
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "0362ba6f-f9a9-4959-832a-456c0b4ae8f1",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "leftValue": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"reply_to_message\"][\"from\"][\"id\"] }}",
              "rightValue": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"from\"][\"id\"] }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "c7376207-9f53-45ef-9edd-2a2740a47d02",
      "name": "Checking if we are in a certain group ",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -384,
        2496
      ],
      "parameters": {
        "chatId": "@your group",
        "userId": "={{ $('Telegram Trigger').item.json.callback_query.from.id }}",
        "resource": "chat",
        "operation": "member"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "75ccd5b9-417c-421b-88d5-7be5cd1b5ca5",
      "name": "A message that only those who sent an original message can request more",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -384,
        2784
      ],
      "parameters": {
        "text": "=Only the person who sent the original message can click this button \ud83d\udd12\n\nSubmit your own message to search for products!  \ud83d\ude0a",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"chat\"][\"id\"] }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('Telegram Trigger').item.json.callback_query.message.reply_to_message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "37a48993-9c0e-4095-84b6-3c36cf219a07",
      "name": "Deleting a message 5",
      "type": "n8n-nodes-base.telegram",
      "position": [
        64,
        2784
      ],
      "parameters": {
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"chat\"][\"id\"] }}",
        "messageId": "={{ $item(\"0\").$node[\"A message that only those who sent an original message can request more\"].json[\"result\"][\"message_id\"] }}",
        "operation": "deleteMessage"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "01b27dcf-804c-4aab-bba2-c4c12fcbc6d3",
      "name": "Request to join the group 1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        64,
        2592
      ],
      "parameters": {
        "text": "=Hello \ud83d\ude0a\n\nTo use the bot, you must first join the \"cheap deals before everyone\" channel on Telegram \ud83c\udfc6\n\nAfter joining, just write: \"Find me...\" and what you are looking for \ud83d\udd0d",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "\ud83d\udd17 \u05de\u05e2\u05d1\u05e8 \u05dc\u05e2\u05e8\u05d5\u05e5 \u05d4\u05d3\u05d9\u05dc\u05d9\u05dd",
                    "additionalFields": {
                      "url": "https://t.me/aliexpressdils"
                    }
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"message_id\"] }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c6d082da-c47b-4c0c-9ac4-83e7b14e1798",
      "name": "Opening message 2",
      "type": "n8n-nodes-base.telegram",
      "position": [
        288,
        2304
      ],
      "parameters": {
        "text": "\u23f3 Just a moment...|You will find a team that searches in depth - checks reviews, compares prices, and does everything to find the most suitable product just for you!",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"chat\"][\"id\"] }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('Telegram Trigger').item.json.callback_query.message.reply_to_message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "24431c33-dfa4-456a-89c4-81b3a2e392ca",
      "name": "Request for correct wording 1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        288,
        2496
      ],
      "parameters": {
        "text": "=\ud83d\udca1 So that the bot can help properly, simply write the message in one of the following forms:\nFind me, look for me, look for me, find me, send me, send me\n\n\ud83d\udd0d For example:\nFind me {{ $('Telegram Trigger').item.json.message.text }}\n\n\u2705 Use one of these starters - and the bot already takes care of the rest!",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"message_id\"] }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "834b00e0-dbb4-4d01-8c86-3e77a904acd7",
      "name": "Start typing 1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        512,
        2304
      ],
      "parameters": {
        "chatId": "={{ $item(\"0\").$node[\"Opening message 2\"].json[\"result\"][\"chat\"][\"id\"] }}",
        "operation": "sendChatAction"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "431ed356-fc49-477f-a389-057f32a1fe67",
      "name": "Creating a professional search term 1",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        736,
        2304
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5.2",
          "cachedResultName": "GPT-5.2"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "role": "system",
              "content": "=You validate and optimize search queries for AliExpress.\nYour task: get a search term and verify/optimize it for search on AliExpress.\n\nInput: {{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"text\"].split(' ').slice(2).join(' ') }}\n\nRules:\n1. Extract only the product name/description from the search term\n2. Remove all non-product information:\n   - Price mentions (for example, \"up to NIS 150\", \"under 100\", \"under 100\")\n   - Quantity references (eg, \"5 units\", \"pack of 3\")\n   - Color/size specifications (e.g., \"in size L\", \"in black color\")\n   - time constraints (for example, \"fast delivery\", \"by Sunday\")\n   - Any filter criteria other than the main product name\n3. Clear the remaining product name:\n   - Remove special characters: # @ $ % ^ & * ( ) = + [ ] { } |   : ;   \"'<>?\n   - Keep hyphens (-) and underscores (_) as they are valid in product searches\n   - Remove excessive spaces (several spaces in a row)\n4. Save the language of the original product name (Hebrew/English/etc.)\n5. Do not translate, do not add words, do not change the core meaning of the product\n6. Return only the cleaned product name, nothing else - no explanations, no quotes, no extra text\n\nExamples:\nInput: \"iPhone cover\"\nOutput: iPhone cover\n\nInput: \"Shoes up to NIS 150\"\nOutput: shoes\n\nInput: \"Wireless headphones under $50\"\nOutput: wireless headphones\n\nInput: \"iPhone charger fast delivery\"\nOutput: iPhone charger\n\nInput: \"Large number speakers 5 units\"\nOutput: Speakers\n\nInput: \"Game mouse!!!   cheap price\"\nOutput: Gaming mouse"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "e9b00b13-53c6-4e5b-a9a4-dfe0e78137b5",
      "name": "Data scraping1",
      "type": "@decodo/n8n-nodes-decodo.decodo",
      "maxTries": 5,
      "position": [
        1088,
        2304
      ],
      "parameters": {
        "geo": "Israel",
        "url": "=https://aliexpress.com/w/wholesale-{{ $json.output[0].content[0].text.replaceAll(' ', '-') }}.html"
      },
      "credentials": {
        "decodoApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1,
      "waitBetweenTries": 5000
    },
    {
      "id": "658b00e2-f47b-43cc-b41d-22502ef6562f",
      "name": "Follow-up message 1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1376,
        2304
      ],
      "parameters": {
        "text": "\ud83d\udd25 Wow!  I have everything!  |  All the details are here with me, now I'm just arranging and comparing the most winning product for you!  A moment and I'll be back with a bomb...",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"chat\"][\"id\"] }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('Telegram Trigger').item.json.callback_query.message.reply_to_message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "074ad2a5-755a-41a0-bcd1-96fd62de9ad5",
      "name": "Extracting all items 1",
      "type": "n8n-nodes-base.code",
      "position": [
        1664,
        2304
      ],
      "parameters": {
        "jsCode": "const html = $('Data scraping1').first().json.results[0].content;\n\nconst scripts = html.match(/<script[^>]*>([\\s\\S]*?)<\\/script>/g) ||  [];\n\n\u05ea\u05df \u05de\u05d5\u05e6\u05e8\u05d9\u05dd = null;\n\n// \u05e0\u05d9\u05e1\u05d9\u05d5\u05df 1: \u05d7\u05d9\u05e4\u05d5\u05e9 \u05d1-window._dida_config_._init_data_\n\u05e2\u05d1\u05d5\u05e8 (\u05ea\u05df \u05e1\u05e7\u05e8\u05d9\u05e4\u05d8 \u05e9\u05dc \u05e1\u05e7\u05e8\u05d9\u05e4\u05d8\u05d9\u05dd) {\n  const content = script.replace(/<script[^>]*>/, '').replace(/<\\/script>/, '');\n \n  if (content.includes('window._dida_config_._init_data_') && content.includes('productId')) {\n    const dataMatch = content.match(/window\\._dida_config_\\._init_data_\\s*=\\s*(\\{[\\s\\S]+?\\});/);\n    if (dataMatch) {\n      \u05e0\u05e1\u05d4 {\n        const dataObj = JSON.parse(dataMatch[1]);\n        products = dataObj?.data?.data?.root?.fields?.mods?.itemList?.content;\n        if (products && Array.isArray(products) && products.length > 0) break;\n      } \u05ea\u05e4\u05d5\u05e1 (\u05d4) {}\n    }\n  }\n}\n\n// \u05e0\u05d9\u05e1\u05d9\u05d5\u05df 2: \u05d7\u05d9\u05e4\u05d5\u05e9 \u05d9\u05e9\u05d9\u05e8 \u05e9\u05dc \"itemList\":{\"content\":[\nif (!products || !Array.isArray(products) || products.length === 0) {\n  \u05e2\u05d1\u05d5\u05e8 (\u05ea\u05df \u05e1\u05e7\u05e8\u05d9\u05e4\u05d8 \u05e9\u05dc \u05e1\u05e7\u05e8\u05d9\u05e4\u05d8\u05d9\u05dd) {\n    const content = script.replace(/<script[^>]*>/, '').replace(/<\\/script>/, '');\n   \n    if (content.includes('\"itemList\"') && content.includes('\"productId\"')) {\n      const searchPattern = '\"itemList\":{\"content\":[';\n      const contentStart = content.indexOf(searchPattern);\n     \n      if (contentStart !== -1) {\n        const arrayStart = content.indexOf('[', contentStart);\n        \u05ea\u05df \u05e2\u05d5\u05de\u05e7 = 0;\n        let inString = false;\n        \u05ea\u05df \u05dc\u05d1\u05e8\u05d5\u05d7 = \u05e9\u05e7\u05e8;\n        let arrayEnd = arrayStart;\n       \n        for (let i = arrayStart; i < content.length; i++) {\n          const char = content[i];\n         \n          if (escape) {\nreturn extractedData.map(item => ({ json: item }));"
      },
      "typeVersion": 2
    },
    {
      "id": "6938c765-3340-4956-8e87-53a51b8449b6",
      "name": "Creating an affiliate link",
      "type": "n8n-nodes-aliexpress-affiliate.aliExpressAffiliate",
      "position": [
        2112,
        2016
      ],
      "parameters": {
        "tracking_id": "YOUR_AFFILIATE_TRACKING_ID",
        "source_values": "={{ $json.productUrl }}",
        "promotion_link_type": 2
      },
      "credentials": {
        "aliExpressAffiliateApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1
    },
    {
      "id": "addbff58-332b-4c08-ade4-df0dabc350b7",
      "name": "If there is an error or not 1",
      "type": "n8n-nodes-base.if",
      "position": [
        2560,
        2304
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c133323a-3b54-4afe-afe3-ed9dcf96c5ab",
              "operator": {
                "type": "number",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.result }}",
              "rightValue": 2
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d705d739-bdb7-46d6-b568-a292cdeebffb",
      "name": "Wording for message",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2784,
        2304
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5.2",
          "cachedResultName": "GPT-5.2"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a professional and convincing sales agent in Hebrew.  It's your job to create a cool Telegram message that will make the customer want to buy right away!\n\nYou received the following details:\n- What the client searched for: {{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"reply_to_message\"][\"text\"].replace(/^(find me|search me|search me|find me|send me|send me)\\s*/g, '').trim() }}\n- Product name: {{ $('Extraction of 2 products from the first 7').item.json.title }}\n- Original price: {{ $('Extraction of 2 products from the first 7').item.json.originalPrice }}\n- Sale price: {{ $('Extraction of 2 products from the first 7').item.json.salePrice }}\n- Discount percentage: {{ $('Extraction of 2 products from the first 7').item.json.discount }}\n- Rating: {{ $('Extraction of 2 products from the first 7').item.json.rating }}\n- Quantity sold: {{ $('Extraction of 2 products from the first 7').item.json.soldCount }}\nMaximum 7-8 lines, short and precise!"
            }
          ]
        },
        "simplify": false
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "12e0b047-b8df-4186-a962-29125ac5e8af",
      "name": "Sending a message 1",
      "type": "n8n-nodes-base.telegram",
      "onError": "continueRegularOutput",
      "position": [
        3136,
        2304
      ],
      "parameters": {
        "file": "={{ $('Extraction of 2 products from the first 7').item.json.mainImage }}",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"chat\"][\"id\"] }}",
        "operation": "sendPhoto",
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "\ud83d\udd0d You will find more",
                    "additionalFields": {
                      "callback_data": "more_results"
                    }
                  },
                  {
                    "text": "\ud83d\uded2 for purchase",
                    "additionalFields": {
                      "url": "={{ $('Creating an affiliate link').item.json.aliexpress_affiliate_link_generate_response.resp_result.result.promotion_links.promotion_link[0].promotion_link }}"
                    }
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {
          "caption": "={{ $('Wording for message').item.json.choices[0].message.content }}",
          "parse_mode": "HTML",
          "reply_to_message_id": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"reply_to_message\"][\"message_id\"] }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2,
      "alwaysOutputData": true
    },
    {
      "id": "9267fb15-8614-49b2-8a91-4c6e63dd0072",
      "name": "Deleting a message 3",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3424,
        2304
      ],
      "parameters": {
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"chat\"][\"id\"] }}",
        "messageId": "={{ $item(\"0\").$node[\"Opening message 2\"].json[\"result\"][\"message_id\"] }}",
        "operation": "deleteMessage"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "723e38f4-2f62-4a8b-bf4d-b11db13e3ded",
      "name": "Deleting a message4",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3712,
        2304
      ],
      "parameters": {
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"callback_query\"][\"message\"][\"chat\"][\"id\"] }}",
        "messageId": "={{ $item(\"0\").$node[\"Follow-up message 1\"].json[\"result\"][\"message_id\"] }}",
        "operation": "deleteMessage"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "b9fa5bab-d9f3-4a2d-8409-8de510da428a",
      "name": "If there is problematic content",
      "type": "n8n-nodes-base.if",
      "position": [
        -160,
        1920
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "da0e80cb-9f79-4ece-af8c-3f188ac7e8f7",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "rejected"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "c16fc16a-21a5-4b60-98bc-24137be6edf6",
      "name": "Checking if we are in a certain group",
      "type": "n8n-nodes-base.telegram",
      "position": [
        64,
        1824
      ],
      "parameters": {
        "chatId": "@your group",
        "userId": "={{ $('Telegram Trigger').item.json.message.from.id }}",
        "resource": "chat",
        "operation": "member"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a5bd1973-89ba-4efa-8c44-e9b6c1120a35",
      "name": "Request to join the group",
      "type": "n8n-nodes-base.telegram",
      "position": [
        512,
        1920
      ],
      "parameters": {
        "text": "=Hello \ud83d\ude0a\n\nTo use the bot, you must first join the \"cheap deals before everyone\" channel on Telegram \ud83c\udfc6\n\nAfter joining, just write: \"Find me...\" and what you are looking for \ud83d\udd0d",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "\ud83d\udd17 \u05de\u05e2\u05d1\u05e8 \u05dc\u05e2\u05e8\u05d5\u05e5 \u05d4\u05d3\u05d9\u05dc\u05d9\u05dd",
                    "additionalFields": {
                      "url": "https://t.me/aliexpressdils"
                    }
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"message_id\"] }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5f066203-bc0d-47ff-9a39-1ed9018d8803",
      "name": "opening message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        800,
        1632
      ],
      "parameters": {
        "text": "\u23f3 Just a moment...|You will find a team that searches in depth - checks reviews, compares prices, and does everything to find the most suitable product just for you!",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"message_id\"] }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7031bd59-85d7-41e0-b9b9-08c2cf425f84",
      "name": "Start typing",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1088,
        1632
      ],
      "parameters": {
        "chatId": "={{ $item(\"0\").$node[\"opening message\"].json[\"result\"][\"chat\"][\"id\"] }}",
        "operation": "sendChatAction"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "106782f8-fc58-4b5c-8db0-9587b2f1d95b",
      "name": "Request for correct wording",
      "type": "n8n-nodes-base.telegram",
      "position": [
        800,
        1920
      ],
      "parameters": {
        "text": "=\ud83d\udca1 So that the bot can help properly, simply write the message in one of the following forms:\nFind me, look for me, look for me, find me, send me, send me\n\n\ud83d\udd0d For example:\nFind me {{ $('Telegram Trigger').item.json.message.text }}\n\n\u2705 Use one of these starters - and the bot already takes care of the rest!",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"message_id\"] }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b6ba7019-d442-4e49-a736-236b4d1526b2",
      "name": "Creating a professional search term",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1312,
        1632
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5.2",
          "cachedResultName": "GPT-5.2"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "=\u05d0\u05ea\u05d4 \u05de\u05d0\u05de\u05ea \u05d5\u05de\u05d9\u05d9\u05e2\u05dc \u05e9\u05d0\u05d9\u05dc\u05ea\u05d5\u05ea \u05d7\u05d9\u05e4\u05d5\u05e9 \u05e2\u05d1\u05d5\u05e8 AliExpress.\n\u05d4\u05de\u05e9\u05d9\u05de\u05d4 \u05e9\u05dc\u05da: \u05dc\u05e7\u05d1\u05dc \u05de\u05d5\u05e0\u05d7 \u05d7\u05d9\u05e4\u05d5\u05e9 \u05d5\u05dc\u05d0\u05de\u05ea/ \u05dc\u05d1\u05e6\u05e2 \u05d0\u05d5\u05e4\u05d8\u05d9\u05de\u05d9\u05d6\u05e6\u05d9\u05d4 \u05e9\u05dc\u05d5 \u05dc\u05d7\u05d9\u05e4\u05d5\u05e9 \u05d1\u05d0\u05dc\u05d9\u05d0\u05e7\u05e1\u05e4\u05e8\u05e1.\n\n\u05e7\u05dc\u05d8: {{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"text\"].split(' ').slice(2).join(' ') }}\n\n\u05db\u05dc\u05dc\u05d9\u05dd:\n1. \u05d7\u05dc\u05e5 \u05e8\u05e7 \u05d0\u05ea \u05e9\u05dd \u05d4\u05de\u05d5\u05e6\u05e8/\u05ea\u05d9\u05d0\u05d5\u05e8 \u05de\u05de\u05d5\u05e0\u05d7 \u05d4\u05d7\u05d9\u05e4\u05d5\u05e9\n2. \u05d4\u05e1\u05e8 \u05d0\u05ea \u05db\u05dc \u05d4\u05de\u05d9\u05d3\u05e2 \u05e9\u05d0\u05d9\u05e0\u05d5 \u05de\u05d5\u05e6\u05e8:\n   - \u05d0\u05d6\u05db\u05d5\u05e8\u05d9 \u05de\u05d7\u05d9\u05e8\u05d9\u05dd (\u05dc\u05de\u05e9\u05dc, \"\u05e2\u05d3 150 \u05e9\u05d7\", \"\u05de\u05ea\u05d7\u05ea \u05dc-100\", \"\u05de\u05ea\u05d7\u05ea \u05dc-100\")\n   - \u05d0\u05d6\u05db\u05d5\u05e8\u05d9\u05dd \u05d1\u05db\u05de\u05d5\u05ea (\u05dc\u05de\u05e9\u05dc, \"5 \u05d9\u05d7\u05d9\u05d3\u05d5\u05ea\", \"\u05d7\u05d1\u05d9\u05dc\u05d4 \u05e9\u05dc 3\")\n   - \u05de\u05e4\u05e8\u05d8\u05d9 \u05e6\u05d1\u05e2/\u05d2\u05d5\u05d3\u05dc (\u05dc\u05de\u05e9\u05dc, \"\u05d1\u05de\u05d9\u05d3\u05d4 L\", \"\u05d1\u05e6\u05d1\u05e2 \u05e9\u05d7\u05d5\u05e8\")\n   - \u05d0\u05d9\u05dc\u05d5\u05e6\u05d9 \u05d6\u05de\u05df (\u05dc\u05d3\u05d5\u05d2\u05de\u05d4, \"\u05de\u05e9\u05dc\u05d5\u05d7 \u05de\u05d4\u05d9\u05e8\", \"\u05e2\u05d3 \u05d9\u05d5\u05dd \u05e8\u05d0\u05e9\u05d5\u05df\")\n   - \u05db\u05dc \u05e7\u05e8\u05d9\u05d8\u05e8\u05d9\u05d5\u05df \u05e1\u05d9\u05e0\u05d5\u05df \u05e9\u05d0\u05d9\u05e0\u05d5 \u05e9\u05dd \u05d4\u05de\u05d5\u05e6\u05e8 \u05d4\u05de\u05e8\u05db\u05d6\u05d9\n3. \u05e0\u05e7\u05d4 \u05d0\u05ea \u05e9\u05dd \u05d4\u05de\u05d5\u05e6\u05e8 \u05d4\u05e0\u05d5\u05ea\u05e8:\n   - \u05d4\u05e1\u05e8 \u05ea\u05d5\u05d5\u05d9\u05dd \u05de\u05d9\u05d5\u05d7\u05d3\u05d9\u05dd: # @ $ % ^ & * ( ) = + [ ] { } |  \\ : ;  \"'<>?\n\u05e4\u05dc\u05d8: \u05e2\u05db\u05d1\u05e8 \u05d2\u05d9\u05d9\u05de\u05d9\u05e0\u05d2"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "f5251536-43e5-4089-b676-fcc5207dc82c",
      "name": "data scraping",
      "type": "@decodo/n8n-nodes-decodo.decodo",
      "maxTries": 5,
      "position": [
        1664,
        1632
      ],
      "parameters": {
        "geo": "Israel",
        "url": "=https://aliexpress.com/w/wholesale-{{ $json.output[0].content[0].text.replaceAll(' ', '-') }}.html"
      },
      "credentials": {
        "decodoApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1,
      "waitBetweenTries": 5000
    },
    {
      "id": "089d8ed5-b24b-4e83-805d-c2ec92c25435",
      "name": "Follow up message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1888,
        1632
      ],
      "parameters": {
        "text": "\ud83d\udd25 Wow!  I have everything!  |  All the details are here with me, now I'm just arranging and comparing the most winning product for you!  A moment and I'll be back with a bomb...",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"message_id\"] }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "820651a3-f443-4493-8663-456b1ce0a8f9",
      "name": "Extract all items",
      "type": "n8n-nodes-base.code",
      "position": [
        2112,
        1632
      ],
      "parameters": {
        "jsCode": "const html = $('data scraping').first().json.results[0].content;\n// Attempt 1: Search window._dida_config_._init_data_\nfor (let script of scripts) {\n  const content = script.replace(/<script[^>]*>/, '').replace(/<\\/script>/, '');\n\n  if (content.includes('window._dida_config_._init_data_') && content.includes('productId')) {\n    const dataMatch = content.match(/window\\._dida_config_\\._init_data_\\s*=\\s*(\\{[\\s\\S]+?\\});/);\n    if (dataMatch) {\n      try {\n        const dataObj = JSON.parse(dataMatch[1]);\n        products = dataObj?.data?.data?.root?.fields?.mods?.itemList?.content;\n        if (products && Array.isArray(products) && products.length > 0) break;\n      } catch (e) {}\n    }\n  }\n}\n\n// Attempt 2: Direct search of \"itemList\":{\"content\":[\nif (!products || !Array.isArray(products) || products.length === 0) {\n  for (let script of scripts) {\n    const content = script.replace(/<script[^>]*>/, '').replace(/<\\/script>/, '');\n  \n    if (content.includes('\"itemList\"') && content.includes('\"productId\"')) {\n      const searchPattern = '\"itemList\":{\"content\":[';\n      const contentStart = content.indexOf(searchPattern);\n    \n      if (contentStart !== -1) {\n        const arrayStart = content.indexOf('[', contentStart);\n        let depth = 0;\n        let inString = false;\n        let escape = false;\n        let arrayEnd = arrayStart;\n      \n        for (let i = arrayStart; i < content.length; i++) {\n          const char = content[i];\n        \n          if (escape) {\n            escape = false;\n            continue;\n          }\n        \n          if (char === '\\\\') {\n            escape = true;\n            continue;\n          }\n        \n          if (char === '\"') {\n            inString = !inString;\n            to continue;\n          }\n        \n          if (!inString) {\n            if (char === '[' || char === '{') depth++;\n            if (char === ']' || char === '}') depth--;\n          \n            if (depth === 0 && char === ']') {\n              arrayEnd = i + 1;\n              break;\n            }\n          }\n        }\n      \n        if (arrayEnd > arrayStart) {\n          const jsonArray = content.substring(arrayStart, arrayEnd);\n          try {\n            products = JSON.parse(jsonArray);\n            if (products && Array.isArray(products) && products.length > 0) break;\nreturn extractedData.map(item => ({ json: item }));"
      },
      "typeVersion": 2
    },
    {
      "id": "ae1b3a0f-d25c-4bb4-8885-b27fc4886629",
      "name": "Extraction of 2 products from the first 10",
      "type": "n8n-nodes-base.code",
      "position": [
        2336,
        1552
      ],
      "parameters": {
        "jsCode": "// Getting all the products\nconst items = $input.all();\nlet products;\nif (items.length === 1 && Array.isArray(items[0].json)) {\n  products = items[0].json;\n} else {\n  products = items.map(item => item.json);\n}\n\n// taking the first 2\nconst top2 = products.slice(0, 2);\n\n// Returning the products with valid links\nreturn top2.map(product => {\n  const cleanUrl = `https://www.aliexpress.com/item/${product.productId}.html`;\n \n  return {\n    json: {\n      ...product,\n      productUrl: cleanUrl\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "96daa4fa-4c06-427c-bd6a-5fb3bf9c43c5",
      "name": "Extraction of 2 products from the first 7",
      "type": "n8n-nodes-base.code",
      "position": [
        1888,
        2016
      ],
      "parameters": {
        "jsCode": "// Getting all the products\nconst items = $input.all();\nlet products;\nif (items.length === 1 && Array.isArray(items[0].json)) {\n  products = items[0].json;\n} else {\n  products = items.map(item => item.json);\n}\n// skipping the first 2, taking the next 5 (from the third to the seventh)\nconst top5 = products.slice(2, 7);\n// Pick 2 random out of 5\nfunction getRandomProducts(arr, count) {\n  const copy = [...arr];\n  const result = [];\n \n  for (let i = 0; i < count && copy.length > 0; i++) {\n    const randomIndex = Math.floor(Math.random() * copy.length);\n    result.push(copy[randomIndex]);\n    copy.splice(randomIndex, 1);\n  }\n \n  return result;\n}\nconst randomProducts = getRandomProducts(top5, 2);\n// Returning the products with valid links\nreturn randomProducts.map(product => {\n  const cleanUrl = `https://www.aliexpress.com/item/${product.productId}.html`;\n \n  return {\n    json: {\n      ...product,\n      productUrl: cleanUrl\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "c7d97f05-445e-41ae-bc1d-4a7937cf0780",
      "name": "Opening message 1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        64,
        2112
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a38f5fb9-50f8-404e-b12b-37c9652f46be",
      "name": "Deleting a message 2",
      "type": "n8n-nodes-base.telegram",
      "position": [
        288,
        2112
      ],
      "parameters": {
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "messageId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"message_id\"] }}",
        "operation": "deleteMessage"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "169222c2-5cb7-4967-9a0a-b73d19862518",
      "name": "Automatic removal of the user from the group",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        512,
        2112
      ],
      "parameters": {
        "url": "=https://api.telegram.org/YOUR_TELEGRAM_BOT_TOKE/banChatMember",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "chat_id",
              "value": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}"
            },
            {
              "name": "user_id",
              "value": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"] }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "350e8e76-441e-4d66-acd5-9ddd0da50817",
      "name": "Creating an affiliate link3",
      "type": "n8n-nodes-aliexpress-affiliate.aliExpressAffiliate",
      "position": [
        2560,
        1552
      ],
      "parameters": {
        "tracking_id": "YOUR_AFFILIATE_TRACKING_ID",
        "source_values": "={{ $json.productUrl }}",
        "promotion_link_type": 2
      },
      "credentials": {
        "aliExpressAffiliateApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1
    },
    {
      "id": "d9b68d3c-78d6-43f7-b314-0788ab3a37ce",
      "name": "whether there is an error or not",
      "type": "n8n-nodes-base.if",
      "position": [
        3136,
        1632
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c133323a-3b54-4afe-afe3-ed9dcf96c5ab",
              "operator": {
                "type": "number",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.result }}",
              "rightValue": 2
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b48378b9-6993-4bbd-b4da-5173e8c9f823",
      "name": "Wording for message 3",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        3360,
        1632
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5.2",
          "cachedResultName": "GPT-5.2"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a professional and convincing sales agent in Hebrew.  It's your job to create a cool Telegram message that will make the customer want to buy right away!\n\nYou received the following details:\n- What the customer searched for: {{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"text\"].replace(/^(find me|search me|search me|find me|send me|send me)\\s*/g, '').trim() }}\n- Product name: {{ $('Extraction of 2 products from the first 10').item.json.title }}\n- Original price: {{ $('Extraction of 2 products from the first 10').item.json.originalPrice }}\n- Sale price: {{ $('Extraction of 2 products from the first 10').item.json.salePrice }}\n- Discount percentage: {{ $('Extraction of 2 products from the first 10').item.json.discount }}\n- Rating: {{ $('Extraction of 2 products from the first 10').item.json.rating }}\n- Quantity sold: {{ $('Extraction of 2 products from the first 10').item.json.soldCount }}\n- Special tags: {{ $('Extraction of 2 products from the first 10').item.json.tags }}\nMaximum 7-8 lines, short and precise!"
            }
          ]
        },
        "simplify": false
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "4af3fdcc-99bc-41ed-98ff-90aeae52633a",
      "name": "sending a message",
      "type": "n8n-nodes-base.telegram",
      "onError": "continueRegularOutput",
      "position": [
        3712,
        1632
      ],
      "parameters": {
        "file": "={{ $('Extraction of 2 products from the first 10').item.json.mainImage }}",
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "operation": "sendPhoto",
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "\ud83d\udd0d You will find more",
                    "additionalFields": {
                      "callback_data": "more_results"
                    }
                  },
                  {
                    "text": "\ud83d\uded2 for purchase",
                    "additionalFields": {
                      "url": "={{ $('Creating an affiliate link3').item.json.aliexpress_affiliate_link_generate_response.resp_result.result.promotion_links.promotion_link[0].promotion_link }}"
                    }
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {
          "caption": "={{ $('Wording for message 3').item.json.choices[0].message.content }}",
          "parse_mode": "HTML",
          "reply_to_message_id": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"message_id\"] }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2,
      "alwaysOutputData": true
    },
    {
      "id": "a35465aa-56a1-450d-98c1-2b5f320180c7",
      "name": "Deleting a message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3936,
        1632
      ],
      "parameters": {
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "messageId": "={{ $item(\"0\").$node[\"opening message\"].json[\"result\"][\"message_id\"] }}",
        "operation": "deleteMessage"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "ecfadf5e-db27-469a-9845-51750d01ad2a",
      "name": "Deleting a message 1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        4160,
        1632
      ],
      "parameters": {
        "chatId": "={{ $item(\"0\").$node[\"Telegram Trigger\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "messageId": "={{ $item(\"0\").$node[\"Follow up message\"].json[\"result\"][\"message_id\"] }}",
        "operation": "deleteMessage"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 1.2
    },
    {
      "id": "5088b848-be9b-40d3-b219-728b8fec9a6e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1504,
        1440
      ],
      "parameters": {
        "width": 528,
        "height": 608,
        "content": "# AliExpress Affiliate Bot for Telegram\n\nAutomatically find and share AliExpress products with affiliate links in your Telegram group.\n\n## How it works\n1. Bot receives messages and callback queries from Telegram group\n2. AI moderator checks content for spam, links, and inappropriate requests\n3. Valid product requests trigger an AliExpress search\n4. System generates affiliate tracking links for top matching products\n5. Formatted product cards are sent back to the Telegram group\n6. Users can request additional options via inline buttons\n\n## Setup steps\n1. Create a Telegram Bot via @BotFather and obtain API token\n2. Register for AliExpress Affiliate Program and get App Key & Secret\n3. Create OpenAI API account and generate API key\n4. Add all three credentials in n8n (Telegram, AliExpress, OpenAI)\n5. Replace placeholder credential IDs with your own\n6. Add the bot to your Telegram group with admin permissions\n7. Activate the workflow and test with a sample product request"
      },
      "typeVersion": 1
    },
    {
      "id": "613c5d55-a79e-40c3-9a74-2eb25845ffda",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1472,
        2176
      ],
      "parameters": {
        "color": 7,
        "height": 112,
        "content": "\ud83d\udce5 Input Handler\nReceives incoming messages and callback queries from Telegram."
      },
      "typeVersion": 1
    },
    {
      "id": "538075c1-6781-4171-bc8e-0b94848ecaae",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        1792
      ],
      "parameters": {
        "color": 7,
        "height": 112,
        "content": "\ud83d\udee1\ufe0f Content Moderation\nAI validates message content. Blocks spam, links, and inappropriate requests."
      },
      "typeVersion": 1
    },
    {
      "id": "74e555fb-230c-4d5e-bd39-17f42b19c803",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1296,
        1504
      ],
      "parameters": {
        "color": 7,
        "height": 112,
        "content": "\ud83d\udd0d Product Search\nTranslates request to search query and scrapes AliExpress for products."
      },
      "typeVersion": 1
    },
    {
      "id": "03bf3077

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Build a Telegram bot that helps users find AliExpress products using natural language requests. The bot uses OpenAI to optimize search queries, Decodo to scrape product listings, and AI analysis to select the best options based on ratings, reviews, and price—then automatically…

Source: https://n8n.io/workflows/12437/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Ask questions like “How much did I spend on food last month?” and get instant answers from your financial data — directly in Telegram.

Telegram Trigger, OpenAI, Google Sheets +2
AI & RAG

Voice Note -> Veo 3 AD. Uses telegramTrigger, telegram, openAi, httpRequest. Event-driven trigger; 49 nodes.

Telegram Trigger, Telegram, OpenAI +3
AI & RAG

&gt; ⚠️ Disclaimer: This workflow uses Community Nodes and must be run on a self-hosted instance of n8n.

HTTP Request, Telegram Trigger, Telegram +2
AI & RAG

Viral Tik Tok Clone Finder. Uses httpRequest, telegramTrigger, openAi, googleSheets. Event-driven trigger; 41 nodes.

HTTP Request, Telegram Trigger, OpenAI +2
AI & RAG

This workflow is designed for content creators, agencies, influencers, and automation builders who want to transform viral videos into personalized avatar-based edits — and automatically publish them

Telegram Trigger, Telegram, HTTP Request +3