{
  "name": "UNIVERSE — Lead & order inbox (Concept)",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "hook": null,
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0
        }
      },
      "notes": "Receives {channel, name, phone, email, message} from ManyChat (Instagram), WhatsApp Cloud API relay or the site order form."
    },
    {
      "id": 2,
      "module": "google-sheets:filterRows",
      "version": 2,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "from": "drive",
        "spreadsheetId": "REPLACE_WITH_YOUR_SPREADSHEET_ID",
        "sheetId": "Leads",
        "includesHeaders": true,
        "valueRenderOption": "FORMATTED_VALUE",
        "dateTimeRenderOption": "FORMATTED_STRING",
        "filter": [
          [
            {
              "a": "C",
              "b": "{{1.phone}}",
              "o": "text:equal"
            }
          ]
        ],
        "limit": "1"
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0
        }
      }
    },
    {
      "id": 3,
      "module": "openai-gpt-3:CreateCompletion",
      "version": 1,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "select": "chat",
        "model": "gpt-4o-mini",
        "max_tokens": "500",
        "temperature": "0.3",
        "response_format": "json_object",
        "messages": [
          {
            "role": "system",
            "content": "You help UNIVERSE, a wholesale clothing brand in Algeria, triage customer messages. Messages may be in Algerian Darja, Arabic, French or English. Return ONLY JSON with keys: intent (one of: order, price_request, catalogue, question, other), language (darja|ar|fr|en), summary (max 20 words, English), products (array of strings), quantity (string or empty), city (string or empty), reply_draft (a short, polite reply in the customer's language; never promise prices, stock or delivery dates — say a team member will confirm)."
          },
          {
            "role": "user",
            "content": "Channel: {{1.channel}}\nName: {{1.name}}\nKnown customer: {{if(2.`__ROW_NUMBER__`; \"yes\"; \"no\")}}\nMessage: {{1.message}}"
          }
        ]
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0
        }
      }
    },
    {
      "id": 4,
      "module": "json:ParseJSON",
      "version": 1,
      "parameters": {
        "type": ""
      },
      "mapper": {
        "json": "{{3.choices[].message.content}}"
      },
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0
        }
      }
    },
    {
      "id": 5,
      "module": "google-sheets:addRow",
      "version": 2,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "from": "drive",
        "mode": "select",
        "valueInputOption": "USER_ENTERED",
        "insertDataOption": "INSERT_ROWS",
        "insertUnformatted": false,
        "spreadsheetId": "REPLACE_WITH_YOUR_SPREADSHEET_ID",
        "sheetId": "Leads",
        "includesHeaders": true,
        "values": {
          "0": "{{formatDate(now; \"YYYY-MM-DD HH:mm\")}}",
          "1": "{{1.name}}",
          "2": "{{1.phone}}",
          "3": "{{1.email}}",
          "4": "{{1.channel}}",
          "5": "{{4.intent}}",
          "6": "{{4.language}}",
          "7": "{{4.summary}}",
          "8": "{{join(4.products; \", \")}}",
          "9": "{{4.quantity}}",
          "10": "{{4.city}}",
          "11": "{{4.reply_draft}}",
          "12": "To review",
          "13": "{{if(2.`__ROW_NUMBER__`; \"Returning\"; \"New\")}}"
        }
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": 0
        }
      }
    },
    {
      "id": 6,
      "module": "builtin:BasicRouter",
      "version": 1,
      "mapper": null,
      "metadata": {
        "designer": {
          "x": 1500,
          "y": 0
        }
      },
      "routes": [
        {
          "flow": [
            {
              "id": 7,
              "module": "telegram:SendReplyMessage",
              "version": 1,
              "parameters": {
                "__IMTCONN__": null
              },
              "filter": {
                "name": "Order or price request",
                "conditions": [
                  [
                    {
                      "a": "{{4.intent}}",
                      "b": "order",
                      "o": "text:equal:ci"
                    }
                  ],
                  [
                    {
                      "a": "{{4.intent}}",
                      "b": "price_request",
                      "o": "text:equal:ci"
                    }
                  ]
                ]
              },
              "mapper": {
                "chatId": "REPLACE_WITH_OWNER_CHAT_ID",
                "text": "🛍️ New {{4.intent}} — {{1.name}} ({{1.channel}})\n{{4.summary}}\nQty: {{4.quantity}} · City: {{4.city}}\nPhone: {{1.phone}}",
                "parseMode": "",
                "disableNotification": false
              },
              "metadata": {
                "designer": {
                  "x": 1800,
                  "y": -200
                }
              }
            }
          ]
        },
        {
          "flow": [
            {
              "id": 8,
              "module": "google-email:ActionSendEmail",
              "version": 2,
              "parameters": {
                "account": null
              },
              "filter": {
                "name": "Customer left an email",
                "conditions": [
                  [
                    {
                      "a": "{{1.email}}",
                      "o": "exist"
                    }
                  ]
                ]
              },
              "mapper": {
                "to": [
                  "{{1.email}}"
                ],
                "subject": "UNIVERSE — we received your request",
                "html": "<p>Hello {{1.name}},</p><p>Thanks for contacting UNIVERSE. We received your message and a team member will reply shortly with the catalogue and wholesale conditions.</p><p>— UNIVERSE</p>",
                "attachments": []
              },
              "metadata": {
                "designer": {
                  "x": 1800,
                  "y": 0
                }
              }
            }
          ]
        },
        {
          "flow": [
            {
              "id": 9,
              "module": "telegram:SendReplyMessage",
              "version": 1,
              "parameters": {
                "__IMTCONN__": null
              },
              "filter": {
                "name": "General question",
                "conditions": [
                  [
                    {
                      "a": "{{4.intent}}",
                      "b": "order",
                      "o": "text:notequal:ci"
                    },
                    {
                      "a": "{{4.intent}}",
                      "b": "price_request",
                      "o": "text:notequal:ci"
                    }
                  ]
                ]
              },
              "mapper": {
                "chatId": "REPLACE_WITH_OWNER_CHAT_ID",
                "text": "💬 Question from {{1.name}} ({{4.language}}): {{4.summary}}\nSuggested reply (review before sending):\n{{4.reply_draft}}",
                "parseMode": "",
                "disableNotification": true
              },
              "metadata": {
                "designer": {
                  "x": 1800,
                  "y": 200
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false,
      "slots": null,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    },
    "zone": "eu1.make.com"
  }
}