@renatoascencio/n8n-nodes-chatwoot 0.6.0 → 0.7.0

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.
Files changed (32) hide show
  1. package/README.md +116 -8
  2. package/dist/nodes/Chatwoot/Chatwoot.node.js +114 -39
  3. package/dist/nodes/Chatwoot/Chatwoot.node.js.map +1 -1
  4. package/dist/nodes/Chatwoot/GenericFunctions.d.ts +1 -0
  5. package/dist/nodes/Chatwoot/GenericFunctions.js +11 -0
  6. package/dist/nodes/Chatwoot/GenericFunctions.js.map +1 -1
  7. package/dist/nodes/Chatwoot/resources/appliedSla/download.operation.d.ts +2 -0
  8. package/dist/nodes/Chatwoot/resources/appliedSla/download.operation.js +30 -0
  9. package/dist/nodes/Chatwoot/resources/appliedSla/download.operation.js.map +1 -0
  10. package/dist/nodes/Chatwoot/resources/appliedSla/getAll.operation.d.ts +2 -0
  11. package/dist/nodes/Chatwoot/resources/appliedSla/getAll.operation.js +75 -0
  12. package/dist/nodes/Chatwoot/resources/appliedSla/getAll.operation.js.map +1 -0
  13. package/dist/nodes/Chatwoot/resources/appliedSla/index.d.ts +3 -0
  14. package/dist/nodes/Chatwoot/resources/appliedSla/index.js +25 -0
  15. package/dist/nodes/Chatwoot/resources/appliedSla/index.js.map +1 -0
  16. package/dist/nodes/Chatwoot/resources/appliedSla/metrics.operation.d.ts +2 -0
  17. package/dist/nodes/Chatwoot/resources/appliedSla/metrics.operation.js +30 -0
  18. package/dist/nodes/Chatwoot/resources/appliedSla/metrics.operation.js.map +1 -0
  19. package/dist/nodes/Chatwoot/resources/contact/importContacts.operation.js +4 -7
  20. package/dist/nodes/Chatwoot/resources/contact/importContacts.operation.js.map +1 -1
  21. package/dist/nodes/Chatwoot/resources/notification/index.js +8 -0
  22. package/dist/nodes/Chatwoot/resources/notification/index.js.map +1 -1
  23. package/dist/nodes/Chatwoot/resources/notification/snooze.operation.d.ts +2 -0
  24. package/dist/nodes/Chatwoot/resources/notification/snooze.operation.js +34 -0
  25. package/dist/nodes/Chatwoot/resources/notification/snooze.operation.js.map +1 -0
  26. package/dist/nodes/Chatwoot/resources/profile/availability.operation.d.ts +2 -0
  27. package/dist/nodes/Chatwoot/resources/profile/availability.operation.js +25 -0
  28. package/dist/nodes/Chatwoot/resources/profile/availability.operation.js.map +1 -0
  29. package/dist/nodes/Chatwoot/resources/profile/index.js +12 -1
  30. package/dist/nodes/Chatwoot/resources/profile/index.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +1 -1
package/README.md CHANGED
@@ -17,10 +17,10 @@ A comprehensive n8n community node for [Chatwoot](https://www.chatwoot.com/) - t
17
17
 
18
18
  ## Highlights
19
19
 
20
- - **27 Resources** - Comprehensive coverage of Application, Platform, and Public APIs
21
- - **130+ Operations** - Complete CRUD operations for all resources
20
+ - **35 Resources** - Comprehensive coverage of Application, Platform, and Public APIs
21
+ - **195+ Operations** - Complete CRUD operations for all resources
22
22
  - **3 API Types** - Application API, Platform API, and Public API support
23
- - **Trigger Node** - Real-time webhook events from Chatwoot
23
+ - **Trigger Node** - Real-time webhook events (10 event types) from Chatwoot
24
24
  - **Dynamic Dropdowns** - Auto-populated lists for agents, teams, inboxes, and labels
25
25
  - **Smart Pagination** - Automatic handling with "Return All" option
26
26
  - **Reports & Analytics** - Access conversation and agent statistics
@@ -132,8 +132,8 @@ Used for client-side/widget operations - creating contacts and conversations fro
132
132
 
133
133
  ### Chatwoot Node
134
134
 
135
- The main node for interacting with Chatwoot APIs. Supports 27 resources across three API types:
136
- - **Application API** (20 resources) - Core operations for conversations, contacts, messages, etc.
135
+ The main node for interacting with Chatwoot APIs. Supports 35 resources across three API types:
136
+ - **Application API** (28 resources) - Core operations for conversations, contacts, messages, macros, notifications, campaigns, companies, SLA policies, global search, etc.
137
137
  - **Platform API** (4 resources) - Admin operations for accounts, users, and agent bots
138
138
  - **Public API** (3 resources) - Client-side operations for widgets and external integrations
139
139
 
@@ -141,14 +141,16 @@ The main node for interacting with Chatwoot APIs. Supports 27 resources across t
141
141
 
142
142
  Webhook-based trigger that starts workflows when events occur in Chatwoot. Automatically registers and manages webhooks in your Chatwoot account.
143
143
 
144
- **Supported Events:**
144
+ **Supported Events (10 total):**
145
+ - `contact_created` - New contact added
146
+ - `contact_updated` - Contact information changed
145
147
  - `conversation_created` - New conversation started
146
148
  - `conversation_status_changed` - Status changed (open/resolved/pending/snoozed)
149
+ - `conversation_typing_off` - Typing indicator stopped
150
+ - `conversation_typing_on` - Typing indicator started
147
151
  - `conversation_updated` - Conversation modified
148
152
  - `message_created` - New message sent or received
149
153
  - `message_updated` - Message edited
150
- - `contact_created` - New contact added
151
- - `contact_updated` - Contact information changed
152
154
  - `webwidget_triggered` - Web widget interaction
153
155
 
154
156
  ---
@@ -203,6 +205,9 @@ Full contact management with search and merge capabilities.
203
205
  | **Filter** | Filter contacts with advanced criteria |
204
206
  | **Add Labels** | Add labels to a contact |
205
207
  | **List Labels** | Get all labels for a contact |
208
+ | **Import** | Import contacts from CSV file (binary upload) |
209
+ | **Export** | Export contacts as CSV |
210
+ | **Contactable Inboxes** | Get inboxes that can reach a contact |
206
211
 
207
212
  ### Conversation
208
213
 
@@ -222,6 +227,12 @@ Manage customer conversations with assignment and labeling.
222
227
  | **Filter** | Filter conversations with advanced criteria |
223
228
  | **Update Custom Attributes** | Set custom attributes on conversation |
224
229
  | **Get Meta** | Get conversation metadata |
230
+ | **Mute** | Mute a conversation |
231
+ | **Unmute** | Unmute a conversation |
232
+ | **Delete** | Delete a conversation |
233
+ | **Search** | Search conversations by query |
234
+ | **Transcript** | Send conversation transcript via email |
235
+ | **Toggle Typing** | Show/hide typing indicator |
225
236
 
226
237
  ### Custom Attribute
227
238
 
@@ -393,6 +404,103 @@ Access customer satisfaction surveys.
393
404
  | Operation | Description |
394
405
  |-----------|-------------|
395
406
  | **Get** | Get CSAT survey for a conversation |
407
+ | **Metrics** | Get CSAT survey metrics summary |
408
+ | **Download** | Download CSAT survey responses |
409
+
410
+ ### Macro
411
+
412
+ Manage reusable action sequences.
413
+
414
+ | Operation | Description |
415
+ |-----------|-------------|
416
+ | **Get Many** | List all macros |
417
+ | **Get** | Retrieve a macro by ID |
418
+ | **Create** | Create a new macro with actions |
419
+ | **Update** | Modify macro settings |
420
+ | **Delete** | Remove a macro |
421
+ | **Execute** | Execute a macro on a conversation |
422
+
423
+ ### Notification
424
+
425
+ Manage agent notifications.
426
+
427
+ | Operation | Description |
428
+ |-----------|-------------|
429
+ | **Get Many** | List notifications (with read/snoozed filters) |
430
+ | **Mark Read** | Mark a notification as read |
431
+ | **Mark Unread** | Mark a notification as unread |
432
+ | **Mark All Read** | Mark all notifications as read |
433
+ | **Delete** | Remove a notification |
434
+ | **Unread Count** | Get count of unread notifications |
435
+
436
+ ### Campaign
437
+
438
+ Manage outbound campaigns.
439
+
440
+ | Operation | Description |
441
+ |-----------|-------------|
442
+ | **Get Many** | List all campaigns |
443
+ | **Get** | Retrieve a campaign by ID |
444
+ | **Create** | Create a new campaign |
445
+ | **Update** | Modify campaign settings |
446
+ | **Delete** | Remove a campaign |
447
+
448
+ ### Contact Note
449
+
450
+ Manage notes on contacts.
451
+
452
+ | Operation | Description |
453
+ |-----------|-------------|
454
+ | **Get Many** | List all notes for a contact |
455
+ | **Create** | Create a note on a contact |
456
+ | **Update** | Modify a contact note |
457
+ | **Delete** | Remove a contact note |
458
+
459
+ ### Conversation Participant
460
+
461
+ Manage conversation watchers/participants.
462
+
463
+ | Operation | Description |
464
+ |-----------|-------------|
465
+ | **Get Many** | List participants of a conversation |
466
+ | **Add** | Add participants to a conversation |
467
+ | **Remove** | Remove participants from a conversation |
468
+
469
+ ### Company (Enterprise)
470
+
471
+ Manage B2B companies. Requires Chatwoot Enterprise.
472
+
473
+ | Operation | Description |
474
+ |-----------|-------------|
475
+ | **Get Many** | List all companies with sorting |
476
+ | **Get** | Retrieve a company by ID |
477
+ | **Create** | Create a new company |
478
+ | **Update** | Modify company settings |
479
+ | **Delete** | Remove a company |
480
+ | **Search** | Search companies by name or domain |
481
+
482
+ ### SLA Policy (Enterprise)
483
+
484
+ Manage SLA policies. Requires Chatwoot Enterprise.
485
+
486
+ | Operation | Description |
487
+ |-----------|-------------|
488
+ | **Get Many** | List all SLA policies |
489
+ | **Get** | Retrieve an SLA policy by ID |
490
+ | **Create** | Create an SLA policy with thresholds |
491
+ | **Update** | Modify SLA policy settings |
492
+ | **Delete** | Remove an SLA policy |
493
+
494
+ ### Search (Global)
495
+
496
+ Search across all entities.
497
+
498
+ | Operation | Description |
499
+ |-----------|-------------|
500
+ | **Search All** | Search across conversations, contacts, and messages |
501
+ | **Search Conversations** | Search conversations only |
502
+ | **Search Contacts** | Search contacts only |
503
+ | **Search Messages** | Search messages only |
396
504
 
397
505
  ---
398
506
 
@@ -31,6 +31,7 @@ const conversationParticipant_1 = require("./resources/conversationParticipant")
31
31
  const company_1 = require("./resources/company");
32
32
  const search_1 = require("./resources/search");
33
33
  const slaPolicy_1 = require("./resources/slaPolicy");
34
+ const appliedSla_1 = require("./resources/appliedSla");
34
35
  const platformAccount_1 = require("./resources/platformAccount");
35
36
  const platformUser_1 = require("./resources/platformUser");
36
37
  const accountUser_1 = require("./resources/accountUser");
@@ -88,6 +89,7 @@ class Chatwoot {
88
89
  'company',
89
90
  'search',
90
91
  'slaPolicy',
92
+ 'appliedSla',
91
93
  ],
92
94
  },
93
95
  },
@@ -121,6 +123,7 @@ class Chatwoot {
121
123
  { name: 'Account', value: 'account' },
122
124
  { name: 'Agent', value: 'agent' },
123
125
  { name: 'Agent Bot', value: 'agentBot' },
126
+ { name: 'Applied SLA (Enterprise)', value: 'appliedSla' },
124
127
  { name: 'Audit Log', value: 'auditLog' },
125
128
  { name: 'Automation Rule', value: 'automationRule' },
126
129
  { name: 'Campaign', value: 'campaign' },
@@ -184,6 +187,7 @@ class Chatwoot {
184
187
  company_1.companyOperations,
185
188
  search_1.searchOperations,
186
189
  slaPolicy_1.slaPolicyOperations,
190
+ appliedSla_1.appliedSlaOperations,
187
191
  platformAccount_1.platformAccountOperations,
188
192
  platformUser_1.platformUserOperations,
189
193
  accountUser_1.accountUserOperations,
@@ -219,6 +223,7 @@ class Chatwoot {
219
223
  ...company_1.companyFields,
220
224
  ...search_1.searchFields,
221
225
  ...slaPolicy_1.slaPolicyFields,
226
+ ...appliedSla_1.appliedSlaFields,
222
227
  ...platformAccount_1.platformAccountFields,
223
228
  ...platformUser_1.platformUserFields,
224
229
  ...accountUser_1.accountUserFields,
@@ -668,7 +673,7 @@ class Chatwoot {
668
673
  if (additionalFields.team_id)
669
674
  body.team_id = additionalFields.team_id;
670
675
  if (additionalFields.custom_attributes) {
671
- body.custom_attributes = JSON.parse(additionalFields.custom_attributes);
676
+ body.custom_attributes = (0, GenericFunctions_1.parseJsonSafe)(additionalFields.custom_attributes, 'custom_attributes');
672
677
  }
673
678
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/conversations', body);
674
679
  }
@@ -690,12 +695,12 @@ class Chatwoot {
690
695
  body.team_id = updateFields.team_id;
691
696
  if (updateFields.status)
692
697
  body.status = updateFields.status;
693
- responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PUT', `/conversations/${conversationId}`, body);
698
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/conversations/${conversationId}`, body);
694
699
  }
695
700
  else if (operation === 'filter') {
696
701
  const filterPayload = this.getNodeParameter('filterPayload', i);
697
702
  const returnAll = this.getNodeParameter('returnAll', i);
698
- const body = { payload: JSON.parse(filterPayload) };
703
+ const body = { payload: (0, GenericFunctions_1.parseJsonSafe)(filterPayload, 'filter payload') };
699
704
  if (returnAll) {
700
705
  responseData = await GenericFunctions_1.chatwootApiRequestAllItems.call(this, 'POST', '/conversations/filter', body, {}, 'payload');
701
706
  }
@@ -710,9 +715,7 @@ class Chatwoot {
710
715
  const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
711
716
  const customAttributes = this.getNodeParameter('customAttributes', i);
712
717
  const body = {
713
- custom_attributes: typeof customAttributes === 'string'
714
- ? JSON.parse(customAttributes)
715
- : customAttributes,
718
+ custom_attributes: (0, GenericFunctions_1.parseJsonSafe)(customAttributes, 'custom_attributes'),
716
719
  };
717
720
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/conversations/${conversationId}`, body);
718
721
  }
@@ -844,10 +847,7 @@ class Chatwoot {
844
847
  if (additionalFields.identifier)
845
848
  body.identifier = additionalFields.identifier;
846
849
  if (additionalFields.custom_attributes) {
847
- body.custom_attributes =
848
- typeof additionalFields.custom_attributes === 'string'
849
- ? JSON.parse(additionalFields.custom_attributes)
850
- : additionalFields.custom_attributes;
850
+ body.custom_attributes = (0, GenericFunctions_1.parseJsonSafe)(additionalFields.custom_attributes, 'custom_attributes');
851
851
  }
852
852
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/contacts', body);
853
853
  }
@@ -889,10 +889,7 @@ class Chatwoot {
889
889
  if (updateFields.blocked !== undefined)
890
890
  body.blocked = updateFields.blocked;
891
891
  if (updateFields.custom_attributes) {
892
- body.custom_attributes =
893
- typeof updateFields.custom_attributes === 'string'
894
- ? JSON.parse(updateFields.custom_attributes)
895
- : updateFields.custom_attributes;
892
+ body.custom_attributes = (0, GenericFunctions_1.parseJsonSafe)(updateFields.custom_attributes, 'custom_attributes');
896
893
  }
897
894
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PUT', `/contacts/${contactId}`, body);
898
895
  }
@@ -936,7 +933,7 @@ class Chatwoot {
936
933
  else if (operation === 'filter') {
937
934
  const filterPayload = this.getNodeParameter('filterPayload', i);
938
935
  const returnAll = this.getNodeParameter('returnAll', i);
939
- const body = { payload: JSON.parse(filterPayload) };
936
+ const body = { payload: (0, GenericFunctions_1.parseJsonSafe)(filterPayload, 'filter payload') };
940
937
  if (returnAll) {
941
938
  responseData = await GenericFunctions_1.chatwootApiRequestAllItems.call(this, 'POST', '/contacts/filter', body, {}, 'payload');
942
939
  }
@@ -958,8 +955,29 @@ class Chatwoot {
958
955
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/contacts/${contactId}/labels`);
959
956
  }
960
957
  else if (operation === 'import') {
961
- const fileContent = this.getNodeParameter('fileContent', i);
962
- responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/contacts/import', { import_file: fileContent });
958
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
959
+ const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
960
+ const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
961
+ const credentials = await this.getCredentials('chatwootApi');
962
+ const baseUrl = credentials.baseUrl.trim().replace(/\/+$/, '');
963
+ const accountId = credentials.accountId;
964
+ responseData = (await this.helpers.httpRequest({
965
+ method: 'POST',
966
+ url: `${baseUrl}/api/v1/accounts/${accountId}/contacts/import`,
967
+ headers: {
968
+ api_access_token: credentials.apiAccessToken,
969
+ },
970
+ body: {
971
+ import_file: {
972
+ value: buffer,
973
+ options: {
974
+ filename: binaryData.fileName || 'contacts.csv',
975
+ contentType: binaryData.mimeType || 'text/csv',
976
+ },
977
+ },
978
+ },
979
+ json: true,
980
+ }));
963
981
  }
964
982
  else if (operation === 'export') {
965
983
  const options = this.getNodeParameter('options', i);
@@ -1023,8 +1041,8 @@ class Chatwoot {
1023
1041
  else if (operation === 'create') {
1024
1042
  const name = this.getNodeParameter('name', i);
1025
1043
  const eventName = this.getNodeParameter('eventName', i);
1026
- const conditions = JSON.parse(this.getNodeParameter('conditions', i));
1027
- const actions = JSON.parse(this.getNodeParameter('actions', i));
1044
+ const conditions = (0, GenericFunctions_1.parseJsonSafe)(this.getNodeParameter('conditions', i), 'conditions');
1045
+ const actions = (0, GenericFunctions_1.parseJsonSafe)(this.getNodeParameter('actions', i), 'actions');
1028
1046
  const additionalFields = this.getNodeParameter('additionalFields', i);
1029
1047
  const body = {
1030
1048
  name,
@@ -1049,9 +1067,9 @@ class Chatwoot {
1049
1067
  if (updateFields.active !== undefined)
1050
1068
  body.active = updateFields.active;
1051
1069
  if (updateFields.conditions)
1052
- body.conditions = JSON.parse(updateFields.conditions);
1070
+ body.conditions = (0, GenericFunctions_1.parseJsonSafe)(updateFields.conditions, 'conditions');
1053
1071
  if (updateFields.actions)
1054
- body.actions = JSON.parse(updateFields.actions);
1072
+ body.actions = (0, GenericFunctions_1.parseJsonSafe)(updateFields.actions, 'actions');
1055
1073
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/automation_rules/${automationRuleId}`, body);
1056
1074
  }
1057
1075
  else if (operation === 'delete') {
@@ -1075,7 +1093,7 @@ class Chatwoot {
1075
1093
  else if (operation === 'create') {
1076
1094
  const name = this.getNodeParameter('name', i);
1077
1095
  const filterType = this.getNodeParameter('filterType', i);
1078
- const query = JSON.parse(this.getNodeParameter('query', i));
1096
+ const query = (0, GenericFunctions_1.parseJsonSafe)(this.getNodeParameter('query', i), 'query');
1079
1097
  const body = {
1080
1098
  name,
1081
1099
  filter_type: filterType,
@@ -1090,7 +1108,7 @@ class Chatwoot {
1090
1108
  if (updateFields.name)
1091
1109
  body.name = updateFields.name;
1092
1110
  if (updateFields.query)
1093
- body.query = JSON.parse(updateFields.query);
1111
+ body.query = (0, GenericFunctions_1.parseJsonSafe)(updateFields.query, 'query');
1094
1112
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/custom_filters/${customFilterId}`, body);
1095
1113
  }
1096
1114
  else if (operation === 'delete') {
@@ -1175,6 +1193,10 @@ class Chatwoot {
1175
1193
  body.auto_offline = updateFields.auto_offline;
1176
1194
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PUT', '/profile', body);
1177
1195
  }
1196
+ else if (operation === 'availability') {
1197
+ const availability = this.getNodeParameter('availability', i);
1198
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/profile/availability', { availability });
1199
+ }
1178
1200
  else {
1179
1201
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
1180
1202
  }
@@ -1257,13 +1279,13 @@ class Chatwoot {
1257
1279
  else if (operation === 'createHook') {
1258
1280
  const appId = this.getNodeParameter('appId', i);
1259
1281
  const inboxId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('inboxId', i), 'Inbox ID');
1260
- const settings = JSON.parse(this.getNodeParameter('settings', i));
1282
+ const settings = (0, GenericFunctions_1.parseJsonSafe)(this.getNodeParameter('settings', i), 'settings');
1261
1283
  const body = { app_id: appId, inbox_id: inboxId, settings };
1262
1284
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/integrations/hooks', body);
1263
1285
  }
1264
1286
  else if (operation === 'updateHook') {
1265
1287
  const hookId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('hookId', i), 'Hook ID');
1266
- const settings = JSON.parse(this.getNodeParameter('settings', i));
1288
+ const settings = (0, GenericFunctions_1.parseJsonSafe)(this.getNodeParameter('settings', i), 'settings');
1267
1289
  const body = { settings };
1268
1290
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/integrations/hooks/${hookId}`, body);
1269
1291
  }
@@ -1303,7 +1325,7 @@ class Chatwoot {
1303
1325
  else if (resource === 'csatSurvey') {
1304
1326
  if (operation === 'get') {
1305
1327
  const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
1306
- responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/csat_survey/${conversationId}`);
1328
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/csat_survey_responses', {}, { conversation_id: conversationId });
1307
1329
  }
1308
1330
  else if (operation === 'metrics') {
1309
1331
  const options = this.getNodeParameter('options', i);
@@ -1341,7 +1363,7 @@ class Chatwoot {
1341
1363
  const additionalFields = this.getNodeParameter('additionalFields', i);
1342
1364
  const body = {
1343
1365
  name,
1344
- actions: typeof actions === 'string' ? JSON.parse(actions) : actions,
1366
+ actions: (0, GenericFunctions_1.parseJsonSafe)(actions, 'actions'),
1345
1367
  };
1346
1368
  if (additionalFields.visibility)
1347
1369
  body.visibility = additionalFields.visibility;
@@ -1356,9 +1378,7 @@ class Chatwoot {
1356
1378
  if (updateFields.visibility)
1357
1379
  body.visibility = updateFields.visibility;
1358
1380
  if (updateFields.actions) {
1359
- body.actions = typeof updateFields.actions === 'string'
1360
- ? JSON.parse(updateFields.actions)
1361
- : updateFields.actions;
1381
+ body.actions = (0, GenericFunctions_1.parseJsonSafe)(updateFields.actions, 'actions');
1362
1382
  }
1363
1383
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/macros/${macroId}`, body);
1364
1384
  }
@@ -1438,6 +1458,13 @@ class Chatwoot {
1438
1458
  const notificationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('notificationId', i), 'Notification ID');
1439
1459
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/notifications/${notificationId}/unread`);
1440
1460
  }
1461
+ else if (operation === 'snooze') {
1462
+ const notificationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('notificationId', i), 'Notification ID');
1463
+ const snoozedUntil = this.getNodeParameter('snoozedUntil', i);
1464
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/notifications/${notificationId}/snooze`, {
1465
+ snoozed_until: snoozedUntil,
1466
+ });
1467
+ }
1441
1468
  else {
1442
1469
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
1443
1470
  }
@@ -1460,9 +1487,7 @@ class Chatwoot {
1460
1487
  if (additionalFields.scheduled_at)
1461
1488
  body.scheduled_at = additionalFields.scheduled_at;
1462
1489
  if (additionalFields.audience) {
1463
- body.audience = typeof additionalFields.audience === 'string'
1464
- ? JSON.parse(additionalFields.audience)
1465
- : additionalFields.audience;
1490
+ body.audience = (0, GenericFunctions_1.parseJsonSafe)(additionalFields.audience, 'audience');
1466
1491
  }
1467
1492
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/campaigns', body);
1468
1493
  }
@@ -1707,6 +1732,56 @@ class Chatwoot {
1707
1732
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
1708
1733
  }
1709
1734
  }
1735
+ else if (resource === 'appliedSla') {
1736
+ if (operation === 'getAll') {
1737
+ const returnAll = this.getNodeParameter('returnAll', i);
1738
+ const options = this.getNodeParameter('options', i);
1739
+ const qs = {};
1740
+ if (options.since)
1741
+ qs.since = new Date(options.since).getTime() / 1000;
1742
+ if (options.until)
1743
+ qs.until = new Date(options.until).getTime() / 1000;
1744
+ if (options.inbox_id)
1745
+ qs.inbox_id = options.inbox_id;
1746
+ if (options.team_id)
1747
+ qs.team_id = options.team_id;
1748
+ if (options.sla_policy_id)
1749
+ qs.sla_policy_id = options.sla_policy_id;
1750
+ if (options.assigned_agent_id)
1751
+ qs.assigned_agent_id = options.assigned_agent_id;
1752
+ if (returnAll) {
1753
+ responseData = await GenericFunctions_1.chatwootApiRequestAllItems.call(this, 'GET', '/applied_slas', {}, qs, 'payload');
1754
+ }
1755
+ else {
1756
+ const limit = this.getNodeParameter('limit', i);
1757
+ qs.page = 1;
1758
+ const result = (await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/applied_slas', {}, qs));
1759
+ const payload = (result.payload || []);
1760
+ responseData = payload.slice(0, limit);
1761
+ }
1762
+ }
1763
+ else if (operation === 'metrics') {
1764
+ const options = this.getNodeParameter('options', i);
1765
+ const qs = {};
1766
+ if (options.since)
1767
+ qs.since = new Date(options.since).getTime() / 1000;
1768
+ if (options.until)
1769
+ qs.until = new Date(options.until).getTime() / 1000;
1770
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/applied_slas/metrics', {}, qs);
1771
+ }
1772
+ else if (operation === 'download') {
1773
+ const options = this.getNodeParameter('options', i);
1774
+ const qs = {};
1775
+ if (options.since)
1776
+ qs.since = new Date(options.since).getTime() / 1000;
1777
+ if (options.until)
1778
+ qs.until = new Date(options.until).getTime() / 1000;
1779
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/applied_slas/download', {}, qs);
1780
+ }
1781
+ else {
1782
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
1783
+ }
1784
+ }
1710
1785
  else if (resource === 'platformAccount') {
1711
1786
  if (operation === 'create') {
1712
1787
  const name = this.getNodeParameter('name', i);
@@ -1741,7 +1816,7 @@ class Chatwoot {
1741
1816
  if (additionalFields.password)
1742
1817
  body.password = additionalFields.password;
1743
1818
  if (additionalFields.custom_attributes) {
1744
- body.custom_attributes = JSON.parse(additionalFields.custom_attributes);
1819
+ body.custom_attributes = (0, GenericFunctions_1.parseJsonSafe)(additionalFields.custom_attributes, 'custom_attributes');
1745
1820
  }
1746
1821
  responseData = await GenericFunctions_1.chatwootPlatformApiRequest.call(this, 'POST', '/users', body);
1747
1822
  }
@@ -1752,8 +1827,8 @@ class Chatwoot {
1752
1827
  else if (operation === 'update') {
1753
1828
  const userId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('userId', i), 'User ID');
1754
1829
  const updateFields = this.getNodeParameter('updateFields', i);
1755
- if (updateFields.custom_attributes && typeof updateFields.custom_attributes === 'string') {
1756
- updateFields.custom_attributes = JSON.parse(updateFields.custom_attributes);
1830
+ if (updateFields.custom_attributes) {
1831
+ updateFields.custom_attributes = (0, GenericFunctions_1.parseJsonSafe)(updateFields.custom_attributes, 'custom_attributes');
1757
1832
  }
1758
1833
  responseData = await GenericFunctions_1.chatwootPlatformApiRequest.call(this, 'PATCH', `/users/${userId}`, updateFields);
1759
1834
  }
@@ -1831,7 +1906,7 @@ class Chatwoot {
1831
1906
  if (operation === 'create') {
1832
1907
  const additionalFields = this.getNodeParameter('additionalFields', i);
1833
1908
  if (additionalFields.custom_attributes && typeof additionalFields.custom_attributes === 'string') {
1834
- additionalFields.custom_attributes = JSON.parse(additionalFields.custom_attributes);
1909
+ additionalFields.custom_attributes = (0, GenericFunctions_1.parseJsonSafe)(additionalFields.custom_attributes, 'custom_attributes');
1835
1910
  }
1836
1911
  responseData = await GenericFunctions_1.chatwootPublicApiRequest.call(this, 'POST', `/inboxes/${inboxIdentifier}/contacts`, additionalFields);
1837
1912
  }
@@ -1843,7 +1918,7 @@ class Chatwoot {
1843
1918
  const contactIdentifier = this.getNodeParameter('contactIdentifier', i);
1844
1919
  const updateFields = this.getNodeParameter('updateFields', i);
1845
1920
  if (updateFields.custom_attributes && typeof updateFields.custom_attributes === 'string') {
1846
- updateFields.custom_attributes = JSON.parse(updateFields.custom_attributes);
1921
+ updateFields.custom_attributes = (0, GenericFunctions_1.parseJsonSafe)(updateFields.custom_attributes, 'custom_attributes');
1847
1922
  }
1848
1923
  responseData = await GenericFunctions_1.chatwootPublicApiRequest.call(this, 'PATCH', `/inboxes/${inboxIdentifier}/contacts/${contactIdentifier}`, updateFields);
1849
1924
  }
@@ -1858,7 +1933,7 @@ class Chatwoot {
1858
1933
  const contactIdentifier = this.getNodeParameter('contactIdentifier', i);
1859
1934
  const additionalFields = this.getNodeParameter('additionalFields', i);
1860
1935
  if (additionalFields.custom_attributes && typeof additionalFields.custom_attributes === 'string') {
1861
- additionalFields.custom_attributes = JSON.parse(additionalFields.custom_attributes);
1936
+ additionalFields.custom_attributes = (0, GenericFunctions_1.parseJsonSafe)(additionalFields.custom_attributes, 'custom_attributes');
1862
1937
  }
1863
1938
  responseData = await GenericFunctions_1.chatwootPublicApiRequest.call(this, 'POST', `/inboxes/${inboxIdentifier}/contacts/${contactIdentifier}/conversations`, additionalFields);
1864
1939
  }