{
  "name": "Pede Ai",
  "nodes": [
    {
      "parameters": {
        "jsCode": "const products = items.map(item => item.json);\n\nconst chatId = $('Compose Context').first().json.chatId;\nconst categoryName = $('Order Menu Switch').first().json.name;\n\nlet menu = `\ud83d\udcd5 Card\u00e1pio de ${categoryName}\\n\\n`;\n\nlet counter = 1;\n\nlet optionsMap = {};\n\nfor (const product of products) {\n\n  if (!product.active) continue;\n\n  menu += `[ ${counter} ] - ${product.name} (R$ ${product.price})\\n`;\n\n  optionsMap[counter] = {\n    type: \"select_product\",\n    productId: product.id,\n    name: product.name,\n    price: product.price\n  };\n\n  counter++;\n}\n\nmenu += `[ ${counter} ] - Voltar\\n`;\n\noptionsMap[counter] = {\n  type: \"back_to_order_menu\"\n};\n\nmenu += \"\\nDigite o n\u00famero da op\u00e7\u00e3o desejada.\";\n\nreturn [{\n  json: {\n    chatId,\n    menu,\n    optionsMap\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1280,
        -192
      ],
      "id": "4ccf96c6-cd77-4cca-8d6f-55505b3e37fa",
      "name": "Render Products Menu"
    },
    {
      "parameters": {
        "url": "http://backend:3000/categories",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        2176,
        -672
      ],
      "id": "336aeefa-e1b3-4127-8d6e-e5ebb20e34ea",
      "name": "Get Categories"
    },
    {
      "parameters": {
        "chatId": "={{ $json.user.chatId }}",
        "text": "Por favor, digite um dos n\u00fameros dispon\u00edveis no menu.",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1728,
        -1024
      ],
      "id": "e2c7d83c-f42c-4c0e-a51d-beb830728ab2",
      "name": "Erro",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.user.chatId }}",
        "text": "\ud83d\udcac Estamos te encaminhando para um atendente.\n\nPor favor, aguarde um momento \ud83d\ude0a",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1504,
        -1168
      ],
      "id": "8037b9db-4853-4dce-8a73-98656638398d",
      "name": "falar_atendente",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.user.chatId }}",
        "text": "\ud83d\udce6 Digite o n\u00famero do seu pedido para consulta-lo",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1504,
        -1360
      ],
      "id": "5b71a6a6-6b58-428a-85d1-77e76b8554e6",
      "name": "acompanhar_pedido",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "d5a42562-40b2-4489-95e9-00fa6feed71c",
                    "leftValue": "={{ $json.input.text }}",
                    "rightValue": "2",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "acompanhar_pedido"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "0ec01d7c-e5b7-4aa5-b81b-8365583a8d70",
                    "leftValue": "={{ $json.input.text }}",
                    "rightValue": "3",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "falar_atendente"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.input.text }}",
                    "rightValue": "1",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "90701c65-e46d-4520-806d-14cab578f4d7"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "pedido"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        1056,
        -1136
      ],
      "id": "cf3f016c-2fe6-4290-ad0a-890a5be4f0fb",
      "name": "Main Menu Switch"
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.user.chatId }}",
        "text": "\ud83d\udc4b Ol\u00e1! Como podemos te ajudar?\n\n[ 1 ] - Fazer um novo pedido  \n[ 2 ] - Acompanhar meu pedido  \n[ 3 ] - Falar com um atendente\n\nResponda com o n\u00famero da op\u00e7\u00e3o.",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2176,
        -864
      ],
      "id": "8864d765-40ca-4467-a66a-eef677507c45",
      "name": "main_menu",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "bad975f9-ad19-4b98-86d6-c6074296898b",
                    "leftValue": "={{ $json.user.state }}",
                    "rightValue": "get_order",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "get_order"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "091525a0-0f8b-4e84-ae5e-43a15e3a1dbe",
                    "leftValue": "={{ $json.user.state }}",
                    "rightValue": "awaiting_main_menu_option",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "awaiting_main_menu_option"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "74fdafbd-e3cd-46cd-b2fe-b73412158aad",
                    "leftValue": "={{ $json.user.state }}",
                    "rightValue": "order_menu",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "order_menu"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.user.state }}",
                    "rightValue": "main_menu",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "afa53c6d-f8de-4e5e-bc5a-12a112b3a3f7"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "main_menu"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "e4f6ac59-a6a0-44ad-a6d5-af2774ca5653",
                    "leftValue": "={{ $json.user.state }}",
                    "rightValue": "awaiting_order_menu_option",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "awaiting_order_menu_option"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "de37b5d4-de8a-4325-90d2-ac8165e6bf60",
                    "leftValue": "={{ $json.user.state }}",
                    "rightValue": "awaiting_product_menu_option",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "awaiting_product_menu_option"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "e4c7c40d-cfa4-405b-a381-01fb498238ec",
                    "leftValue": "={{ $json.user.state }}",
                    "rightValue": "checkout",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "checkout"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        160,
        -352
      ],
      "id": "71439b89-8e9a-409b-85d1-c2d42a0efe52",
      "name": "Switch"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "WITH ensure_user AS (\n  INSERT INTO users (telegram_chat_id)\n  VALUES ($1)\n  ON CONFLICT (telegram_chat_id) DO NOTHING\n),\ninserted AS (\n  INSERT INTO user_sessions (chat_id, state)\n  VALUES ($1, 'main_menu')\n  ON CONFLICT (chat_id) DO NOTHING\n  RETURNING chat_id, state, data\n)\nSELECT chat_id, state, data FROM inserted\nUNION ALL\nSELECT chat_id, state, data\nFROM user_sessions\nWHERE chat_id = $1\nLIMIT 1;",
        "options": {
          "queryReplacement": "={{$json.chatId}}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        -288,
        -288
      ],
      "id": "5af15a3e-2dc6-4017-9b9d-76d474f087d8",
      "name": "Search Session",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "return [{\n  json: {\n    chatId: String($json.chat_id),\n    user: {\n      chatId: $json.chat_id,\n      state: $json.state,\n      data: $json.data || {}\n    },\n    input: {\n      text: $node[\"Extract Input\"].json.text\n    }\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -64,
        -288
      ],
      "id": "36fc62b6-05e0-45ee-bba6-d9b053b8d8f2",
      "name": "Compose Context"
    },
    {
      "parameters": {
        "jsCode": "return [{\n  json: {\n    chatId: $json.message.chat.id.toString(),\n    text: ($json.message.text || \"\").trim()\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -512,
        -288
      ],
      "id": "cfc8f7f5-0851-4b97-9212-f4d57e474c10",
      "name": "Extract Input"
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -736,
        -288
      ],
      "id": "ce5aadf9-d7d5-4523-bfb4-b3c72ff52972",
      "name": "Telegram Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const categories = items.map(item => item.json);\nconst chatId = $json.chatId;\n\nlet menu = \"\ud83d\uded2 Seu Pedido\\n\\n\";\nmenu += \"O que voc\u00ea gostaria de fazer agora?\\n\\n\";\n\nlet counter = 1;\nlet optionsMap = {};\n\nfor (const category of categories) {\n  menu += `[ ${counter} ] - Adicionar ${category.name}\\n`;\n\n  optionsMap[counter] = {\n    type: \"select_category\",\n    categoryId: category.id,\n    name: category.name\n  };\n\n  counter++;\n}\n\nmenu += `[ ${counter} ] - Voltar ao menu principal\\n`;\noptionsMap[counter] = { type: \"menu\" };\ncounter++;\n\nmenu += `[ ${counter} ] - Finalizar Pedido\\n`;\noptionsMap[counter] = { type: \"checkout\" };\n\nmenu += \"\\nDigite o n\u00famero da op\u00e7\u00e3o desejada.\";\n\nreturn [{\n  json: {\n    chatId,\n    menu,\n    optionsMap\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2400,
        -672
      ],
      "id": "75768172-35e9-4bf3-8f31-2452e7008c0e",
      "name": "Render Order Menu"
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.user.chatId }}",
        "text": "={{ $('Render Order Menu').item.json.menu }}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2848,
        -672
      ],
      "id": "5fe7aad2-847e-4ece-a179-d606e4c8c439",
      "name": "Order Menu",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions\nSET \n  state = 'awaiting_order_menu_option',\n  data = jsonb_set(\n    COALESCE(data, '{}'::jsonb),\n    '{optionsMap}',\n    $2::jsonb,\n    true\n  )\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "={{ $('Compose Context').item.json.user.chatId + ''  }}, {{ $json.optionsMap }}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        2624,
        -672
      ],
      "id": "c64c139a-1d6b-4f98-93b6-99746d185def",
      "name": "Save Options Map",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const chatId = $json.chatId;\nconst text = $json.input.text;\n\nconst number = Number(text);\nconst optionsMap = $json.user.data?.optionsMap;\n\nif (!optionsMap) {\n  return [{\n    json: {\n      chatId,\n      error: \"no_options_map\"\n    }\n  }];\n}\n\nconst option = optionsMap[number];\n\nif (!option) {\n  return [{\n    json: {\n      chatId,\n      type: \"invalid\"\n    }\n  }];\n}\n\nreturn [{\n  json: {\n    chatId,\n    type: option.type,\n    categoryId: option.categoryId,\n    name: option.name\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        608,
        -288
      ],
      "id": "831a646f-b8e6-4308-9549-40013dc66438",
      "name": "Resolve Order Menu Option"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "d2c1c22c-344c-4528-8d56-0b9273812aae",
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "invalid",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "invalid"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "2f3b2a79-611e-4fd0-a2cd-8b462b65f7f9",
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "menu",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "menu"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "select_category",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "0d1da128-48eb-482b-90b5-2ad9cfc7bcaf"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "select_category"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "1ebf498e-c50a-499f-93c6-92189290cb18",
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "checkout",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "checkout"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        816,
        -320
      ],
      "id": "1733060a-48c9-40f1-b430-d3334efca6e1",
      "name": "Order Menu Switch"
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.chatId }}",
        "text": "\ud83d\udd19 Voc\u00ea voltou ao menu principal.",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1728,
        -368
      ],
      "id": "159aa956-b8c5-4854-bafb-0002393c772b",
      "name": "menu",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "=http://backend:3000/categories/{{ $json.categoryId }}/products",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1056,
        -192
      ],
      "id": "41f13c6a-b0a8-452e-8968-38ec906c243d",
      "name": "Get Products by Category"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions\nSET data = data - 'optionsMap' - 'orderId'\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "={{ $('Compose Context').item.json.chatId  + ''}}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1504,
        -384
      ],
      "id": "7530c4e2-b7a6-459a-83cf-5f7c39684e1b",
      "name": "Erase data",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Render Products Menu').item.json.chatId }}",
        "text": "={{ $('Render Products Menu').item.json.menu }}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1728,
        -176
      ],
      "id": "1412bc91-775f-4264-8128-f92f59c4db34",
      "name": "Products Menu",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions\nSET \n  state = 'awaiting_product_menu_option',\n  data = jsonb_set(\n    COALESCE(data, '{}'::jsonb),\n    '{optionsMap}',\n    $2::jsonb,\n    true\n  )\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "={{ $('Compose Context').item.json.user.chatId + ''  }}, {{ $json.optionsMap }}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1504,
        -192
      ],
      "id": "e44d6e5b-e46a-4670-82ff-b3b613d1245d",
      "name": "Save Products Map",
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions \nSET state = 'awaiting_order_menu_option'\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "={{ $('Compose Context').item.json.chatId  + ''}}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1280,
        -832
      ],
      "id": "277411c9-84b0-4e14-8456-6b6201c432ae",
      "name": "Update State awaiting_order_menu_option",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions \nSET state = 'main_menu'\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "=={{ $json.chatId + '' }}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1280,
        -1168
      ],
      "id": "f58d64dc-fee8-42f9-96f6-d04436590962",
      "name": "Update State main_menu1",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions \nSET state = 'awaiting_main_menu_option'\nWHERE chat_id = $1;\n",
        "options": {
          "queryReplacement": "={{ $('Compose Context').item.json.chatId  + ''}}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1952,
        -864
      ],
      "id": "289cad03-f79a-44f0-8cfa-10e72e83eda1",
      "name": "Update State awaiting_main_menu_option",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const chatId = $json.chatId;\nconst text = $json.input.text;\n\nconst number = Number(text);\nconst optionsMap = $json.user.data?.optionsMap;\n\nif (!optionsMap) {\n  return [{\n    json: {\n      chatId,\n      error: \"no_options_map\"\n    }\n  }];\n}\n\nconst option = optionsMap[number];\n\nif (!option) {\n  return [{\n    json: {\n      chatId,\n      type: \"invalid\"\n    }\n  }];\n}\n\nreturn [{\n  json: {\n    chatId,\n    type: option.type,\n    productId: option.productId,\n    name: option.name,\n    price: option.price\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        384,
        352
      ],
      "id": "075efca2-0cf8-4d89-8600-083598696b47",
      "name": "Resolve Product Menu Option"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions \nSET state = 'checkout'\nWHERE chat_id = $1;\n",
        "options": {
          "queryReplacement": "={{ $('Compose Context').item.json.user.chatId + ''  }}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1056,
        0
      ],
      "id": "677886c2-aa5d-4758-83f5-ec33c8e3ebec",
      "name": "Update State checkout",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.chatId }}",
        "text": "\ud83d\udccd Qual \u00e9 o endere\u00e7o para entrega?",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1280,
        0
      ],
      "id": "75ff2c44-d2ae-47d1-97ee-f61654de1416",
      "name": "Endere\u00e7o de Entrega",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "e4043ff1-fdd4-4a2d-9fc6-5017f85a5110",
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "invalid",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "invalid"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "26542482-bb37-4dc9-9f16-c132c3d4ac97",
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "back",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "back"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "select_product",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "68acc263-1b7f-480d-a943-038dad379539"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "select_product"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        608,
        336
      ],
      "id": "9cd68022-c975-47bc-b909-ad5e0bc34c75",
      "name": "Product Menu Switch"
    },
    {
      "parameters": {
        "url": "=http://backend:3000/users/telegram/{{ $('Compose Context').item.json.user.chatId }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1504,
        -832
      ],
      "id": "87ca8649-6fbe-4852-86ac-7775f0484652",
      "name": "Get User"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://backend:3000/orders",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "user_id",
              "value": "={{$json.id}}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1728,
        -832
      ],
      "id": "c0a40b87-1413-43ab-a2a1-7396ad771f12",
      "name": "POST Order"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions\nSET data = jsonb_set(\n  COALESCE(data, '{}'::jsonb),\n  '{orderId}',\n  to_jsonb($2::int)\n)\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "={{ $('Compose Context').item.json.user.chatId + '' }}, {{$json.id}}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1952,
        -672
      ],
      "id": "07b838e1-7d2b-4d5c-90da-4cbb276e41c2",
      "name": "Save ChatId",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.chatId }}",
        "text": "Por favor, digite um dos n\u00fameros dispon\u00edveis no menu.",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1056,
        -528
      ],
      "id": "b46cf344-4243-408e-adc4-c66f18c01045",
      "name": "invalid",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.chatId }}",
        "text": "\ud83d\udd19 Voc\u00ea voltou ao seu pedido.",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1056,
        352
      ],
      "id": "e40c53c4-103c-479b-9271-be1ac3498fcd",
      "name": "back",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.user.chatId }}",
        "text": "=\u2705 {{ $('Product Menu Switch').item.json.name }} foi adicionado ao seu pedido!",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1056,
        544
      ],
      "id": "2bf78e40-728f-4cec-bfd1-3b232842bb29",
      "name": "Adicionado",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=http://backend:3000/orders/{{ $('Compose Context').item.json.user.data.orderId }}/items",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "productId",
              "value": "={{ $json.productId }}"
            },
            {
              "name": "quantity",
              "value": "1"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        832,
        544
      ],
      "id": "b894cb9a-73a1-43a7-818e-9a317818ce07",
      "name": "POST Item"
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "=http://backend:3000/orders/{{ $('Compose Context').item.json.user.data.orderId }}",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "address",
              "value": "={{ $('Compose Context').item.json.input.text }}"
            },
            {
              "name": "status",
              "value": "pedido_recebido"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        384,
        736
      ],
      "id": "1904bedb-c48a-4668-bd06-2f5e301a6679",
      "name": "PATCH Order"
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.user.chatId }}",
        "text": "\ud83c\udf89 Pedido realizado com sucesso!\n\nEm breve ele ser\u00e1 preparado e enviado para voc\u00ea.",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        608,
        736
      ],
      "id": "d651da27-c95f-4e5b-b7cb-7fc8ae924e82",
      "name": "Sucess",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "=http://backend:3000/orders/{{ $('Compose Context').item.json.user.data.orderId }}/summary",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        832,
        736
      ],
      "id": "ef36d734-2a46-4fe2-88fb-52a2096fe0f5",
      "name": "GET Order Summary"
    },
    {
      "parameters": {
        "jsCode": "const order = items[0].json;\n\nlet message = `\ud83e\uddfe Resumo do seu pedido #${order.order_number}\\n\\n`;\n\nfor (const item of order.items) {\n  message += `\u2022 ${item.quantity}x ${item.name} - R$ ${item.total_price.toFixed(2)}\\n`;\n}\n\nmessage += `\\n\ud83d\udcb0 Total: R$ ${order.total_price.toFixed(2)}`;\n\nif (order.payment) {\n  message += `\\n\ud83d\udcb3 Pagamento: ${order.payment}`;\n}\n\nif (order.address) {\n  message += `\\n\ud83d\udccd Entrega: ${order.address}`;\n}\n\nif (order.observation) {\n  message += `\\n\ud83d\udcdd Obs: ${order.observation}`;\n}\n\nreturn [\n  {\n    json: {\n      message\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1056,
        736
      ],
      "id": "66fb46ea-6ebc-4eec-a0e8-77a02bccbb64",
      "name": "Order Summary Message"
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.chatId }}",
        "text": "={{$json.message}}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1280,
        736
      ],
      "id": "4f5621a4-bca1-4d46-ae10-7d738f3a9884",
      "name": "Send Order Summary",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "order-status",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        -752,
        -528
      ],
      "id": "c08708a4-acfa-4580-b7c2-39b2b5ca5eb4",
      "name": "Webhook"
    },
    {
      "parameters": {
        "url": "=http://backend:3000/users/{{ $json.body.user_id }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -544,
        -528
      ],
      "id": "66f0356c-87df-4826-9c99-f93629ddba14",
      "name": "GET User"
    },
    {
      "parameters": {
        "jsCode": "const orderId = $('Webhook').first().json.body.order_id;\nconst status = $('Webhook').first().json.body.status;\nconst user = $json;\n\nlet message = \"\";\n\nswitch (status) {\n  case \"pedido_recebido\":\n    message = `\ud83e\uddfe Pedido #${orderId} recebido com sucesso!\\nEstamos organizando tudo para voc\u00ea.`;\n    break;\n\n  case \"em_preparo\":\n    message = `\ud83d\udc68\u200d\ud83c\udf73 Pedido #${orderId} est\u00e1 em preparo!\\nLogo logo sai quentinho \ud83c\udf55`;\n    break;\n\n  case \"a_caminho\":\n    message = `\ud83d\udef5 Pedido #${orderId} saiu para entrega!\\nFique atento \ud83d\ude09`;\n    break;\n\n  case \"finalizado\":\n    message = `\u2705 Pedido #${orderId} foi finalizado!\\nObrigado por pedir com a gente \ud83d\udc9a`;\n    break;\n\n  case \"cancelado\":\n    message = `\u274c Pedido #${orderId} foi cancelado.\\nSe precisar, estamos aqui.`;\n    break;\n\n  default:\n    message = `\ud83d\udce6 Pedido #${orderId} atualizado para: ${status}`;\n}\n\nreturn [\n  {\n    json: {\n      chat_id: user.telegram_chat_id,\n      text: message\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -336,
        -528
      ],
      "id": "28e846ed-0e74-4a89-8050-31a91689175c",
      "name": "Status Message"
    },
    {
      "parameters": {
        "chatId": "={{ $json.chat_id }}",
        "text": "={{ $json.text }}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -128,
        -528
      ],
      "id": "b6b9c8e0-6e1e-4e03-a1fe-6091b6a49bfc",
      "name": "Send a text message",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions\nSET data = data - 'optionsMap' - 'orderId'\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "={{ $('Compose Context').item.json.chatId  + ''}}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1504,
        736
      ],
      "id": "57aec508-efe0-4f54-ab66-2c377c2abf5f",
      "name": "Erase data1",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions \nSET state = 'main_menu'\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "={{ $('Compose Context').item.json.user.chatId }}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1712,
        736
      ],
      "id": "c56722ca-2e7d-40f2-b58d-13d64aec5024",
      "name": "Update State main_menu",
      "alwaysOutputData": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions \nSET state = 'get_order'\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "=={{ $json.chatId + '' }}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        1280,
        -1360
      ],
      "id": "444ef797-79b7-4dc9-935e-4246d21caa49",
      "name": "Update State get_order",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const order = items[0].json;\n\nfunction formatStatus(status) {\n  const map = {\n    carrinho: \"\ud83d\uded2 No carrinho\",\n    pedido_recebido: \"\ud83d\udce9 Pedido recebido\",\n    em_preparo: \"\ud83d\udc68\u200d\ud83c\udf73 Em preparo\",\n    a_caminho: \"\ud83d\ude9a A caminho\",\n    finalizado: \"\u2705 Finalizado\",\n    cancelado: \"\u274c Cancelado\"\n  };\n\n  return map[status] || status;\n}\n\nlet message = `\ud83e\uddfe Resumo do seu pedido #${order.order_number}\\n`;\nmessage += `\ud83d\udccc Status: ${formatStatus(order.status)}\\n\\n`;\n\nfor (const item of order.items) {\n  message += `\u2022 ${item.quantity}x ${item.name} - R$ ${item.total_price.toFixed(2)}\\n`;\n}\n\nmessage += `\\n\ud83d\udcb0 Total: R$ ${order.total_price.toFixed(2)}`;\n\nif (order.payment) {\n  message += `\\n\ud83d\udcb3 Pagamento: ${order.payment}`;\n}\n\nif (order.address) {\n  message += `\\n\ud83d\udccd Entrega: ${order.address}`;\n}\n\nif (order.observation) {\n  message += `\\n\ud83d\udcdd Obs: ${order.observation}`;\n}\n\nreturn [\n  {\n    json: {\n      message\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1344,
        -1824
      ],
      "id": "7d1ec307-2be1-48a0-9076-02381298a78b",
      "name": "Order Summary Message1"
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.chatId }}",
        "text": "={{$json.message}}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1568,
        -1824
      ],
      "id": "662d5515-311d-407e-bf99-ee80980eddc6",
      "name": "Send Order Summary1",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE user_sessions \nSET state = 'main_menu'\nWHERE chat_id = $1;",
        "options": {
          "queryReplacement": "=={{ $json.chatId + '' }}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        944,
        -1728
      ],
      "id": "2ac636c5-ca3e-4757-8bcd-b37d9f86cba2",
      "name": "Update State main_menu2",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "=http://backend:3000/orders/{{ $('Compose Context').item.json.input.text }}/summary",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1152,
        -1728
      ],
      "id": "6a45fd0b-71ce-49c5-a0fa-10bbb88e1247",
      "name": "GET Order Summary1",
      "alwaysOutputData": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "chatId": "={{ $('Compose Context').item.json.chatId }}",
        "text": "=\u274c N\u00e3o foi poss\u00edvel encontrar um pedido com esse n\u00famero.\nVerifique e tente novamente.",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1344,
        -1616
      ],
      "id": "3c12df9d-2f1a-422a-980b-fa1cd182ff0e",
      "name": "GET Order Error",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Save Main Menu State1": {
      "main": [
        [
          {
            "node": "Send Main Menu1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Build Main Menu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Render Products Menu": {
      "main": [
        [
          {
            "node": "Save Products Map",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Main Menu Switch": {
      "main": [
        [
          {
            "node": "Update State get_order",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update State main_menu1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update State awaiting_order_menu_option",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Erro",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Erro": {
      "main": [
        [
          {
            "node": "Update State awaiting_main_menu_option",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Update State main_menu2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Main Menu Switch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update State awaiting_order_menu_option",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update State awaiting_main_menu_option",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Resolve Order Menu Option",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Resolve Product Menu Option",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "PATCH Order",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Session": {
      "main": [
        [
          {
            "node": "Compose Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compose Context": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Input": {
      "main": [
        [
          {
            "node": "Search Session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Extract Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Categories": {
      "main": [
        [
          {
            "node": "Render Order Menu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Render Order Menu": {
      "main": [
        [
          {
            "node": "Save Options Map",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Options Map": {
      "main": [
        [
          {
            "node": "Order Menu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Resolve Order Menu Option": {
      "main": [
        [
          {
            "node": "Order Menu Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Order Menu Switch": {
      "main": [
        [
          {
            "node": "invalid",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Erase data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Products by Category",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update State checkout",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "menu": {
      "main": [
        [
          {
            "node": "Update State awaiting_main_menu_option",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Products by Category": {
      "main": [
        [
          {
            "node": "Render Products Menu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Erase data": {
      "main": [
        [
          {
            "node": "menu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Products Map": {
      "main": [
        [
          {
            "node": "Products Menu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update State awaiting_order_menu_option": {
      "main": [
        [
          {
            "node": "Get User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update State main_menu1": {
      "main": [
        [
          {
            "node": "falar_atendente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update State awaiting_main_menu_option": {
      "main": [
        [
          {
            "node": "main_menu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Resolve Product Menu Option": {
      "main": [
        [
          {
            "node": "Product Menu Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update State checkout": {
      "main": [
        [
          {
            "node": "Endere\u00e7o de Entrega",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Product Menu Switch": {
      "main": [
        [
          {
            "node": "invalid",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "back",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "POST Item",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get User": {
      "main": [
        [
          {
            "node": "POST Order",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "POST Order": {
      "main": [
        [
          {
            "node": "Save ChatId",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save ChatId": {
      "main": [
        [
          {
            "node": "Get Categories",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "invalid": {
      "main": [
        [
          {
            "node": "Update State awaiting_order_menu_option",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "back": {
      "main": [
        [
          {
            "node": "Update State awaiting_order_menu_option",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Adicionado": {
      "main": [
        [
          {
            "node": "Update State awaiting_order_menu_option",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "POST Item": {
      "main": [
        [
          {
            "node": "Adicionado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PATCH Order": {
      "main": [
        [
          {
            "node": "Sucess",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sucess": {
      "main": [
        [
          {
            "node": "GET Order Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET Order Summary": {
      "main": [
        [
          {
            "node": "Order Summary Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Order Summary Message": {
      "main": [
        [
          {
            "node": "Send Order Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Order Summary": {
      "main": [
        [
          {
            "node": "Erase data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "GET User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET User": {
      "main": [
        [
          {
            "node": "Status Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Status Message": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Erase data1": {
      "main": [
        [
          {
            "node": "Update State main_menu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update State get_order": {
      "main": [
        [
          {
            "node": "acompanhar_pedido",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Order Summary Message1": {
      "main": [
        [
          {
            "node": "Send Order Summary1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update State main_menu2": {
      "main": [
        [
          {
            "node": "GET Order Summary1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET Order Summary1": {
      "main": [
        [
          {
            "node": "Order Summary Message1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "GET Order Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "c842ec11-be0c-455d-8534-9b11b071bf03",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "ciEqBBemoolgt2Mg",
  "tags": []
}