n8n-nodes-bgos 1.2.0 → 1.2.1

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.
@@ -406,9 +406,8 @@ class BGOSAction {
406
406
  placeholder: 'user_xxx',
407
407
  description: 'Override the user ID. If empty, falls back to user_id from the input data.',
408
408
  displayOptions: {
409
- hide: {
410
- resource: ['message'],
411
- operation: ['sendMessage', 'deleteMessage'],
409
+ show: {
410
+ resource: ['chat', 'assistant', 'callback', 'file'],
412
411
  },
413
412
  },
414
413
  },
@@ -488,13 +487,18 @@ class BGOSAction {
488
487
  });
489
488
  }
490
489
  catch (error) {
491
- returnData.push({
492
- json: {
493
- ...items[i].json,
494
- success: false,
495
- error: error instanceof Error ? error.message : 'Unknown error',
496
- },
497
- });
490
+ const message = error instanceof Error ? error.message : 'Unknown error';
491
+ if (this.continueOnFail()) {
492
+ returnData.push({
493
+ json: {
494
+ ...items[i].json,
495
+ success: false,
496
+ error: message,
497
+ },
498
+ });
499
+ continue;
500
+ }
501
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), message, { itemIndex: i });
498
502
  }
499
503
  }
500
504
  return [returnData];
@@ -122,17 +122,31 @@ class Bgos {
122
122
  // ── MESSAGE ────────────────────────────────────────────────────────
123
123
  if (resource === 'message') {
124
124
  switch (operation) {
125
- case 'createMessage':
125
+ case 'createMessage': {
126
+ // Calls /api/v1/send-message with sender=assistant: saves to DB,
127
+ // pushes to frontend via WebSocket, and sends push notification.
128
+ const filesRaw = g('filesJson', i, '');
129
+ let files = [];
130
+ if (Array.isArray(filesRaw)) {
131
+ files = filesRaw;
132
+ }
133
+ else if (typeof filesRaw === 'string' && filesRaw.trim()) {
134
+ files = JSON.parse(filesRaw);
135
+ }
126
136
  result = await req({
127
137
  method: 'POST',
128
- url: `${baseUrl}/api/v1/messages`,
138
+ url: `${baseUrl}/api/v1/send-message`,
129
139
  body: {
140
+ assistantId: Number(g('assistantId', i)),
130
141
  chatId: Number(g('chatId', i)),
131
- sender: g('sender', i),
142
+ sender: g('sender', i, 'assistant'),
132
143
  text: g('text', i),
144
+ files,
145
+ hasAttachment: files.length > 0,
133
146
  },
134
147
  });
135
148
  break;
149
+ }
136
150
  case 'bulkCreateMessages': {
137
151
  const jsonParam = g('messagesJson', i);
138
152
  result = await req({
@@ -158,60 +172,6 @@ class Bgos {
158
172
  url: `${baseUrl}/api/v1/messages/${Number(g('messageId', i))}`,
159
173
  });
160
174
  break;
161
- case 'sendWebhookMessage': {
162
- const af = g('additionalFields', i, {});
163
- const chatId = Number(g('chatId', i));
164
- const assistantId = Number(g('assistantId', i));
165
- result = await req({
166
- method: 'POST',
167
- url: `${baseUrl}/webhook/message`,
168
- body: {
169
- event_type: af.eventType ?? 'message',
170
- user_id: g('userId', i),
171
- chat_id: String(chatId),
172
- text: g('text', i),
173
- timestamp: af.timestamp || new Date().toISOString(),
174
- assistant: {
175
- id: String(assistantId),
176
- name: af.assistantName ?? 'Assistant',
177
- },
178
- chat: {
179
- id: af.chatObjectId || String(chatId),
180
- title: af.chatTitle ?? '',
181
- },
182
- message: { text: g('text', i) },
183
- },
184
- });
185
- break;
186
- }
187
- case 'editWebhookMessage': {
188
- const af = g('additionalFields', i, {});
189
- const msgId = Number(g('messageId', i));
190
- const chatId = Number(g('chatId', i));
191
- const assistantId = Number(g('assistantId', i));
192
- result = await req({
193
- method: 'POST',
194
- url: `${baseUrl}/webhook/edited_message`,
195
- body: {
196
- event_type: af.eventType ?? 'edited_message',
197
- user_id: g('userId', i),
198
- chat_id: String(chatId),
199
- message_id: String(msgId),
200
- text: g('text', i),
201
- timestamp: af.timestamp || new Date().toISOString(),
202
- assistant: {
203
- id: String(assistantId),
204
- name: af.assistantName ?? 'Assistant',
205
- },
206
- chat: {
207
- id: af.chatObjectId || String(chatId),
208
- title: af.chatTitle ?? '',
209
- },
210
- message: { text: g('text', i), id: String(msgId) },
211
- },
212
- });
213
- break;
214
- }
215
175
  default:
216
176
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown message operation: ${operation}`, { itemIndex: i });
217
177
  }
@@ -16,75 +16,27 @@ exports.messageOperations = [
16
16
  {
17
17
  name: 'Create Message',
18
18
  value: 'createMessage',
19
- description: 'Create a message directly in a chat',
20
- routing: {
21
- request: {
22
- method: 'POST',
23
- url: '/api/v1/messages',
24
- },
25
- },
19
+ description: 'Send an assistant reply — saves to DB and pushes to frontend in real time',
26
20
  action: 'Create a message',
27
21
  },
28
22
  {
29
23
  name: 'Bulk Create Messages',
30
24
  value: 'bulkCreateMessages',
31
25
  description: 'Create multiple messages at once',
32
- routing: {
33
- request: {
34
- method: 'POST',
35
- url: '/api/v1/messages/bulk',
36
- },
37
- },
38
26
  action: 'Bulk create messages',
39
27
  },
40
28
  {
41
29
  name: 'Edit Message',
42
30
  value: 'editMessage',
43
31
  description: 'Edit an existing message',
44
- routing: {
45
- request: {
46
- method: 'PATCH',
47
- url: '=/api/v1/messages/{{$parameter.messageId}}',
48
- },
49
- },
50
32
  action: 'Edit a message',
51
33
  },
52
34
  {
53
35
  name: 'Delete Message',
54
36
  value: 'deleteMessage',
55
37
  description: 'Delete a message',
56
- routing: {
57
- request: {
58
- method: 'DELETE',
59
- url: '=/api/v1/messages/{{$parameter.messageId}}',
60
- },
61
- },
62
38
  action: 'Delete a message',
63
39
  },
64
- {
65
- name: 'Send Webhook Message',
66
- value: 'sendWebhookMessage',
67
- description: 'Send a message via webhook (saves to DB + pushes via WebSocket for real-time)',
68
- routing: {
69
- request: {
70
- method: 'POST',
71
- url: '/webhook/message',
72
- },
73
- },
74
- action: 'Send a webhook message',
75
- },
76
- {
77
- name: 'Edit Webhook Message',
78
- value: 'editWebhookMessage',
79
- description: 'Edit a message via webhook (updates DB + pushes via WebSocket for real-time)',
80
- routing: {
81
- request: {
82
- method: 'POST',
83
- url: '/webhook/edited_message',
84
- },
85
- },
86
- action: 'Edit a webhook message',
87
- },
88
40
  ],
89
41
  default: 'createMessage',
90
42
  },
@@ -107,8 +59,8 @@ exports.messageFields = [
107
59
  },
108
60
  // --- createMessage fields ---
109
61
  {
110
- displayName: 'Chat ID',
111
- name: 'chatId',
62
+ displayName: 'Assistant ID',
63
+ name: 'assistantId',
112
64
  type: 'number',
113
65
  required: true,
114
66
  default: 0,
@@ -118,150 +70,7 @@ exports.messageFields = [
118
70
  operation: ['createMessage'],
119
71
  },
120
72
  },
121
- routing: {
122
- send: {
123
- type: 'body',
124
- property: 'chatId',
125
- },
126
- },
127
- description: 'The chat ID',
128
- },
129
- {
130
- displayName: 'Sender',
131
- name: 'sender',
132
- type: 'options',
133
- required: true,
134
- default: 'user',
135
- options: [
136
- { name: 'User', value: 'user' },
137
- { name: 'Assistant', value: 'assistant' },
138
- ],
139
- displayOptions: {
140
- show: {
141
- resource: ['message'],
142
- operation: ['createMessage'],
143
- },
144
- },
145
- routing: {
146
- send: {
147
- type: 'body',
148
- property: 'sender',
149
- },
150
- },
151
- description: 'Who sent the message',
152
- },
153
- {
154
- displayName: 'Text',
155
- name: 'text',
156
- type: 'string',
157
- typeOptions: { rows: 4 },
158
- required: true,
159
- default: '',
160
- displayOptions: {
161
- show: {
162
- resource: ['message'],
163
- operation: ['createMessage'],
164
- },
165
- },
166
- routing: {
167
- send: {
168
- type: 'body',
169
- property: 'text',
170
- },
171
- },
172
- description: 'The message text',
173
- },
174
- // --- bulkCreateMessages fields ---
175
- {
176
- displayName: 'Messages JSON',
177
- name: 'messagesJson',
178
- type: 'json',
179
- required: true,
180
- default: '[{"chatId":0,"sender":"assistant","text":"Hello"}]',
181
- displayOptions: {
182
- show: {
183
- resource: ['message'],
184
- operation: ['bulkCreateMessages'],
185
- },
186
- },
187
- description: 'JSON array of message objects. Each object must have: chatId (number), sender ("user" | "assistant"), text (string). Optional: sentDate (ISO string).',
188
- routing: {
189
- send: {
190
- preSend: [
191
- async function (requestOptions) {
192
- const json = this.getNodeParameter('messagesJson');
193
- requestOptions.body = typeof json === 'string' ? JSON.parse(json) : json;
194
- return requestOptions;
195
- },
196
- ],
197
- },
198
- },
199
- },
200
- // --- editMessage fields ---
201
- {
202
- displayName: 'User ID',
203
- name: 'userId',
204
- type: 'string',
205
- required: true,
206
- default: '',
207
- displayOptions: {
208
- show: {
209
- resource: ['message'],
210
- operation: ['editMessage'],
211
- },
212
- },
213
- routing: {
214
- send: {
215
- type: 'body',
216
- property: 'userId',
217
- },
218
- },
219
- description: 'The user ID (for ownership validation)',
220
- },
221
- {
222
- displayName: 'Text',
223
- name: 'text',
224
- type: 'string',
225
- typeOptions: { rows: 4 },
226
- required: true,
227
- default: '',
228
- displayOptions: {
229
- show: {
230
- resource: ['message'],
231
- operation: ['editMessage'],
232
- },
233
- },
234
- routing: {
235
- send: {
236
- type: 'body',
237
- property: 'text',
238
- },
239
- },
240
- description: 'The new message text',
241
- },
242
- // =====================================================================
243
- // sendWebhookMessage fields
244
- // POST /webhook/message — saves to DB + pushes via WebSocket
245
- // =====================================================================
246
- {
247
- displayName: 'User ID',
248
- name: 'userId',
249
- type: 'string',
250
- required: true,
251
- default: '',
252
- displayOptions: {
253
- show: {
254
- resource: ['message'],
255
- operation: ['sendWebhookMessage'],
256
- },
257
- },
258
- routing: {
259
- send: {
260
- type: 'body',
261
- property: 'user_id',
262
- },
263
- },
264
- description: 'The user ID (used for WebSocket room targeting)',
73
+ description: 'The assistant ID sending this reply',
265
74
  },
266
75
  {
267
76
  displayName: 'Chat ID',
@@ -272,36 +81,10 @@ exports.messageFields = [
272
81
  displayOptions: {
273
82
  show: {
274
83
  resource: ['message'],
275
- operation: ['sendWebhookMessage'],
276
- },
277
- },
278
- routing: {
279
- send: {
280
- type: 'body',
281
- property: 'chat_id',
282
- },
283
- },
284
- description: 'The chat ID to send the message to',
285
- },
286
- {
287
- displayName: 'Assistant ID',
288
- name: 'assistantId',
289
- type: 'number',
290
- required: true,
291
- default: 0,
292
- displayOptions: {
293
- show: {
294
- resource: ['message'],
295
- operation: ['sendWebhookMessage'],
296
- },
297
- },
298
- routing: {
299
- send: {
300
- type: 'body',
301
- property: 'assistant.id',
84
+ operation: ['createMessage'],
302
85
  },
303
86
  },
304
- description: 'The assistant ID sending this message',
87
+ description: 'The chat ID to send the reply into',
305
88
  },
306
89
  {
307
90
  displayName: 'Text',
@@ -313,126 +96,58 @@ exports.messageFields = [
313
96
  displayOptions: {
314
97
  show: {
315
98
  resource: ['message'],
316
- operation: ['sendWebhookMessage'],
317
- },
318
- },
319
- routing: {
320
- send: {
321
- type: 'body',
322
- property: 'text',
99
+ operation: ['createMessage'],
323
100
  },
324
101
  },
325
- description: 'The message text',
102
+ description: 'The reply text',
326
103
  },
327
104
  {
328
- // Hidden field: also send text inside the nested message object
329
- displayName: 'Message Text (Auto)',
330
- name: 'messageText',
331
- type: 'hidden',
332
- default: '={{$parameter.text}}',
105
+ displayName: 'Sender',
106
+ name: 'sender',
107
+ type: 'options',
108
+ default: 'assistant',
109
+ options: [
110
+ { name: 'Assistant', value: 'assistant' },
111
+ { name: 'User', value: 'user' },
112
+ ],
333
113
  displayOptions: {
334
114
  show: {
335
115
  resource: ['message'],
336
- operation: ['sendWebhookMessage'],
337
- },
338
- },
339
- routing: {
340
- send: {
341
- type: 'body',
342
- property: 'message.text',
116
+ operation: ['createMessage'],
343
117
  },
344
118
  },
119
+ description: 'Who is sending the message',
345
120
  },
346
121
  {
347
- // Hidden field: auto-send current timestamp so sentDate is never Invalid Date
348
- displayName: 'Timestamp (Auto)',
349
- name: 'timestampAuto',
350
- type: 'hidden',
351
- default: '={{$now.toISO()}}',
122
+ displayName: 'Files (JSON)',
123
+ name: 'filesJson',
124
+ type: 'json',
125
+ required: false,
126
+ default: '',
352
127
  displayOptions: {
353
128
  show: {
354
129
  resource: ['message'],
355
- operation: ['sendWebhookMessage'],
356
- },
357
- },
358
- routing: {
359
- send: {
360
- type: 'body',
361
- property: 'timestamp',
130
+ operation: ['createMessage'],
362
131
  },
363
132
  },
133
+ description: 'Optional JSON array of file objects to attach. Each object must have: fileName (string), fileData (URL string), fileMimeType (string), isImage (boolean), isVideo (boolean), isAudio (boolean), isDocument (boolean). You can pass {{ $json.files }} directly from the BGOS Trigger output.',
364
134
  },
135
+ // --- bulkCreateMessages fields ---
365
136
  {
366
- displayName: 'Additional Fields',
367
- name: 'additionalFields',
368
- type: 'collection',
369
- placeholder: 'Add Field',
370
- default: {},
137
+ displayName: 'Messages JSON',
138
+ name: 'messagesJson',
139
+ type: 'json',
140
+ required: true,
141
+ default: '[{"chatId":0,"sender":"assistant","text":"Hello"}]',
371
142
  displayOptions: {
372
143
  show: {
373
144
  resource: ['message'],
374
- operation: ['sendWebhookMessage'],
145
+ operation: ['bulkCreateMessages'],
375
146
  },
376
147
  },
377
- options: [
378
- {
379
- displayName: 'Assistant Name',
380
- name: 'assistantName',
381
- type: 'string',
382
- default: 'Assistant',
383
- description: 'Name of the assistant (sent in the webhook payload)',
384
- routing: { send: { type: 'body', property: 'assistant.name' } },
385
- },
386
- {
387
- displayName: 'Chat Title',
388
- name: 'chatTitle',
389
- type: 'string',
390
- default: 'Chat',
391
- description: 'Title of the chat (sent in the webhook payload)',
392
- routing: { send: { type: 'body', property: 'chat.title' } },
393
- },
394
- {
395
- displayName: 'Chat ID in Chat Object',
396
- name: 'chatObjectId',
397
- type: 'string',
398
- default: '',
399
- description: 'Chat ID for the nested chat object (defaults to the main Chat ID if empty)',
400
- routing: { send: { type: 'body', property: 'chat.id' } },
401
- },
402
- {
403
- displayName: 'Event Type',
404
- name: 'eventType',
405
- type: 'string',
406
- default: 'message',
407
- description: 'The event_type field value',
408
- routing: { send: { type: 'body', property: 'event_type' } },
409
- },
410
- {
411
- displayName: 'Timestamp',
412
- name: 'timestamp',
413
- type: 'string',
414
- default: '',
415
- description: 'ISO 8601 timestamp (defaults to current time if empty)',
416
- routing: { send: { type: 'body', property: 'timestamp' } },
417
- },
418
- {
419
- displayName: 'Sender',
420
- name: 'sender',
421
- type: 'options',
422
- default: 'assistant',
423
- options: [
424
- { name: 'User', value: 'user' },
425
- { name: 'Assistant', value: 'assistant' },
426
- ],
427
- description: 'Who sent the message',
428
- routing: { send: { type: 'body', property: 'sender' } },
429
- },
430
- ],
148
+ description: 'JSON array of message objects. Each object must have: chatId (number), sender ("user" | "assistant"), text (string). Optional: sentDate (ISO string).',
431
149
  },
432
- // =====================================================================
433
- // editWebhookMessage fields
434
- // POST /webhook/edited_message — updates DB + pushes via WebSocket
435
- // =====================================================================
150
+ // --- editMessage fields ---
436
151
  {
437
152
  displayName: 'User ID',
438
153
  name: 'userId',
@@ -442,76 +157,10 @@ exports.messageFields = [
442
157
  displayOptions: {
443
158
  show: {
444
159
  resource: ['message'],
445
- operation: ['editWebhookMessage'],
446
- },
447
- },
448
- routing: {
449
- send: {
450
- type: 'body',
451
- property: 'user_id',
452
- },
453
- },
454
- description: 'The user ID (used for WebSocket room targeting)',
455
- },
456
- {
457
- displayName: 'Chat ID',
458
- name: 'chatId',
459
- type: 'number',
460
- required: true,
461
- default: 0,
462
- displayOptions: {
463
- show: {
464
- resource: ['message'],
465
- operation: ['editWebhookMessage'],
466
- },
467
- },
468
- routing: {
469
- send: {
470
- type: 'body',
471
- property: 'chat_id',
472
- },
473
- },
474
- description: 'The chat ID containing the message',
475
- },
476
- {
477
- displayName: 'Message ID',
478
- name: 'messageId',
479
- type: 'number',
480
- required: true,
481
- default: 0,
482
- displayOptions: {
483
- show: {
484
- resource: ['message'],
485
- operation: ['editWebhookMessage'],
486
- },
487
- },
488
- routing: {
489
- send: {
490
- type: 'body',
491
- property: 'message_id',
492
- },
493
- },
494
- description: 'The ID of the message to edit',
495
- },
496
- {
497
- displayName: 'Assistant ID',
498
- name: 'assistantId',
499
- type: 'number',
500
- required: true,
501
- default: 0,
502
- displayOptions: {
503
- show: {
504
- resource: ['message'],
505
- operation: ['editWebhookMessage'],
506
- },
507
- },
508
- routing: {
509
- send: {
510
- type: 'body',
511
- property: 'assistant.id',
160
+ operation: ['editMessage'],
512
161
  },
513
162
  },
514
- description: 'The assistant ID',
163
+ description: 'The user ID (for ownership validation)',
515
164
  },
516
165
  {
517
166
  displayName: 'Text',
@@ -523,127 +172,9 @@ exports.messageFields = [
523
172
  displayOptions: {
524
173
  show: {
525
174
  resource: ['message'],
526
- operation: ['editWebhookMessage'],
527
- },
528
- },
529
- routing: {
530
- send: {
531
- type: 'body',
532
- property: 'text',
175
+ operation: ['editMessage'],
533
176
  },
534
177
  },
535
178
  description: 'The new message text',
536
179
  },
537
- {
538
- // Hidden field: also send text and id inside the nested message object
539
- displayName: 'Message Text (Auto)',
540
- name: 'messageText',
541
- type: 'hidden',
542
- default: '={{$parameter.text}}',
543
- displayOptions: {
544
- show: {
545
- resource: ['message'],
546
- operation: ['editWebhookMessage'],
547
- },
548
- },
549
- routing: {
550
- send: {
551
- type: 'body',
552
- property: 'message.text',
553
- },
554
- },
555
- },
556
- {
557
- // Hidden field: copy messageId into the nested message object
558
- displayName: 'Message ID (Auto)',
559
- name: 'messageIdNested',
560
- type: 'hidden',
561
- default: '={{$parameter.messageId}}',
562
- displayOptions: {
563
- show: {
564
- resource: ['message'],
565
- operation: ['editWebhookMessage'],
566
- },
567
- },
568
- routing: {
569
- send: {
570
- type: 'body',
571
- property: 'message.id',
572
- },
573
- },
574
- },
575
- {
576
- // Hidden field: auto-send current timestamp so sentDate is never Invalid Date
577
- displayName: 'Timestamp (Auto)',
578
- name: 'timestampAuto',
579
- type: 'hidden',
580
- default: '={{$now.toISO()}}',
581
- displayOptions: {
582
- show: {
583
- resource: ['message'],
584
- operation: ['editWebhookMessage'],
585
- },
586
- },
587
- routing: {
588
- send: {
589
- type: 'body',
590
- property: 'timestamp',
591
- },
592
- },
593
- },
594
- {
595
- displayName: 'Additional Fields',
596
- name: 'additionalFields',
597
- type: 'collection',
598
- placeholder: 'Add Field',
599
- default: {},
600
- displayOptions: {
601
- show: {
602
- resource: ['message'],
603
- operation: ['editWebhookMessage'],
604
- },
605
- },
606
- options: [
607
- {
608
- displayName: 'Assistant Name',
609
- name: 'assistantName',
610
- type: 'string',
611
- default: 'Assistant',
612
- description: 'Name of the assistant (sent in the webhook payload)',
613
- routing: { send: { type: 'body', property: 'assistant.name' } },
614
- },
615
- {
616
- displayName: 'Chat Title',
617
- name: 'chatTitle',
618
- type: 'string',
619
- default: 'Chat',
620
- description: 'Title of the chat (sent in the webhook payload)',
621
- routing: { send: { type: 'body', property: 'chat.title' } },
622
- },
623
- {
624
- displayName: 'Chat ID in Chat Object',
625
- name: 'chatObjectId',
626
- type: 'string',
627
- default: '',
628
- description: 'Chat ID for the nested chat object (defaults to the main Chat ID if empty)',
629
- routing: { send: { type: 'body', property: 'chat.id' } },
630
- },
631
- {
632
- displayName: 'Event Type',
633
- name: 'eventType',
634
- type: 'string',
635
- default: 'edited_message',
636
- description: 'The event_type field value',
637
- routing: { send: { type: 'body', property: 'event_type' } },
638
- },
639
- {
640
- displayName: 'Timestamp',
641
- name: 'timestamp',
642
- type: 'string',
643
- default: '',
644
- description: 'ISO 8601 timestamp (defaults to current time if empty)',
645
- routing: { send: { type: 'body', property: 'timestamp' } },
646
- },
647
- ],
648
- },
649
180
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-bgos",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "n8n community nodes for BGOS (Brand Growth OS) - AI assistant chat platform",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",