n8n-nodes-chat2crm 0.1.8 → 0.1.9
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.
|
@@ -43,9 +43,8 @@ class Chat2CrmSend {
|
|
|
43
43
|
displayName: 'Message Data',
|
|
44
44
|
name: 'messageData',
|
|
45
45
|
type: 'json',
|
|
46
|
-
required: true,
|
|
47
46
|
default: '{}',
|
|
48
|
-
description: 'Message data to send to Redis stream (JSON object)',
|
|
47
|
+
description: 'Message data to send to Redis stream (JSON object). If not provided, will use data from input item (from trigger).',
|
|
49
48
|
},
|
|
50
49
|
{
|
|
51
50
|
displayName: 'Message ID',
|
|
@@ -261,34 +260,46 @@ class Chat2CrmSend {
|
|
|
261
260
|
}
|
|
262
261
|
// Обрабатываем каждый элемент входных данных
|
|
263
262
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
|
264
|
-
const
|
|
265
|
-
|
|
263
|
+
const item = items[itemIndex];
|
|
264
|
+
const inputJson = item.json;
|
|
265
|
+
// Определяем данные для отправки: приоритет - data из входного элемента, затем commandList, затем параметр messageData
|
|
266
266
|
let messageData = {};
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
267
|
+
if (inputJson.data && typeof inputJson.data === 'object') {
|
|
268
|
+
// Используем data из входного элемента (из триггера)
|
|
269
|
+
messageData = inputJson.data;
|
|
270
|
+
}
|
|
271
|
+
else if (inputJson.commandList && typeof inputJson.commandList === 'object') {
|
|
272
|
+
// Используем commandList из входного элемента (из триггера)
|
|
273
|
+
messageData = inputJson.commandList;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
// Используем параметр messageData из настроек ноды
|
|
277
|
+
const messageDataParam = this.getNodeParameter('messageData', itemIndex);
|
|
278
|
+
try {
|
|
279
|
+
if (typeof messageDataParam === 'string') {
|
|
280
|
+
// Если это строка, пытаемся распарсить JSON
|
|
281
|
+
if (messageDataParam.trim() === '') {
|
|
282
|
+
messageData = {};
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
messageData = JSON.parse(messageDataParam);
|
|
286
|
+
}
|
|
272
287
|
}
|
|
273
|
-
else {
|
|
274
|
-
|
|
288
|
+
else if (typeof messageDataParam === 'object' && messageDataParam !== null) {
|
|
289
|
+
// Если это уже объект, используем его напрямую
|
|
290
|
+
messageData = messageDataParam;
|
|
275
291
|
}
|
|
276
292
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
messageData = messageDataParam;
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
throw new n8n_workflow_1.ApplicationError('messageData must be a JSON object or string', { level: 'error' });
|
|
293
|
+
catch (error) {
|
|
294
|
+
throw new n8n_workflow_1.ApplicationError(`Invalid JSON in messageData: ${error.message}`, { level: 'error' });
|
|
283
295
|
}
|
|
284
296
|
}
|
|
285
|
-
catch (error) {
|
|
286
|
-
throw new n8n_workflow_1.ApplicationError(`Invalid JSON in messageData: ${error.message}`, { level: 'error' });
|
|
287
|
-
}
|
|
288
297
|
// Проверяем, что messageData не пустой
|
|
289
298
|
if (Object.keys(messageData).length === 0) {
|
|
290
|
-
throw new n8n_workflow_1.ApplicationError('messageData cannot be empty', { level: 'error' });
|
|
299
|
+
throw new n8n_workflow_1.ApplicationError('messageData cannot be empty. Provide data in input item or in messageData parameter', { level: 'error' });
|
|
291
300
|
}
|
|
301
|
+
// Определяем messageId: приоритет - из входного элемента, затем из параметра
|
|
302
|
+
const finalMessageId = inputJson.messageId || messageId || '*';
|
|
292
303
|
// Отправляем сообщение в каждый выбранный stream
|
|
293
304
|
const sent = [];
|
|
294
305
|
const errors = [];
|
|
@@ -312,7 +323,7 @@ class Chat2CrmSend {
|
|
|
312
323
|
}
|
|
313
324
|
}
|
|
314
325
|
// Отправляем сообщение в stream
|
|
315
|
-
const id = await redis.xadd(stream,
|
|
326
|
+
const id = await redis.xadd(stream, finalMessageId, ...fields);
|
|
316
327
|
if (!id) {
|
|
317
328
|
throw new n8n_workflow_1.ApplicationError('Failed to add message to stream: XADD returned null', { level: 'error' });
|
|
318
329
|
}
|