n8n-nodes-digitalsac 0.2.4 → 0.2.7

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.
@@ -51,6 +51,42 @@ class Digitalsac {
51
51
  },
52
52
  description: 'Número, CPF ou UUID da mensagem (conforme operação)',
53
53
  },
54
+ {
55
+ displayName: 'Corpo da Mensagem',
56
+ name: 'messageBody',
57
+ type: 'string',
58
+ default: 'Mensagem de teste',
59
+ displayOptions: {
60
+ show: {
61
+ operation: ['sendMessage'],
62
+ },
63
+ },
64
+ description: 'Texto da mensagem a ser enviada',
65
+ },
66
+ {
67
+ displayName: 'Número de Telefone',
68
+ name: 'phoneNumber',
69
+ type: 'string',
70
+ default: '5511999999999',
71
+ displayOptions: {
72
+ show: {
73
+ operation: ['sendMessage'],
74
+ },
75
+ },
76
+ description: 'Número de telefone no formato DDI+DDD+Número (ex: 5511999999999)',
77
+ },
78
+ {
79
+ displayName: 'Chave Externa',
80
+ name: 'externalKey',
81
+ type: 'string',
82
+ default: 'Digitalsac123',
83
+ displayOptions: {
84
+ show: {
85
+ operation: ['sendMessage'],
86
+ },
87
+ },
88
+ description: 'Identificador único opcional para a mensagem',
89
+ },
54
90
  {
55
91
  displayName: 'Dados (JSON)',
56
92
  name: 'bodyData',
@@ -58,7 +94,7 @@ class Digitalsac {
58
94
  default: '{"body": "Mensagem de teste", "number": "5511999999999", "externalKey": "chave123"}',
59
95
  displayOptions: {
60
96
  show: {
61
- operation: ['validateDate', 'transferQueue', 'transferAgent', 'closeTicket', 'sendMessage'],
97
+ operation: ['validateDate', 'transferQueue', 'transferAgent', 'closeTicket'],
62
98
  },
63
99
  },
64
100
  description: 'Dados no formato JSON',
@@ -94,12 +130,17 @@ class Digitalsac {
94
130
  case 'validateDate':
95
131
  url = '/typebot/validate/data';
96
132
  method = 'POST';
97
- body = JSON.parse(this.getNodeParameter('bodyData', i));
133
+ try {
134
+ body = JSON.parse(this.getNodeParameter('bodyData', i));
135
+ }
136
+ catch (e) {
137
+ throw new Error('Formato de JSON inválido para Dados (JSON)');
138
+ }
98
139
  headers['Content-Type'] = 'application/json';
99
140
  options = {
100
141
  method,
101
142
  headers,
102
- body: JSON.stringify(body),
143
+ body,
103
144
  uri: `${baseUrl}${url}`,
104
145
  json: true,
105
146
  };
@@ -113,12 +154,17 @@ class Digitalsac {
113
154
  case 'transferQueue':
114
155
  url = '/typebot/transferir_para_fila';
115
156
  method = 'POST';
116
- body = JSON.parse(this.getNodeParameter('bodyData', i));
157
+ try {
158
+ body = JSON.parse(this.getNodeParameter('bodyData', i));
159
+ }
160
+ catch (e) {
161
+ throw new Error('Formato de JSON inválido para Dados (JSON)');
162
+ }
117
163
  headers['Content-Type'] = 'application/json';
118
164
  options = {
119
165
  method,
120
166
  headers,
121
- body: JSON.stringify(body),
167
+ body,
122
168
  uri: `${baseUrl}${url}`,
123
169
  json: true,
124
170
  };
@@ -126,12 +172,17 @@ class Digitalsac {
126
172
  case 'transferAgent':
127
173
  url = '/typebot/transferir_para_atendente';
128
174
  method = 'POST';
129
- body = JSON.parse(this.getNodeParameter('bodyData', i));
175
+ try {
176
+ body = JSON.parse(this.getNodeParameter('bodyData', i));
177
+ }
178
+ catch (e) {
179
+ throw new Error('Formato de JSON inválido para Dados (JSON)');
180
+ }
130
181
  headers['Content-Type'] = 'application/json';
131
182
  options = {
132
183
  method,
133
184
  headers,
134
- body: JSON.stringify(body),
185
+ body,
135
186
  uri: `${baseUrl}${url}`,
136
187
  json: true,
137
188
  };
@@ -139,12 +190,17 @@ class Digitalsac {
139
190
  case 'closeTicket':
140
191
  url = '/typebot/fechar_ticket';
141
192
  method = 'POST';
142
- body = JSON.parse(this.getNodeParameter('bodyData', i));
193
+ try {
194
+ body = JSON.parse(this.getNodeParameter('bodyData', i));
195
+ }
196
+ catch (e) {
197
+ throw new Error('Formato de JSON inválido para Dados (JSON)');
198
+ }
143
199
  headers['Content-Type'] = 'application/json';
144
200
  options = {
145
201
  method,
146
202
  headers,
147
- body: JSON.stringify(body),
203
+ body,
148
204
  uri: `${baseUrl}${url}`,
149
205
  json: true,
150
206
  };
@@ -152,12 +208,21 @@ class Digitalsac {
152
208
  case 'sendMessage':
153
209
  url = `/v1/api/external/${param}`;
154
210
  method = 'POST';
155
- body = JSON.parse(this.getNodeParameter('bodyData', i));
211
+ // Usar campos separados em vez de JSON
212
+ const messageBody = this.getNodeParameter('messageBody', i);
213
+ const phoneNumber = this.getNodeParameter('phoneNumber', i);
214
+ const externalKey = this.getNodeParameter('externalKey', i);
215
+ // Criar o objeto diretamente
216
+ body = {
217
+ body: messageBody,
218
+ number: phoneNumber,
219
+ externalKey: externalKey
220
+ };
156
221
  headers['Content-Type'] = 'application/json';
157
222
  options = {
158
223
  method,
159
224
  headers,
160
- body: JSON.stringify(body),
225
+ body,
161
226
  uri: `${baseUrl}${url}`,
162
227
  json: true,
163
228
  };
@@ -178,7 +243,7 @@ class Digitalsac {
178
243
  }
179
244
  catch (error) {
180
245
  if (error.response) {
181
- returnData.push({ json: { error: error.response.body } });
246
+ returnData.push({ json: { error: error.response.body || error.message } });
182
247
  }
183
248
  else {
184
249
  returnData.push({ json: { error: error.message } });
@@ -56,6 +56,42 @@ export class Digitalsac implements INodeType {
56
56
  },
57
57
  description: 'Número, CPF ou UUID da mensagem (conforme operação)',
58
58
  },
59
+ {
60
+ displayName: 'Corpo da Mensagem',
61
+ name: 'messageBody',
62
+ type: 'string',
63
+ default: 'Mensagem de teste',
64
+ displayOptions: {
65
+ show: {
66
+ operation: ['sendMessage'],
67
+ },
68
+ },
69
+ description: 'Texto da mensagem a ser enviada',
70
+ },
71
+ {
72
+ displayName: 'Número de Telefone',
73
+ name: 'phoneNumber',
74
+ type: 'string',
75
+ default: '5511999999999',
76
+ displayOptions: {
77
+ show: {
78
+ operation: ['sendMessage'],
79
+ },
80
+ },
81
+ description: 'Número de telefone no formato DDI+DDD+Número (ex: 5511999999999)',
82
+ },
83
+ {
84
+ displayName: 'Chave Externa',
85
+ name: 'externalKey',
86
+ type: 'string',
87
+ default: 'Digitalsac123',
88
+ displayOptions: {
89
+ show: {
90
+ operation: ['sendMessage'],
91
+ },
92
+ },
93
+ description: 'Identificador único opcional para a mensagem',
94
+ },
59
95
  {
60
96
  displayName: 'Dados (JSON)',
61
97
  name: 'bodyData',
@@ -63,7 +99,7 @@ export class Digitalsac implements INodeType {
63
99
  default: '{"body": "Mensagem de teste", "number": "5511999999999", "externalKey": "chave123"}',
64
100
  displayOptions: {
65
101
  show: {
66
- operation: ['validateDate', 'transferQueue', 'transferAgent', 'closeTicket', 'sendMessage'],
102
+ operation: ['validateDate', 'transferQueue', 'transferAgent', 'closeTicket'],
67
103
  },
68
104
  },
69
105
  description: 'Dados no formato JSON',
@@ -104,12 +140,16 @@ export class Digitalsac implements INodeType {
104
140
  case 'validateDate':
105
141
  url = '/typebot/validate/data';
106
142
  method = 'POST';
107
- body = JSON.parse(this.getNodeParameter('bodyData', i) as string);
143
+ try {
144
+ body = JSON.parse(this.getNodeParameter('bodyData', i) as string);
145
+ } catch (e) {
146
+ throw new Error('Formato de JSON inválido para Dados (JSON)');
147
+ }
108
148
  headers['Content-Type'] = 'application/json';
109
149
  options = {
110
150
  method,
111
151
  headers,
112
- body: JSON.stringify(body),
152
+ body,
113
153
  uri: `${baseUrl}${url}`,
114
154
  json: true,
115
155
  };
@@ -123,12 +163,16 @@ export class Digitalsac implements INodeType {
123
163
  case 'transferQueue':
124
164
  url = '/typebot/transferir_para_fila';
125
165
  method = 'POST';
126
- body = JSON.parse(this.getNodeParameter('bodyData', i) as string);
166
+ try {
167
+ body = JSON.parse(this.getNodeParameter('bodyData', i) as string);
168
+ } catch (e) {
169
+ throw new Error('Formato de JSON inválido para Dados (JSON)');
170
+ }
127
171
  headers['Content-Type'] = 'application/json';
128
172
  options = {
129
173
  method,
130
174
  headers,
131
- body: JSON.stringify(body),
175
+ body,
132
176
  uri: `${baseUrl}${url}`,
133
177
  json: true,
134
178
  };
@@ -136,12 +180,16 @@ export class Digitalsac implements INodeType {
136
180
  case 'transferAgent':
137
181
  url = '/typebot/transferir_para_atendente';
138
182
  method = 'POST';
139
- body = JSON.parse(this.getNodeParameter('bodyData', i) as string);
183
+ try {
184
+ body = JSON.parse(this.getNodeParameter('bodyData', i) as string);
185
+ } catch (e) {
186
+ throw new Error('Formato de JSON inválido para Dados (JSON)');
187
+ }
140
188
  headers['Content-Type'] = 'application/json';
141
189
  options = {
142
190
  method,
143
191
  headers,
144
- body: JSON.stringify(body),
192
+ body,
145
193
  uri: `${baseUrl}${url}`,
146
194
  json: true,
147
195
  };
@@ -149,12 +197,16 @@ export class Digitalsac implements INodeType {
149
197
  case 'closeTicket':
150
198
  url = '/typebot/fechar_ticket';
151
199
  method = 'POST';
152
- body = JSON.parse(this.getNodeParameter('bodyData', i) as string);
200
+ try {
201
+ body = JSON.parse(this.getNodeParameter('bodyData', i) as string);
202
+ } catch (e) {
203
+ throw new Error('Formato de JSON inválido para Dados (JSON)');
204
+ }
153
205
  headers['Content-Type'] = 'application/json';
154
206
  options = {
155
207
  method,
156
208
  headers,
157
- body: JSON.stringify(body),
209
+ body,
158
210
  uri: `${baseUrl}${url}`,
159
211
  json: true,
160
212
  };
@@ -162,12 +214,24 @@ export class Digitalsac implements INodeType {
162
214
  case 'sendMessage':
163
215
  url = `/v1/api/external/${param}`;
164
216
  method = 'POST';
165
- body = JSON.parse(this.getNodeParameter('bodyData', i) as string);
217
+
218
+ // Usar campos separados em vez de JSON
219
+ const messageBody = this.getNodeParameter('messageBody', i) as string;
220
+ const phoneNumber = this.getNodeParameter('phoneNumber', i) as string;
221
+ const externalKey = this.getNodeParameter('externalKey', i) as string;
222
+
223
+ // Criar o objeto diretamente
224
+ body = {
225
+ body: messageBody,
226
+ number: phoneNumber,
227
+ externalKey: externalKey
228
+ };
229
+
166
230
  headers['Content-Type'] = 'application/json';
167
231
  options = {
168
232
  method,
169
233
  headers,
170
- body: JSON.stringify(body),
234
+ body,
171
235
  uri: `${baseUrl}${url}`,
172
236
  json: true,
173
237
  };
@@ -189,7 +253,7 @@ export class Digitalsac implements INodeType {
189
253
  returnData.push({ json: responseData });
190
254
  } catch (error: any) {
191
255
  if (error.response) {
192
- returnData.push({ json: { error: error.response.body } });
256
+ returnData.push({ json: { error: error.response.body || error.message } });
193
257
  } else {
194
258
  returnData.push({ json: { error: error.message } });
195
259
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-digitalsac",
3
- "version": "0.2.4",
3
+ "version": "0.2.7",
4
4
  "description": "Izing Pro Digitalsac",
5
5
  "keywords": [
6
6
  "n8n",