Pular para conteúdo

ACCUMULATOR - Acumular Valores

O que é este Node?

O ACCUMULATOR é o node responsável por acumular valores numéricos em uma variável através de operações matemáticas (soma, subtração, multiplicação, divisão) ou resetar o contador.

Por que este Node existe?

Muitos flows precisam manter contadores ou totalizadores. O ACCUMULATOR existe para:

  1. Contadores: Contar quantas vezes algo aconteceu (tentativas, mensagens, cliques)
  2. Totalizadores: Somar valores ao longo do flow (valor total do carrinho, pontos acumulados)
  3. Operações matemáticas: Realizar cálculos progressivos com valores dinâmicos
  4. Estatísticas: Manter métricas durante a execução do flow
  5. Controle de loops: Incrementar/decrementar contadores de iteração

Como funciona internamente?

Quando o ACCUMULATOR é executado, o sistema:

  1. Lê o valor atual da variável (se não existir, assume 0)
  2. Identifica a operação (add, subtract, multiply, divide, reset)
  3. Aplica a operação usando o valor fornecido
  4. Atualiza a variável com o novo valor calculado
  5. Retorna resultado com valor anterior e novo valor
  6. Continua o flow com a variável atualizada no contexto

Código interno (logic-control-executor.service.ts:197-237):

private async executeAccumulator(parameters: any, context: any): Promise<any> {
  const { name, value, operation } = parameters;

  this.logger.log(`📊 ACCUMULATOR - ${operation || 'add'}: ${name} += ${value}`);

  const currentVariables = context.variables || {};
  const currentValue = currentVariables[name] || 0;
  let newValue;

  switch (operation) {
    case 'add':
      newValue = currentValue + (value || 0);
      break;
    case 'subtract':
      newValue = currentValue - (value || 0);
      break;
    case 'multiply':
      newValue = currentValue * (value || 1);
      break;
    case 'divide':
      newValue = currentValue / (value || 1);
      break;
    case 'reset':
      newValue = 0;
      break;
    default:
      newValue = currentValue + (value || 0);
  }

  return {
    success: true,
    action: 'accumulator_updated',
    accumulator: {
      name: name,
      previousValue: currentValue,
      newValue: newValue,
      operation: operation || 'add'
    },
    timestamp: new Date().toISOString()
  };
}

Quando você DEVE usar este Node?

Use ACCUMULATOR sempre que precisar de contadores ou totalizadores:

Casos de uso:

  1. Contador de tentativas: "Você já tentou 3 vezes"
  2. Total do carrinho: Somar preços de produtos escolhidos
  3. Sistema de pontos: Acumular pontos durante interação
  4. Limite de ações: Contar quantas vezes usuário fez algo
  5. Estatísticas de uso: Manter métricas durante o flow
  6. Controle de loops: Incrementar contador de iterações

Quando NÃO usar ACCUMULATOR:

  • Cálculos simples únicos: Use VARIABLE com expressão matemática
  • Comparações: Use CONDITION
  • Valores que não acumulam: Use VARIABLE para atribuição simples

Parâmetros Detalhados

name (string, obrigatório)

O que é: Nome da variável que será usada como acumulador.

Flow completo para testar:

{
  "name": "Teste ACCUMULATOR - Name",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Iniciar Contador",
        "parameters": {
          "name": "contador",
          "value": 1,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Mostrar Valor",
        "parameters": {
          "message": "Contador: {{contador}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 700, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Teste: A variável "contador" começará em 0 e será incrementada para 1.

value (number, obrigatório para operações matemáticas)

O que é: Valor que será usado na operação matemática.

Padrão: 0 para add/subtract, 1 para multiply/divide

Flow completo para testar:

{
  "name": "Teste ACCUMULATOR - Value",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Somar 10",
        "parameters": {
          "name": "total",
          "value": 10,
          "operation": "add"
        }
      }
    },
    {
      "id": "accumulator_2",
      "type": "accumulator",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Somar 25",
        "parameters": {
          "name": "total",
          "value": 25,
          "operation": "add"
        }
      }
    },
    {
      "id": "accumulator_3",
      "type": "accumulator",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Somar 15",
        "parameters": {
          "name": "total",
          "value": 15,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Total",
        "parameters": {
          "message": "Total acumulado: R$ {{total}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1100, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "accumulator_2" },
    { "source": "accumulator_2", "target": "accumulator_3" },
    { "source": "accumulator_3", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Teste: O total será 0 + 10 + 25 + 15 = 50.

operation (string, opcional)

O que é: Operação matemática a ser realizada.

Padrão: "add"

Valores aceitos: add, subtract, multiply, divide, reset

operation: "add" (Soma)

Flow completo para testar:

{
  "name": "Teste ACCUMULATOR - Add",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Adicionar 5",
        "parameters": {
          "name": "pontos",
          "value": 5,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Pontos",
        "parameters": {
          "message": "Pontos: {{pontos}}"
        }
      }
    },
    {
      "id": "accumulator_2",
      "type": "accumulator",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Adicionar 3",
        "parameters": {
          "name": "pontos",
          "value": 3,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_2",
      "type": "message",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Total",
        "parameters": {
          "message": "Total de pontos: {{pontos}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1100, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "message_1" },
    { "source": "message_1", "target": "accumulator_2" },
    { "source": "accumulator_2", "target": "message_2" },
    { "source": "message_2", "target": "end_1" }
  ]
}

Teste: Pontos começa em 0, adiciona 5 (=5), depois adiciona 3 (=8).

operation: "subtract" (Subtração)

Flow completo para testar:

{
  "name": "Teste ACCUMULATOR - Subtract",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "variable_1",
      "type": "variable",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Saldo Inicial",
        "parameters": {
          "name": "saldo",
          "value": 100
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Saldo Inicial",
        "parameters": {
          "message": "Saldo inicial: R$ {{saldo}}"
        }
      }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Descontar 30",
        "parameters": {
          "name": "saldo",
          "value": 30,
          "operation": "subtract"
        }
      }
    },
    {
      "id": "message_2",
      "type": "message",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Saldo Final",
        "parameters": {
          "message": "Saldo após desconto: R$ {{saldo}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1100, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "variable_1" },
    { "source": "variable_1", "target": "message_1" },
    { "source": "message_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "message_2" },
    { "source": "message_2", "target": "end_1" }
  ]
}

Teste: Saldo começa em 100, subtrai 30, resultado final: 70.

operation: "multiply" (Multiplicação)

Flow completo para testar:

{
  "name": "Teste ACCUMULATOR - Multiply",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "variable_1",
      "type": "variable",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Valor Base",
        "parameters": {
          "name": "valor",
          "value": 10
        }
      }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Multiplicar por 5",
        "parameters": {
          "name": "valor",
          "value": 5,
          "operation": "multiply"
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Resultado",
        "parameters": {
          "message": "10 x 5 = {{valor}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 900, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "variable_1" },
    { "source": "variable_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Teste: Valor começa em 10, multiplica por 5, resultado: 50.

operation: "divide" (Divisão)

Flow completo para testar:

{
  "name": "Teste ACCUMULATOR - Divide",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "variable_1",
      "type": "variable",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Valor Total",
        "parameters": {
          "name": "total",
          "value": 100
        }
      }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Dividir por 4",
        "parameters": {
          "name": "total",
          "value": 4,
          "operation": "divide"
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Resultado",
        "parameters": {
          "message": "100 / 4 = {{total}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 900, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "variable_1" },
    { "source": "variable_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Teste: Total começa em 100, divide por 4, resultado: 25.

operation: "reset" (Resetar para 0)

Flow completo para testar:

{
  "name": "Teste ACCUMULATOR - Reset",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Incrementar",
        "parameters": {
          "name": "contador",
          "value": 1,
          "operation": "add"
        }
      }
    },
    {
      "id": "accumulator_2",
      "type": "accumulator",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Incrementar",
        "parameters": {
          "name": "contador",
          "value": 1,
          "operation": "add"
        }
      }
    },
    {
      "id": "accumulator_3",
      "type": "accumulator",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Incrementar",
        "parameters": {
          "name": "contador",
          "value": 1,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Antes Reset",
        "parameters": {
          "message": "Contador antes do reset: {{contador}}"
        }
      }
    },
    {
      "id": "accumulator_4",
      "type": "accumulator",
      "position": { "x": 1100, "y": 100 },
      "data": {
        "label": "Resetar",
        "parameters": {
          "name": "contador",
          "operation": "reset"
        }
      }
    },
    {
      "id": "message_2",
      "type": "message",
      "position": { "x": 1300, "y": 100 },
      "data": {
        "label": "Após Reset",
        "parameters": {
          "message": "Contador após reset: {{contador}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1500, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "accumulator_2" },
    { "source": "accumulator_2", "target": "accumulator_3" },
    { "source": "accumulator_3", "target": "message_1" },
    { "source": "message_1", "target": "accumulator_4" },
    { "source": "accumulator_4", "target": "message_2" },
    { "source": "message_2", "target": "end_1" }
  ]
}

Teste: Contador chega a 3, depois do reset volta para 0.

Parâmetros

Campo Tipo Obrigatório Descrição
name string Sim Nome da variável acumuladora
value number Condicional Valor usado na operação (obrigatório exceto para reset)
operation string Não add, subtract, multiply, divide, reset (padrão: add)

Exemplo 1: Carrinho de Compras

Objetivo: Calcular total de produtos escolhidos

JSON para Importar

{
  "name": "Carrinho com ACCUMULATOR",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Boas-vindas",
        "parameters": {
          "message": "Bem-vindo! Vou adicionar produtos ao seu carrinho."
        }
      }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Produto 1",
        "parameters": {
          "name": "total_carrinho",
          "value": 49.90,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_2",
      "type": "message",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Produto Adicionado",
        "parameters": {
          "message": "Camiseta adicionada (R$ 49,90)\nTotal: R$ {{total_carrinho}}"
        }
      }
    },
    {
      "id": "accumulator_2",
      "type": "accumulator",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Produto 2",
        "parameters": {
          "name": "total_carrinho",
          "value": 129.90,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_3",
      "type": "message",
      "position": { "x": 1100, "y": 100 },
      "data": {
        "label": "Produto Adicionado",
        "parameters": {
          "message": "Calça adicionada (R$ 129,90)\nTotal: R$ {{total_carrinho}}"
        }
      }
    },
    {
      "id": "accumulator_3",
      "type": "accumulator",
      "position": { "x": 1300, "y": 100 },
      "data": {
        "label": "Produto 3",
        "parameters": {
          "name": "total_carrinho",
          "value": 89.90,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_4",
      "type": "message",
      "position": { "x": 1500, "y": 100 },
      "data": {
        "label": "Total Final",
        "parameters": {
          "message": "Tênis adicionado (R$ 89,90)\n\n🛒 TOTAL DO CARRINHO: R$ {{total_carrinho}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1700, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "message_1" },
    { "source": "message_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "message_2" },
    { "source": "message_2", "target": "accumulator_2" },
    { "source": "accumulator_2", "target": "message_3" },
    { "source": "message_3", "target": "accumulator_3" },
    { "source": "accumulator_3", "target": "message_4" },
    { "source": "message_4", "target": "end_1" }
  ]
}

Saída esperada:

Sistema: Bem-vindo! Vou adicionar produtos ao seu carrinho.
Sistema: Camiseta adicionada (R$ 49,90)
         Total: R$ 49.9
Sistema: Calça adicionada (R$ 129,90)
         Total: R$ 179.8
Sistema: Tênis adicionado (R$ 89,90)
         🛒 TOTAL DO CARRINHO: R$ 269.7

Exemplo 2: Sistema de Tentativas com Limite

Objetivo: Controlar número de tentativas e bloquear após limite

JSON para Importar

{
  "name": "Contador de Tentativas",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Incrementar Tentativas",
        "parameters": {
          "name": "tentativas",
          "value": 1,
          "operation": "add"
        }
      }
    },
    {
      "id": "input_1",
      "type": "input",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Pedir Senha",
        "parameters": {
          "message": "Digite a senha (Tentativa {{tentativas}}/3):",
          "variable": "senha"
        }
      }
    },
    {
      "id": "condition_1",
      "type": "condition",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Verificar Senha",
        "parameters": {
          "variable": "senha",
          "operator": "equals",
          "value": "1234"
        }
      }
    },
    {
      "id": "message_success",
      "type": "message",
      "position": { "x": 900, "y": 0 },
      "data": {
        "label": "Sucesso",
        "parameters": {
          "message": "✅ Senha correta! Acesso liberado."
        }
      }
    },
    {
      "id": "condition_2",
      "type": "condition",
      "position": { "x": 900, "y": 200 },
      "data": {
        "label": "Checar Limite",
        "parameters": {
          "variable": "tentativas",
          "operator": "less_than",
          "value": 3
        }
      }
    },
    {
      "id": "message_retry",
      "type": "message",
      "position": { "x": 1100, "y": 150 },
      "data": {
        "label": "Tentar Novamente",
        "parameters": {
          "message": "❌ Senha incorreta. Tente novamente."
        }
      }
    },
    {
      "id": "message_blocked",
      "type": "message",
      "position": { "x": 1100, "y": 250 },
      "data": {
        "label": "Bloqueado",
        "parameters": {
          "message": "🚫 Limite de tentativas excedido! Acesso bloqueado."
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1300, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "input_1" },
    { "source": "input_1", "target": "condition_1" },
    { "source": "condition_1", "sourceHandle": "true", "target": "message_success" },
    { "source": "condition_1", "sourceHandle": "false", "target": "condition_2" },
    { "source": "condition_2", "sourceHandle": "true", "target": "message_retry" },
    { "source": "condition_2", "sourceHandle": "false", "target": "message_blocked" },
    { "source": "message_retry", "target": "accumulator_1" },
    { "source": "message_success", "target": "end_1" },
    { "source": "message_blocked", "target": "end_1" }
  ]
}

Saída esperada:

Sistema: Digite a senha (Tentativa 1/3):
Usuário: 5678
Sistema: ❌ Senha incorreta. Tente novamente.
Sistema: Digite a senha (Tentativa 2/3):
Usuário: 9999
Sistema: ❌ Senha incorreta. Tente novamente.
Sistema: Digite a senha (Tentativa 3/3):
Usuário: 0000
Sistema: 🚫 Limite de tentativas excedido! Acesso bloqueado.

Exemplo 3: Sistema de Pontos Gamificado

Objetivo: Acumular pontos com multiplicador de bônus

JSON para Importar

{
  "name": "Sistema de Pontos",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Início",
        "parameters": {
          "message": "🎮 Bem-vindo ao Sistema de Pontos!"
        }
      }
    },
    {
      "id": "accumulator_1",
      "type": "accumulator",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Ação 1",
        "parameters": {
          "name": "pontos",
          "value": 10,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_2",
      "type": "message",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Ganhou Pontos",
        "parameters": {
          "message": "✅ +10 pontos! Total: {{pontos}}"
        }
      }
    },
    {
      "id": "accumulator_2",
      "type": "accumulator",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Ação 2",
        "parameters": {
          "name": "pontos",
          "value": 20,
          "operation": "add"
        }
      }
    },
    {
      "id": "message_3",
      "type": "message",
      "position": { "x": 1100, "y": 100 },
      "data": {
        "label": "Ganhou Pontos",
        "parameters": {
          "message": "✅ +20 pontos! Total: {{pontos}}"
        }
      }
    },
    {
      "id": "message_4",
      "type": "message",
      "position": { "x": 1300, "y": 100 },
      "data": {
        "label": "Bônus",
        "parameters": {
          "message": "🌟 BÔNUS ATIVADO! Seus pontos serão DOBRADOS!"
        }
      }
    },
    {
      "id": "accumulator_3",
      "type": "accumulator",
      "position": { "x": 1500, "y": 100 },
      "data": {
        "label": "Aplicar Bônus 2x",
        "parameters": {
          "name": "pontos",
          "value": 2,
          "operation": "multiply"
        }
      }
    },
    {
      "id": "message_5",
      "type": "message",
      "position": { "x": 1700, "y": 100 },
      "data": {
        "label": "Total Final",
        "parameters": {
          "message": "🏆 PONTUAÇÃO FINAL: {{pontos}} pontos!"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1900, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "message_1" },
    { "source": "message_1", "target": "accumulator_1" },
    { "source": "accumulator_1", "target": "message_2" },
    { "source": "message_2", "target": "accumulator_2" },
    { "source": "accumulator_2", "target": "message_3" },
    { "source": "message_3", "target": "message_4" },
    { "source": "message_4", "target": "accumulator_3" },
    { "source": "accumulator_3", "target": "message_5" },
    { "source": "message_5", "target": "end_1" }
  ]
}

Saída esperada:

Sistema: 🎮 Bem-vindo ao Sistema de Pontos!
Sistema: ✅ +10 pontos! Total: 10
Sistema: ✅ +20 pontos! Total: 30
Sistema: 🌟 BÔNUS ATIVADO! Seus pontos serão DOBRADOS!
Sistema: 🏆 PONTUAÇÃO FINAL: 60 pontos!

Resposta do Node

{
  "success": true,
  "action": "accumulator_updated",
  "accumulator": {
    "name": "contador",
    "previousValue": 5,
    "newValue": 8,
    "operation": "add"
  },
  "timestamp": "2025-01-15T10:30:00.000Z"
}

Operações Matemáticas

Operação Exemplo Resultado
add 10 + 5 15
subtract 10 - 3 7
multiply 10 * 2 20
divide 10 / 2 5
reset qualquer → 0

Boas Práticas

SIM:

  • Use nomes descritivos para acumuladores (contador_tentativas, total_carrinho, pontos_usuario)
  • Inicialize variáveis com VARIABLE antes de usar ACCUMULATOR se precisar valor inicial diferente de 0
  • Use reset para zerar contadores quando necessário
  • Combine com CONDITION para verificar limites
  • Use subtract para decrementar (estoque, tentativas restantes)

NÃO:

  • Não divida por zero (causará erro)
  • Não misture operações sem planejamento (dificulta debug)
  • Não use ACCUMULATOR para valores que não acumulam (use VARIABLE)
  • Não esqueça de validar limites em contadores

Dicas

💡 Contador de iterações: Use com LOOP para controlar quantas vezes algo repetiu

💡 Carrinho de compras: Soma valores de produtos, usa subtract para descontos

💡 Sistema de tentativas: Incrementa até limite, depois bloqueia com CONDITION

💡 Estatísticas: Mantenha contadores de ações (mensagens enviadas, cliques, etc)

💡 Multiplicadores: Use multiply para aplicar bônus (2x, 3x pontos)

💡 Reset estratégico: Use reset para recomeçar contadores em novos ciclos

Casos de Uso Comuns

Contador Simples

Operação: add
Valor: 1
Uso: Contar eventos (tentativas, cliques, mensagens)

Totalizador Financeiro

Operação: add
Valor: preço_produto
Uso: Somar valores de carrinho, pedidos

Estoque

Operação: subtract
Valor: quantidade_vendida
Uso: Diminuir estoque disponível

Aplicar Desconto

Operação: multiply
Valor: 0.9 (10% desconto)
Uso: Aplicar percentual de desconto

Dividir Conta

Operação: divide
Valor: numero_pessoas
Uso: Dividir valor entre pessoas

Reiniciar Jogo

Operação: reset
Uso: Zerar pontos no início de novo jogo

Próximo Node

SCHEDULE - Agendar execução futura → LOOP - Repetir ações com contador → VARIABLE - Criar e manipular variáveis