n8n-nodes-aib 0.4.0 → 0.4.2
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.
|
@@ -6,14 +6,30 @@ const n8n_workflow_1 = require("n8n-workflow");
|
|
|
6
6
|
async function api(ctx, method, path, body, qs) {
|
|
7
7
|
const cred = (await ctx.getCredentials("aibDigitalApi"));
|
|
8
8
|
const base = String(cred.baseUrl).replace(/\/+$/, "");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
try {
|
|
10
|
+
return await ctx.helpers.httpRequest({
|
|
11
|
+
method,
|
|
12
|
+
url: `${base}${path}`,
|
|
13
|
+
qs,
|
|
14
|
+
body,
|
|
15
|
+
json: true,
|
|
16
|
+
headers: { Authorization: `Bearer ${cred.apiKey}` },
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
// A API responde { error: "..." } com a causa real; o axios do n8n
|
|
21
|
+
// esconde isso atrás de "Request failed with status code 400".
|
|
22
|
+
// Traz a mensagem de verdade para o usuário.
|
|
23
|
+
const corpo = e?.response?.body ?? e?.cause?.response?.body;
|
|
24
|
+
const msg = (corpo && typeof corpo === "object" && (corpo.error || corpo.message)) ||
|
|
25
|
+
(typeof corpo === "string" && corpo) ||
|
|
26
|
+
e?.message;
|
|
27
|
+
const status = e?.httpCode ?? e?.response?.status ?? e?.cause?.response?.status;
|
|
28
|
+
throw new n8n_workflow_1.NodeApiError(ctx.getNode(), e, {
|
|
29
|
+
message: status ? `AIB (${status}): ${msg}` : `AIB: ${msg}`,
|
|
30
|
+
description: "Resposta do Sistema AIB Digital",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
17
33
|
}
|
|
18
34
|
/** A conta escolhida no nó (vazio = a conta da própria chave). */
|
|
19
35
|
function contaQs(ctx, i) {
|
|
@@ -338,7 +354,21 @@ class AibDigital {
|
|
|
338
354
|
async execute() {
|
|
339
355
|
const items = this.getInputData();
|
|
340
356
|
const out = [];
|
|
341
|
-
|
|
357
|
+
let operation = this.getNodeParameter("operation", 0);
|
|
358
|
+
// Autocorreção: ao atualizar o pacote, o n8n às vezes perde a operação
|
|
359
|
+
// salva e injeta o "__CUSTOM_API_CALL__" da auth genérica. Em vez de
|
|
360
|
+
// falhar, assumimos a operação natural do recurso escolhido.
|
|
361
|
+
if (operation === "__CUSTOM_API_CALL__") {
|
|
362
|
+
const recurso = this.getNodeParameter("recurso", 0, "conversa");
|
|
363
|
+
const padrao = {
|
|
364
|
+
conta: "selecionarConta",
|
|
365
|
+
conversa: "listarConversas",
|
|
366
|
+
mensagem: "enviarMensagem",
|
|
367
|
+
contato: "atualizarContato",
|
|
368
|
+
funil: "criarFunil",
|
|
369
|
+
};
|
|
370
|
+
operation = padrao[recurso] ?? "selecionarConta";
|
|
371
|
+
}
|
|
342
372
|
for (let i = 0; i < items.length; i++) {
|
|
343
373
|
const qs = contaQs(this, i);
|
|
344
374
|
let res;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-aib",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
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",
|