n8n-nodes-aib 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,7 +48,6 @@ class AibDigital {
48
48
  defaults: { name: "AIB Digital" },
49
49
  // Vira ferramenta de agente de IA no n8n — o mesmo truque do nó
50
50
  // do Chatwoot que a Íris usa (chatwootTool).
51
- usableAsTool: true,
52
51
  inputs: ["main"],
53
52
  outputs: ["main"],
54
53
  credentials: [{ name: "aibDigitalApi", required: true }],
@@ -248,12 +247,13 @@ class AibDigital {
248
247
  description: "Lista de { nome, cor?, ganha?, perdida? } na ordem das colunas",
249
248
  },
250
249
  {
251
- displayName: "Ambiente (ID)",
250
+ displayName: "Ambiente",
252
251
  name: "ambienteId",
253
- type: "string",
252
+ type: "options",
253
+ typeOptions: { loadOptionsMethod: "getAmbientes", loadOptionsDependsOn: ["conta"] },
254
254
  default: "",
255
- displayOptions: { show: { operation: ["criarFunil"] } },
256
- description: "Obrigatório só quando a conta tem 2+ ambientes",
255
+ displayOptions: { show: { operation: ["selecionarConta", "criarFunil"] } },
256
+ description: "Onde o funil/dado vai nascer. Conta com 2+ ambientes exige escolher aqui.",
257
257
  },
258
258
  {
259
259
  displayName: "Funil",
@@ -337,6 +337,20 @@ class AibDigital {
337
337
  return [{ name: "— A conta da chave —", value: "" }];
338
338
  }
339
339
  },
340
+ async getAmbientes() {
341
+ const conta = this.getNodeParameter("conta", "");
342
+ try {
343
+ const res = await api(this, "GET", "/api/v1/ambientes", undefined, conta ? { conta } : undefined);
344
+ const ambientes = (res?.ambientes ?? []);
345
+ if (ambientes.length <= 1) {
346
+ return [{ name: "— Único ambiente da conta —", value: ambientes[0]?.id ?? "" }];
347
+ }
348
+ return ambientes.map((a) => ({ name: a.nome, value: a.id }));
349
+ }
350
+ catch {
351
+ return [{ name: "— Único ambiente da conta —", value: "" }];
352
+ }
353
+ },
340
354
  async getFunis() {
341
355
  const conta = this.getNodeParameter("conta", "");
342
356
  const res = await api(this, "GET", "/api/v1/funis", undefined, conta ? { conta } : undefined);
@@ -447,20 +461,25 @@ class AibDigital {
447
461
  res = await api(this, "PATCH", `/api/v1/contatos/${contatoId}`, campos, qs);
448
462
  }
449
463
  else if (operation === "selecionarConta") {
450
- // A âncora do fluxo, como o "Selecionar conta" do Chatwoot: devolve a
451
- // conta escolhida para os nós seguintes referenciarem por expressão.
464
+ // A âncora do fluxo: devolve a conta E o ambiente escolhidos para os
465
+ // nós seguintes referenciarem ($('Selecionar conta').item.json.id e
466
+ // .ambiente_id). É onde o funil vai nascer.
452
467
  const contaSel = this.getNodeParameter("conta", i, "");
468
+ const ambienteSel = this.getNodeParameter("ambienteId", i, "");
469
+ let base;
453
470
  if (contaSel) {
454
471
  const r = await api(this, "GET", "/api/v1/contas");
455
472
  const achada = (r?.contas ?? []).find((c) => c.id === contaSel);
456
473
  if (!achada)
457
474
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Conta não encontrada para esta chave");
458
- res = achada;
475
+ base = { ...achada };
459
476
  }
460
477
  else {
461
478
  const ping = await api(this, "GET", "/api/v1/ping");
462
- res = { id: "", nome: "— a conta da chave —", escopo: ping?.escopo };
479
+ base = { id: "", nome: "— a conta da chave —", escopo: ping?.escopo };
463
480
  }
481
+ base.ambiente_id = ambienteSel || null;
482
+ res = base;
464
483
  }
465
484
  else {
466
485
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operação desconhecida: ${operation}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-aib",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "Nós do Sistema AIB Digital para n8n: gatilho de mensagens do WhatsApp (via AIB Inbox) e ações — enviar mensagem, mover card no funil, pausar IA — escolhendo conta e caixa por dropdown.",
5
5
  "license": "MIT",
6
6
  "author": "AIB Digital",