n8n-nodes-digitalsac 0.1.4 → 0.1.6

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.
@@ -36,9 +36,74 @@ class Digitalsac {
36
36
  { name: 'Transferir para Atendente', value: 'transferAgent' },
37
37
  { name: 'Fechar Ticket', value: 'closeTicket' },
38
38
  { name: 'Enviar Mensagem', value: 'sendMessage' },
39
+ { name: 'Enviar Arquivo', value: 'sendFile' },
39
40
  ],
40
41
  default: 'validateWhatsapp',
41
42
  },
43
+ {
44
+ displayName: 'UUID',
45
+ name: 'uuid',
46
+ type: 'string',
47
+ default: '',
48
+ displayOptions: {
49
+ show: {
50
+ operation: ['sendMessage', 'sendFile'],
51
+ },
52
+ },
53
+ description: 'UUID da conexão para envio da mensagem',
54
+ required: true,
55
+ },
56
+ {
57
+ displayName: 'Número',
58
+ name: 'number',
59
+ type: 'string',
60
+ default: '',
61
+ displayOptions: {
62
+ show: {
63
+ operation: ['sendMessage', 'sendFile'],
64
+ },
65
+ },
66
+ description: 'Número de telefone no formato DDI+DDD+NÚMERO (ex: 5511999999999)',
67
+ required: true,
68
+ },
69
+ {
70
+ displayName: 'Mensagem',
71
+ name: 'body',
72
+ type: 'string',
73
+ default: '',
74
+ displayOptions: {
75
+ show: {
76
+ operation: ['sendMessage', 'sendFile'],
77
+ },
78
+ },
79
+ description: 'Texto da mensagem a ser enviada',
80
+ required: true,
81
+ },
82
+ {
83
+ displayName: 'External Key',
84
+ name: 'externalKey',
85
+ type: 'string',
86
+ default: '',
87
+ displayOptions: {
88
+ show: {
89
+ operation: ['sendMessage', 'sendFile'],
90
+ },
91
+ },
92
+ description: 'Chave externa para identificação no webhook',
93
+ },
94
+ {
95
+ displayName: 'Arquivo',
96
+ name: 'binaryPropertyName',
97
+ type: 'string',
98
+ default: 'data',
99
+ displayOptions: {
100
+ show: {
101
+ operation: ['sendFile'],
102
+ },
103
+ },
104
+ description: 'Nome da propriedade binária que contém o arquivo a ser enviado',
105
+ required: true,
106
+ },
42
107
  {
43
108
  displayName: 'Parâmetro',
44
109
  name: 'param',
@@ -46,10 +111,10 @@ class Digitalsac {
46
111
  default: '',
47
112
  displayOptions: {
48
113
  show: {
49
- operation: ['validateWhatsapp', 'validateCpf', 'sendMessage'],
114
+ operation: ['validateWhatsapp', 'validateCpf'],
50
115
  },
51
116
  },
52
- description: 'Número, CPF ou UUID da mensagem (conforme operação)',
117
+ description: 'Número ou CPF (conforme operação)',
53
118
  },
54
119
  {
55
120
  displayName: 'Dados (JSON)',
@@ -58,7 +123,7 @@ class Digitalsac {
58
123
  default: '',
59
124
  displayOptions: {
60
125
  show: {
61
- operation: ['validateDate', 'transferQueue', 'transferAgent', 'closeTicket', 'sendMessage'],
126
+ operation: ['validateDate', 'transferQueue', 'transferAgent', 'closeTicket'],
62
127
  },
63
128
  },
64
129
  },
@@ -82,12 +147,20 @@ class Digitalsac {
82
147
  let url = '';
83
148
  let method = 'GET';
84
149
  let body;
85
- let param = this.getNodeParameter('param', i, '');
150
+ let param = '';
151
+ let options = {};
152
+ let isFormData = false;
153
+ let formDataFields = {};
154
+ let binaryData;
155
+ let binaryFileName;
156
+ let binaryContentType;
86
157
  switch (operation) {
87
158
  case 'validateWhatsapp':
159
+ param = this.getNodeParameter('param', i);
88
160
  url = `/typebot/whatsappnumber/${param}`;
89
161
  break;
90
162
  case 'validateCpf':
163
+ param = this.getNodeParameter('param', i);
91
164
  url = `/typebot/validate/cpf/${param}`;
92
165
  break;
93
166
  case 'validateDate':
@@ -117,20 +190,93 @@ class Digitalsac {
117
190
  body = this.getNodeParameter('bodyData', i);
118
191
  break;
119
192
  case 'sendMessage':
120
- url = `/v1/api/external/${param}`;
193
+ const uuid = this.getNodeParameter('uuid', i);
194
+ url = `/v1/api/external/${uuid}`;
121
195
  method = 'POST';
122
- body = this.getNodeParameter('bodyData', i);
196
+ body = {
197
+ body: this.getNodeParameter('body', i),
198
+ number: this.getNodeParameter('number', i),
199
+ };
200
+ const externalKey = this.getNodeParameter('externalKey', i, '');
201
+ if (externalKey) {
202
+ body.externalKey = externalKey;
203
+ }
204
+ break;
205
+ case 'sendFile':
206
+ const fileUuid = this.getNodeParameter('uuid', i);
207
+ url = `/v1/api/external/${fileUuid}`;
208
+ method = 'POST';
209
+ // Preparar para FormData
210
+ isFormData = true;
211
+ formDataFields = {
212
+ body: this.getNodeParameter('body', i),
213
+ number: this.getNodeParameter('number', i),
214
+ };
215
+ const fileExternalKey = this.getNodeParameter('externalKey', i, '');
216
+ if (fileExternalKey) {
217
+ formDataFields.externalKey = fileExternalKey;
218
+ }
219
+ // Preparar arquivo binário
220
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
221
+ const binaryKeyData = items[i].binary;
222
+ if (binaryKeyData && binaryKeyData[binaryPropertyName]) {
223
+ const binaryProperty = binaryKeyData[binaryPropertyName];
224
+ binaryData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
225
+ binaryFileName = binaryProperty.fileName || 'file';
226
+ binaryContentType = binaryProperty.mimeType;
227
+ }
228
+ else {
229
+ throw new Error(`Nenhum dado binário encontrado na propriedade "${binaryPropertyName}"`);
230
+ }
231
+ headers['Content-Type'] = 'multipart/form-data';
232
+ options = {
233
+ formData: true,
234
+ };
123
235
  break;
124
236
  }
125
- const options = {
237
+ // Configurar opções da requisição
238
+ const requestOptions = {
126
239
  method,
127
240
  headers,
128
- body: body ? JSON.stringify(body) : undefined,
129
241
  uri: `${baseUrl}${url}`,
130
242
  json: true,
131
243
  };
132
- responseData = await this.helpers.request(options);
133
- returnData.push({ json: responseData });
244
+ // Adicionar body quando necessário
245
+ if (body && !isFormData) {
246
+ requestOptions.body = body;
247
+ }
248
+ // Configurar FormData quando necessário
249
+ if (isFormData) {
250
+ const formData = {};
251
+ // Adicionar campos de texto
252
+ Object.entries(formDataFields).forEach(([key, value]) => {
253
+ formData[key] = value;
254
+ });
255
+ // Adicionar arquivo se disponível
256
+ if (binaryData && binaryFileName) {
257
+ formData.media = {
258
+ value: binaryData,
259
+ options: {
260
+ filename: binaryFileName,
261
+ contentType: binaryContentType,
262
+ },
263
+ };
264
+ }
265
+ requestOptions.formData = formData;
266
+ }
267
+ // Mesclar opções adicionais
268
+ Object.assign(requestOptions, options);
269
+ try {
270
+ responseData = await this.helpers.request(requestOptions);
271
+ returnData.push({ json: responseData });
272
+ }
273
+ catch (error) {
274
+ if (this.continueOnFail()) {
275
+ returnData.push({ json: { error: error.message } });
276
+ continue;
277
+ }
278
+ throw error;
279
+ }
134
280
  }
135
281
  return [returnData];
136
282
  }