n8n-nodes-aib 0.4.1 → 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
|
|
250
|
+
displayName: "Ambiente",
|
|
252
251
|
name: "ambienteId",
|
|
253
|
-
type: "
|
|
252
|
+
type: "options",
|
|
253
|
+
typeOptions: { loadOptionsMethod: "getAmbientes", loadOptionsDependsOn: ["conta"] },
|
|
254
254
|
default: "",
|
|
255
|
-
displayOptions: { show: { operation: ["criarFunil"] } },
|
|
256
|
-
description: "
|
|
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);
|
|
@@ -354,7 +368,21 @@ class AibDigital {
|
|
|
354
368
|
async execute() {
|
|
355
369
|
const items = this.getInputData();
|
|
356
370
|
const out = [];
|
|
357
|
-
|
|
371
|
+
let operation = this.getNodeParameter("operation", 0);
|
|
372
|
+
// Autocorreção: ao atualizar o pacote, o n8n às vezes perde a operação
|
|
373
|
+
// salva e injeta o "__CUSTOM_API_CALL__" da auth genérica. Em vez de
|
|
374
|
+
// falhar, assumimos a operação natural do recurso escolhido.
|
|
375
|
+
if (operation === "__CUSTOM_API_CALL__") {
|
|
376
|
+
const recurso = this.getNodeParameter("recurso", 0, "conversa");
|
|
377
|
+
const padrao = {
|
|
378
|
+
conta: "selecionarConta",
|
|
379
|
+
conversa: "listarConversas",
|
|
380
|
+
mensagem: "enviarMensagem",
|
|
381
|
+
contato: "atualizarContato",
|
|
382
|
+
funil: "criarFunil",
|
|
383
|
+
};
|
|
384
|
+
operation = padrao[recurso] ?? "selecionarConta";
|
|
385
|
+
}
|
|
358
386
|
for (let i = 0; i < items.length; i++) {
|
|
359
387
|
const qs = contaQs(this, i);
|
|
360
388
|
let res;
|
|
@@ -433,23 +461,25 @@ class AibDigital {
|
|
|
433
461
|
res = await api(this, "PATCH", `/api/v1/contatos/${contatoId}`, campos, qs);
|
|
434
462
|
}
|
|
435
463
|
else if (operation === "selecionarConta") {
|
|
436
|
-
// A âncora do fluxo
|
|
437
|
-
//
|
|
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.
|
|
438
467
|
const contaSel = this.getNodeParameter("conta", i, "");
|
|
468
|
+
const ambienteSel = this.getNodeParameter("ambienteId", i, "");
|
|
469
|
+
let base;
|
|
439
470
|
if (contaSel) {
|
|
440
471
|
const r = await api(this, "GET", "/api/v1/contas");
|
|
441
472
|
const achada = (r?.contas ?? []).find((c) => c.id === contaSel);
|
|
442
473
|
if (!achada)
|
|
443
474
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Conta não encontrada para esta chave");
|
|
444
|
-
|
|
475
|
+
base = { ...achada };
|
|
445
476
|
}
|
|
446
477
|
else {
|
|
447
478
|
const ping = await api(this, "GET", "/api/v1/ping");
|
|
448
|
-
|
|
479
|
+
base = { id: "", nome: "— a conta da chave —", escopo: ping?.escopo };
|
|
449
480
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Escolha o Recurso e a Operação no nó (o n8n perdeu a seleção ao atualizar o pacote).", { description: "Reabra o nó, selecione Recurso → Operação e salve." });
|
|
481
|
+
base.ambiente_id = ambienteSel || null;
|
|
482
|
+
res = base;
|
|
453
483
|
}
|
|
454
484
|
else {
|
|
455
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.
|
|
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",
|