n8n-nodes-digitalsac 0.1.6 → 0.1.8

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,74 +36,9 @@ 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' },
40
39
  ],
41
40
  default: 'validateWhatsapp',
42
41
  },
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
- },
107
42
  {
108
43
  displayName: 'Parâmetro',
109
44
  name: 'param',
@@ -111,21 +46,22 @@ class Digitalsac {
111
46
  default: '',
112
47
  displayOptions: {
113
48
  show: {
114
- operation: ['validateWhatsapp', 'validateCpf'],
49
+ operation: ['validateWhatsapp', 'validateCpf', 'sendMessage'],
115
50
  },
116
51
  },
117
- description: 'Número ou CPF (conforme operação)',
52
+ description: 'Número, CPF ou UUID da conexão (conforme operação)',
118
53
  },
119
54
  {
120
55
  displayName: 'Dados (JSON)',
121
56
  name: 'bodyData',
122
57
  type: 'json',
123
- default: '',
58
+ default: '{\n "body": "Mensagem a ser enviada",\n "number": "5511999999999",\n "externalKey": "chave_opcional"\n}',
124
59
  displayOptions: {
125
60
  show: {
126
- operation: ['validateDate', 'transferQueue', 'transferAgent', 'closeTicket'],
61
+ operation: ['validateDate', 'transferQueue', 'transferAgent', 'closeTicket', 'sendMessage'],
127
62
  },
128
63
  },
64
+ description: 'Para enviar mensagem: {"body": "texto", "number": "5511999999999", "externalKey": "opcional"}',
129
65
  },
130
66
  ],
131
67
  };
@@ -190,48 +126,59 @@ class Digitalsac {
190
126
  body = this.getNodeParameter('bodyData', i);
191
127
  break;
192
128
  case 'sendMessage':
193
- const uuid = this.getNodeParameter('uuid', i);
129
+ // Obter UUID da conexão do campo parâmetro
130
+ const uuid = this.getNodeParameter('param', i);
194
131
  url = `/v1/api/external/${uuid}`;
195
132
  method = 'POST';
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;
133
+ // Verificar se há dados binários (para envio de arquivo)
134
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i, '');
135
+ let hasBinaryData = false;
136
+ if (binaryPropertyName && items[i].binary) {
137
+ const binary = items[i].binary;
138
+ hasBinaryData = binary[binaryPropertyName] !== undefined;
203
139
  }
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;
140
+ // Obter dados do corpo da mensagem
141
+ const messageData = this.getNodeParameter('bodyData', i, '{}');
142
+ let messageBody = {};
143
+ try {
144
+ // Tentar fazer parse do JSON
145
+ if (typeof messageData === 'string') {
146
+ messageBody = JSON.parse(messageData);
147
+ }
148
+ else {
149
+ messageBody = messageData;
150
+ }
151
+ }
152
+ catch (error) {
153
+ // Se falhar, usar como está
154
+ messageBody = { body: messageData };
218
155
  }
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;
156
+ // Se não tiver dados binários, enviar como JSON normal
157
+ if (!hasBinaryData) {
158
+ body = messageBody;
227
159
  }
228
160
  else {
229
- throw new Error(`Nenhum dado binário encontrado na propriedade "${binaryPropertyName}"`);
161
+ // Configurar para envio de arquivo
162
+ isFormData = true;
163
+ formDataFields = messageBody;
164
+ // Preparar arquivo binário
165
+ if (items[i].binary) {
166
+ const binaryKeyData = items[i].binary;
167
+ if (binaryKeyData[binaryPropertyName]) {
168
+ const binaryProperty = binaryKeyData[binaryPropertyName];
169
+ binaryData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
170
+ binaryFileName = binaryProperty.fileName || 'file';
171
+ binaryContentType = binaryProperty.mimeType;
172
+ }
173
+ else {
174
+ throw new Error(`Nenhum dado binário encontrado na propriedade "${binaryPropertyName}"`);
175
+ }
176
+ }
177
+ headers['Content-Type'] = 'multipart/form-data';
178
+ options = {
179
+ formData: true,
180
+ };
230
181
  }
231
- headers['Content-Type'] = 'multipart/form-data';
232
- options = {
233
- formData: true,
234
- };
235
182
  break;
236
183
  }
237
184
  // Configurar opções da requisição
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-digitalsac",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Izing Pro Digitalsac N8N Nodes",
5
5
  "keywords": [
6
6
  "n8n",