@ivanlaomarketing/n8n-nodes-risveglia 0.3.0 → 0.4.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RisveglIa = exports.parametriDi = exports.risorsaDi = void 0;
|
|
3
|
+
exports.RisveglIa = exports.OPERAZIONE_NUMERO = exports.parametriDi = exports.risorsaDi = void 0;
|
|
4
|
+
exports.corpoNumero = corpoNumero;
|
|
4
5
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
6
|
const catalogo_1 = require("./catalogo");
|
|
6
7
|
const richiesta_1 = require("./richiesta");
|
|
@@ -33,6 +34,121 @@ const esempiQuery = {
|
|
|
33
34
|
"invii.elenca": { conversationId: "" },
|
|
34
35
|
"allegati.elenca": { messageId: "" },
|
|
35
36
|
};
|
|
37
|
+
/** «Invia a un numero» ha campi suoi al posto del corpo JSON: numero mittente e template si scelgono da elenchi. */
|
|
38
|
+
exports.OPERAZIONE_NUMERO = "numero.invia";
|
|
39
|
+
const suNumero = { show: { operation: [exports.OPERAZIONE_NUMERO] } };
|
|
40
|
+
const coppie = (displayName, name, description) => ({
|
|
41
|
+
displayName,
|
|
42
|
+
name,
|
|
43
|
+
type: "fixedCollection",
|
|
44
|
+
typeOptions: { multipleValues: true },
|
|
45
|
+
default: {},
|
|
46
|
+
displayOptions: suNumero,
|
|
47
|
+
description,
|
|
48
|
+
options: [
|
|
49
|
+
{
|
|
50
|
+
name: "voce",
|
|
51
|
+
displayName: "Variabile",
|
|
52
|
+
values: [
|
|
53
|
+
{ displayName: "Variabile", name: "chiave", type: "string", default: "", description: "1, 2… per il testo, header:1 per l'intestazione, button:0 per un link" },
|
|
54
|
+
{ displayName: "Valore", name: "valore", type: "string", default: "" },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
function campiNumero() {
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
|
|
63
|
+
displayName: "Numero Mittente",
|
|
64
|
+
name: "numeroMittente",
|
|
65
|
+
type: "options",
|
|
66
|
+
typeOptions: { loadOptionsMethod: "numeriCanali" },
|
|
67
|
+
required: true,
|
|
68
|
+
default: "",
|
|
69
|
+
displayOptions: suNumero,
|
|
70
|
+
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-options
|
|
71
|
+
description: "Tra parentesi i canali collegati adesso: QR, API o tutti e due. Scegli dall'elenco o usa un'espressione.",
|
|
72
|
+
},
|
|
73
|
+
{ displayName: "Telefono Destinatario", name: "telefono", type: "string", default: "", displayOptions: suNumero, description: "Con il prefisso internazionale (senza prefisso vale l'Italia). In alternativa compila la chat." },
|
|
74
|
+
{ displayName: "Chat", name: "chatId", type: "string", default: "", displayOptions: suNumero, description: "ID di una chat già in archivio sul numero mittente, al posto del telefono" },
|
|
75
|
+
{
|
|
76
|
+
displayName: "Canale",
|
|
77
|
+
name: "canale",
|
|
78
|
+
type: "options",
|
|
79
|
+
default: "automatico",
|
|
80
|
+
displayOptions: suNumero,
|
|
81
|
+
options: [
|
|
82
|
+
{ name: "Automatico", value: "automatico", description: "Con un testo: API se il contatto ha scritto nelle ultime 24 ore, altrimenti QR code. Con un template: API." },
|
|
83
|
+
{ name: "Collegamento Con QR Code", value: "qr" },
|
|
84
|
+
{ name: "WhatsApp Business API", value: "api" },
|
|
85
|
+
],
|
|
86
|
+
description: "Se il canale scelto non è collegato l'invio si rifiuta, senza ripieghi",
|
|
87
|
+
},
|
|
88
|
+
{ displayName: "Testo", name: "testo", type: "string", typeOptions: { rows: 4 }, default: "", displayOptions: suNumero, description: "Compila il testo oppure il template, non tutti e due" },
|
|
89
|
+
{
|
|
90
|
+
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
|
|
91
|
+
displayName: "Template",
|
|
92
|
+
name: "template",
|
|
93
|
+
type: "options",
|
|
94
|
+
typeOptions: { loadOptionsMethod: "templateNumero", loadOptionsDependsOn: ["numeroMittente"] },
|
|
95
|
+
default: "",
|
|
96
|
+
displayOptions: suNumero,
|
|
97
|
+
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-options
|
|
98
|
+
description: "Solo i template approvati del numero scelto: si creano e si modificano nel portale o da un assistente collegato",
|
|
99
|
+
},
|
|
100
|
+
coppie("Variabili del template", "variabili", "Valori delle variabili del template"),
|
|
101
|
+
{ displayName: "File Libreria Media", name: "mediaId", type: "string", default: "", displayOptions: suNumero, description: "ID di un file della libreria: allegato del testo via QR o intestazione del template" },
|
|
102
|
+
{
|
|
103
|
+
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
|
|
104
|
+
displayName: "Template Alternativo",
|
|
105
|
+
name: "templateRiserva",
|
|
106
|
+
type: "options",
|
|
107
|
+
typeOptions: { loadOptionsMethod: "templateNumero", loadOptionsDependsOn: ["numeroMittente"] },
|
|
108
|
+
default: "",
|
|
109
|
+
displayOptions: suNumero,
|
|
110
|
+
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-options
|
|
111
|
+
description: "Canale Automatico con un testo, fuori dalle 24 ore e senza QR code: parte questo template invece di rifiutare",
|
|
112
|
+
},
|
|
113
|
+
coppie("Variabili del template di riserva", "variabiliRiserva", "Valori delle variabili del template di riserva"),
|
|
114
|
+
{ displayName: "Fonte Consenso", name: "consensoFonte", type: "string", default: "", displayOptions: suNumero, description: "Obbligatoria per il primo messaggio a un numero nuovo: dove ha dato il consenso, per esempio il modulo del sito" },
|
|
115
|
+
{ displayName: "Data Consenso", name: "consensoData", type: "dateTime", default: "", displayOptions: suNumero },
|
|
116
|
+
{
|
|
117
|
+
displayName: "Scopo Consenso",
|
|
118
|
+
name: "consensoScopo",
|
|
119
|
+
type: "options",
|
|
120
|
+
default: "utilita",
|
|
121
|
+
displayOptions: suNumero,
|
|
122
|
+
options: [
|
|
123
|
+
{ name: "Servizio", value: "utilita" },
|
|
124
|
+
{ name: "Marketing", value: "marketing" },
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
const daCoppie = (v) => {
|
|
130
|
+
const voci = (v?.voce ?? []).filter((x) => x.chiave?.trim());
|
|
131
|
+
return voci.length ? Object.fromEntries(voci.map((x) => [x.chiave.trim(), x.valore ?? ""])) : undefined;
|
|
132
|
+
};
|
|
133
|
+
/** Corpo di «Invia a un numero» dai campi del nodo: i campi vuoti non si mandano. */
|
|
134
|
+
function corpoNumero(get) {
|
|
135
|
+
const t = (nome) => String(get(nome) ?? "").trim();
|
|
136
|
+
const body = { numberId: t("numeroMittente"), channel: t("canale") || "automatico" };
|
|
137
|
+
for (const [campo, chiave] of [["telefono", "phone"], ["chatId", "chatId"], ["testo", "text"], ["template", "templateId"], ["mediaId", "mediaId"], ["templateRiserva", "fallbackTemplateId"]]) {
|
|
138
|
+
const v = t(campo);
|
|
139
|
+
if (v)
|
|
140
|
+
body[chiave] = v;
|
|
141
|
+
}
|
|
142
|
+
const variables = daCoppie(get("variabili"));
|
|
143
|
+
if (variables)
|
|
144
|
+
body.variables = variables;
|
|
145
|
+
const fallbackVariables = daCoppie(get("variabiliRiserva"));
|
|
146
|
+
if (fallbackVariables)
|
|
147
|
+
body.fallbackVariables = fallbackVariables;
|
|
148
|
+
if (t("consensoFonte"))
|
|
149
|
+
body.consent = { source: t("consensoFonte"), date: t("consensoData") || new Date().toISOString(), purpose: t("consensoScopo") || "utilita" };
|
|
150
|
+
return body;
|
|
151
|
+
}
|
|
36
152
|
const nomiParametri = {
|
|
37
153
|
id: { displayName: "ID", description: "Identificativo dell'elemento, come lo restituisce un'altra operazione di RisveglIA" },
|
|
38
154
|
azione: { displayName: "Azione", description: "Nome dell'azione, come indicato nella guida dell'operazione" },
|
|
@@ -98,7 +214,10 @@ function proprieta() {
|
|
|
98
214
|
description: nomiParametri[nome]?.description ?? "",
|
|
99
215
|
});
|
|
100
216
|
}
|
|
217
|
+
props.push(...campiNumero());
|
|
101
218
|
for (const op of catalogo_1.operazioni) {
|
|
219
|
+
if (op.id === exports.OPERAZIONE_NUMERO)
|
|
220
|
+
continue;
|
|
102
221
|
if (conCorpo(op))
|
|
103
222
|
props.push({
|
|
104
223
|
displayName: "Corpo (JSON)",
|
|
@@ -176,6 +295,20 @@ class RisveglIa {
|
|
|
176
295
|
const tools = res.body.tools ?? [];
|
|
177
296
|
return tools.map((t) => ({ name: t.title || t.name, value: t.name, description: t.description }));
|
|
178
297
|
},
|
|
298
|
+
/** Numeri mittenti con i canali collegati adesso. */
|
|
299
|
+
async numeriCanali() {
|
|
300
|
+
const res = await (0, richiesta_1.chiama)(this, { method: "GET", path: "/api/v2/invii/numero/canali" });
|
|
301
|
+
const numbers = res.body.numbers ?? [];
|
|
302
|
+
return numbers.map((n) => ({ name: `${n.label} (${n.channels})`, value: n.id }));
|
|
303
|
+
},
|
|
304
|
+
/** Template approvati del numero scelto: solo questi, gli altri non si possono mandare. */
|
|
305
|
+
async templateNumero() {
|
|
306
|
+
const numero = String(this.getCurrentNodeParameter("numeroMittente") ?? "");
|
|
307
|
+
const res = await (0, richiesta_1.chiama)(this, { method: "GET", path: "/api/v2/invii/numero/canali" });
|
|
308
|
+
const numbers = res.body.numbers ?? [];
|
|
309
|
+
const templates = numbers.find((n) => n.id === numero)?.templates ?? [];
|
|
310
|
+
return [{ name: "Nessuno", value: "" }, ...templates.map((t) => ({ name: `${t.name} · ${t.language.toUpperCase()} · ${t.category}`, value: t.id, description: t.preview.slice(0, 200) }))];
|
|
311
|
+
},
|
|
179
312
|
},
|
|
180
313
|
};
|
|
181
314
|
async execute() {
|
|
@@ -206,7 +339,11 @@ class RisveglIa {
|
|
|
206
339
|
const res = await (0, richiesta_1.chiama)(this, {
|
|
207
340
|
method: op.method,
|
|
208
341
|
path: `/api${path}`,
|
|
209
|
-
...(
|
|
342
|
+
...(op.id === exports.OPERAZIONE_NUMERO
|
|
343
|
+
? { body: corpoNumero((nome) => this.getNodeParameter(nome, i, "")) }
|
|
344
|
+
: conCorpo(op)
|
|
345
|
+
? { body: json(this, "corpo", i) }
|
|
346
|
+
: { qs: json(this, "parametri", i) }),
|
|
210
347
|
binario,
|
|
211
348
|
...(chiave ? { headers: { "Idempotency-Key": chiave } } : {}),
|
|
212
349
|
itemIndex: i,
|
|
@@ -54,6 +54,36 @@ exports.operazioni = [
|
|
|
54
54
|
"idempotent": false,
|
|
55
55
|
"binary": false
|
|
56
56
|
},
|
|
57
|
+
{
|
|
58
|
+
"id": "numero.canali",
|
|
59
|
+
"method": "GET",
|
|
60
|
+
"path": "/v2/invii/numero/canali",
|
|
61
|
+
"scope": "messages:send",
|
|
62
|
+
"group": "Messaggi",
|
|
63
|
+
"title": "Numeri mittenti con i canali collegati (QR, API) e modelli approvati",
|
|
64
|
+
"idempotent": false,
|
|
65
|
+
"binary": false
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"id": "numero.invia",
|
|
69
|
+
"method": "POST",
|
|
70
|
+
"path": "/v2/invii/numero",
|
|
71
|
+
"scope": "messages:send",
|
|
72
|
+
"group": "Messaggi",
|
|
73
|
+
"title": "Invia a un numero, anche nuovo (testo o modello, QR o API)",
|
|
74
|
+
"idempotent": true,
|
|
75
|
+
"binary": false
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "numero.dettaglio",
|
|
79
|
+
"method": "GET",
|
|
80
|
+
"path": "/v2/invii/numero/{id}",
|
|
81
|
+
"scope": "messages:send",
|
|
82
|
+
"group": "Messaggi",
|
|
83
|
+
"title": "Stato di un invio a un numero",
|
|
84
|
+
"idempotent": false,
|
|
85
|
+
"binary": false
|
|
86
|
+
},
|
|
57
87
|
{
|
|
58
88
|
"id": "allegati.elenca",
|
|
59
89
|
"method": "GET",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ivanlaomarketing/n8n-nodes-risveglia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "n8n community node for RisveglIA: WhatsApp messages, contacts and deals, groups and channels, AI agent, media and triggers. Built by Ivan Lao (@ivanlaomarketing).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"n8n-community-node-package",
|