@renatoascencio/n8n-nodes-chatwoot 0.1.2 → 0.3.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 (172) hide show
  1. package/README.md +315 -80
  2. package/dist/nodes/Chatwoot/Chatwoot.node.d.ts +9 -0
  3. package/dist/nodes/Chatwoot/Chatwoot.node.js +611 -77
  4. package/dist/nodes/Chatwoot/Chatwoot.node.js.map +1 -1
  5. package/dist/nodes/Chatwoot/Chatwoot.node.json +22 -0
  6. package/dist/nodes/Chatwoot/ChatwootTrigger.node.d.ts +12 -0
  7. package/dist/nodes/Chatwoot/ChatwootTrigger.node.js +197 -0
  8. package/dist/nodes/Chatwoot/ChatwootTrigger.node.js.map +1 -0
  9. package/dist/nodes/Chatwoot/ChatwootTrigger.node.json +22 -0
  10. package/dist/nodes/Chatwoot/GenericFunctions.d.ts +5 -1
  11. package/dist/nodes/Chatwoot/GenericFunctions.js +71 -0
  12. package/dist/nodes/Chatwoot/GenericFunctions.js.map +1 -1
  13. package/dist/nodes/Chatwoot/chatwoot.svg +4 -7
  14. package/dist/nodes/Chatwoot/resources/account/get.operation.d.ts +2 -0
  15. package/dist/nodes/Chatwoot/resources/account/get.operation.js +5 -0
  16. package/dist/nodes/Chatwoot/resources/account/get.operation.js.map +1 -0
  17. package/dist/nodes/Chatwoot/resources/account/index.d.ts +3 -0
  18. package/dist/nodes/Chatwoot/resources/account/index.js +36 -0
  19. package/dist/nodes/Chatwoot/resources/account/index.js.map +1 -0
  20. package/dist/nodes/Chatwoot/resources/account/update.operation.d.ts +2 -0
  21. package/dist/nodes/Chatwoot/resources/account/update.operation.js +75 -0
  22. package/dist/nodes/Chatwoot/resources/account/update.operation.js.map +1 -0
  23. package/dist/nodes/Chatwoot/resources/agent/create.operation.d.ts +2 -0
  24. package/dist/nodes/Chatwoot/resources/agent/create.operation.js +95 -0
  25. package/dist/nodes/Chatwoot/resources/agent/create.operation.js.map +1 -0
  26. package/dist/nodes/Chatwoot/resources/agent/delete.operation.d.ts +2 -0
  27. package/dist/nodes/Chatwoot/resources/agent/delete.operation.js +23 -0
  28. package/dist/nodes/Chatwoot/resources/agent/delete.operation.js.map +1 -0
  29. package/dist/nodes/Chatwoot/resources/agent/getAll.operation.d.ts +2 -0
  30. package/dist/nodes/Chatwoot/resources/agent/getAll.operation.js +5 -0
  31. package/dist/nodes/Chatwoot/resources/agent/getAll.operation.js.map +1 -0
  32. package/dist/nodes/Chatwoot/resources/agent/index.d.ts +3 -0
  33. package/dist/nodes/Chatwoot/resources/agent/index.js +52 -0
  34. package/dist/nodes/Chatwoot/resources/agent/index.js.map +1 -0
  35. package/dist/nodes/Chatwoot/resources/agent/update.operation.d.ts +2 -0
  36. package/dist/nodes/Chatwoot/resources/agent/update.operation.js +75 -0
  37. package/dist/nodes/Chatwoot/resources/agent/update.operation.js.map +1 -0
  38. package/dist/nodes/Chatwoot/resources/agentBot/index.d.ts +3 -0
  39. package/dist/nodes/Chatwoot/resources/agentBot/index.js +143 -0
  40. package/dist/nodes/Chatwoot/resources/agentBot/index.js.map +1 -0
  41. package/dist/nodes/Chatwoot/resources/automationRule/index.d.ts +3 -0
  42. package/dist/nodes/Chatwoot/resources/automationRule/index.js +205 -0
  43. package/dist/nodes/Chatwoot/resources/automationRule/index.js.map +1 -0
  44. package/dist/nodes/Chatwoot/resources/cannedResponse/create.operation.d.ts +2 -0
  45. package/dist/nodes/Chatwoot/resources/cannedResponse/create.operation.js +38 -0
  46. package/dist/nodes/Chatwoot/resources/cannedResponse/create.operation.js.map +1 -0
  47. package/dist/nodes/Chatwoot/resources/cannedResponse/delete.operation.d.ts +2 -0
  48. package/dist/nodes/Chatwoot/resources/cannedResponse/delete.operation.js +20 -0
  49. package/dist/nodes/Chatwoot/resources/cannedResponse/delete.operation.js.map +1 -0
  50. package/dist/nodes/Chatwoot/resources/cannedResponse/getAll.operation.d.ts +2 -0
  51. package/dist/nodes/Chatwoot/resources/cannedResponse/getAll.operation.js +28 -0
  52. package/dist/nodes/Chatwoot/resources/cannedResponse/getAll.operation.js.map +1 -0
  53. package/dist/nodes/Chatwoot/resources/cannedResponse/index.d.ts +3 -0
  54. package/dist/nodes/Chatwoot/resources/cannedResponse/index.js +52 -0
  55. package/dist/nodes/Chatwoot/resources/cannedResponse/index.js.map +1 -0
  56. package/dist/nodes/Chatwoot/resources/cannedResponse/update.operation.d.ts +2 -0
  57. package/dist/nodes/Chatwoot/resources/cannedResponse/update.operation.js +52 -0
  58. package/dist/nodes/Chatwoot/resources/cannedResponse/update.operation.js.map +1 -0
  59. package/dist/nodes/Chatwoot/resources/contact/getConversations.operation.d.ts +2 -0
  60. package/dist/nodes/Chatwoot/resources/contact/getConversations.operation.js +20 -0
  61. package/dist/nodes/Chatwoot/resources/contact/getConversations.operation.js.map +1 -0
  62. package/dist/nodes/Chatwoot/resources/contact/index.js +16 -0
  63. package/dist/nodes/Chatwoot/resources/contact/index.js.map +1 -1
  64. package/dist/nodes/Chatwoot/resources/contact/merge.operation.d.ts +2 -0
  65. package/dist/nodes/Chatwoot/resources/contact/merge.operation.js +34 -0
  66. package/dist/nodes/Chatwoot/resources/contact/merge.operation.js.map +1 -0
  67. package/dist/nodes/Chatwoot/resources/conversation/addLabels.operation.d.ts +2 -0
  68. package/dist/nodes/Chatwoot/resources/conversation/addLabels.operation.js +37 -0
  69. package/dist/nodes/Chatwoot/resources/conversation/addLabels.operation.js.map +1 -0
  70. package/dist/nodes/Chatwoot/resources/conversation/assign.operation.d.ts +2 -0
  71. package/dist/nodes/Chatwoot/resources/conversation/assign.operation.js +87 -0
  72. package/dist/nodes/Chatwoot/resources/conversation/assign.operation.js.map +1 -0
  73. package/dist/nodes/Chatwoot/resources/conversation/create.operation.d.ts +2 -0
  74. package/dist/nodes/Chatwoot/resources/conversation/create.operation.js +92 -0
  75. package/dist/nodes/Chatwoot/resources/conversation/create.operation.js.map +1 -0
  76. package/dist/nodes/Chatwoot/resources/conversation/index.js +32 -0
  77. package/dist/nodes/Chatwoot/resources/conversation/index.js.map +1 -1
  78. package/dist/nodes/Chatwoot/resources/conversation/togglePriority.operation.d.ts +2 -0
  79. package/dist/nodes/Chatwoot/resources/conversation/togglePriority.operation.js +41 -0
  80. package/dist/nodes/Chatwoot/resources/conversation/togglePriority.operation.js.map +1 -0
  81. package/dist/nodes/Chatwoot/resources/customAttribute/create.operation.d.ts +2 -0
  82. package/dist/nodes/Chatwoot/resources/customAttribute/create.operation.js +122 -0
  83. package/dist/nodes/Chatwoot/resources/customAttribute/create.operation.js.map +1 -0
  84. package/dist/nodes/Chatwoot/resources/customAttribute/delete.operation.d.ts +2 -0
  85. package/dist/nodes/Chatwoot/resources/customAttribute/delete.operation.js +20 -0
  86. package/dist/nodes/Chatwoot/resources/customAttribute/delete.operation.js.map +1 -0
  87. package/dist/nodes/Chatwoot/resources/customAttribute/get.operation.d.ts +2 -0
  88. package/dist/nodes/Chatwoot/resources/customAttribute/get.operation.js +20 -0
  89. package/dist/nodes/Chatwoot/resources/customAttribute/get.operation.js.map +1 -0
  90. package/dist/nodes/Chatwoot/resources/customAttribute/getAll.operation.d.ts +2 -0
  91. package/dist/nodes/Chatwoot/resources/customAttribute/getAll.operation.js +32 -0
  92. package/dist/nodes/Chatwoot/resources/customAttribute/getAll.operation.js.map +1 -0
  93. package/dist/nodes/Chatwoot/resources/customAttribute/index.d.ts +3 -0
  94. package/dist/nodes/Chatwoot/resources/customAttribute/index.js +60 -0
  95. package/dist/nodes/Chatwoot/resources/customAttribute/index.js.map +1 -0
  96. package/dist/nodes/Chatwoot/resources/customAttribute/update.operation.d.ts +2 -0
  97. package/dist/nodes/Chatwoot/resources/customAttribute/update.operation.js +64 -0
  98. package/dist/nodes/Chatwoot/resources/customAttribute/update.operation.js.map +1 -0
  99. package/dist/nodes/Chatwoot/resources/customFilter/index.d.ts +3 -0
  100. package/dist/nodes/Chatwoot/resources/customFilter/index.js +139 -0
  101. package/dist/nodes/Chatwoot/resources/customFilter/index.js.map +1 -0
  102. package/dist/nodes/Chatwoot/resources/inbox/get.operation.d.ts +2 -0
  103. package/dist/nodes/Chatwoot/resources/inbox/get.operation.js +23 -0
  104. package/dist/nodes/Chatwoot/resources/inbox/get.operation.js.map +1 -0
  105. package/dist/nodes/Chatwoot/resources/inbox/getAll.operation.d.ts +2 -0
  106. package/dist/nodes/Chatwoot/resources/inbox/getAll.operation.js +5 -0
  107. package/dist/nodes/Chatwoot/resources/inbox/getAll.operation.js.map +1 -0
  108. package/dist/nodes/Chatwoot/resources/inbox/index.d.ts +3 -0
  109. package/dist/nodes/Chatwoot/resources/inbox/index.js +44 -0
  110. package/dist/nodes/Chatwoot/resources/inbox/index.js.map +1 -0
  111. package/dist/nodes/Chatwoot/resources/inbox/update.operation.d.ts +2 -0
  112. package/dist/nodes/Chatwoot/resources/inbox/update.operation.js +143 -0
  113. package/dist/nodes/Chatwoot/resources/inbox/update.operation.js.map +1 -0
  114. package/dist/nodes/Chatwoot/resources/label/create.operation.d.ts +2 -0
  115. package/dist/nodes/Chatwoot/resources/label/create.operation.js +56 -0
  116. package/dist/nodes/Chatwoot/resources/label/create.operation.js.map +1 -0
  117. package/dist/nodes/Chatwoot/resources/label/delete.operation.d.ts +2 -0
  118. package/dist/nodes/Chatwoot/resources/label/delete.operation.js +23 -0
  119. package/dist/nodes/Chatwoot/resources/label/delete.operation.js.map +1 -0
  120. package/dist/nodes/Chatwoot/resources/label/getAll.operation.d.ts +2 -0
  121. package/dist/nodes/Chatwoot/resources/label/getAll.operation.js +5 -0
  122. package/dist/nodes/Chatwoot/resources/label/getAll.operation.js.map +1 -0
  123. package/dist/nodes/Chatwoot/resources/label/index.d.ts +3 -0
  124. package/dist/nodes/Chatwoot/resources/label/index.js +52 -0
  125. package/dist/nodes/Chatwoot/resources/label/index.js.map +1 -0
  126. package/dist/nodes/Chatwoot/resources/label/update.operation.d.ts +2 -0
  127. package/dist/nodes/Chatwoot/resources/label/update.operation.js +66 -0
  128. package/dist/nodes/Chatwoot/resources/label/update.operation.js.map +1 -0
  129. package/dist/nodes/Chatwoot/resources/message/delete.operation.d.ts +2 -0
  130. package/dist/nodes/Chatwoot/resources/message/delete.operation.js +34 -0
  131. package/dist/nodes/Chatwoot/resources/message/delete.operation.js.map +1 -0
  132. package/dist/nodes/Chatwoot/resources/message/index.js +8 -1
  133. package/dist/nodes/Chatwoot/resources/message/index.js.map +1 -1
  134. package/dist/nodes/Chatwoot/resources/report/index.d.ts +3 -0
  135. package/dist/nodes/Chatwoot/resources/report/index.js +155 -0
  136. package/dist/nodes/Chatwoot/resources/report/index.js.map +1 -0
  137. package/dist/nodes/Chatwoot/resources/team/create.operation.d.ts +2 -0
  138. package/dist/nodes/Chatwoot/resources/team/create.operation.js +49 -0
  139. package/dist/nodes/Chatwoot/resources/team/create.operation.js.map +1 -0
  140. package/dist/nodes/Chatwoot/resources/team/delete.operation.d.ts +2 -0
  141. package/dist/nodes/Chatwoot/resources/team/delete.operation.js +23 -0
  142. package/dist/nodes/Chatwoot/resources/team/delete.operation.js.map +1 -0
  143. package/dist/nodes/Chatwoot/resources/team/get.operation.d.ts +2 -0
  144. package/dist/nodes/Chatwoot/resources/team/get.operation.js +23 -0
  145. package/dist/nodes/Chatwoot/resources/team/get.operation.js.map +1 -0
  146. package/dist/nodes/Chatwoot/resources/team/getAll.operation.d.ts +2 -0
  147. package/dist/nodes/Chatwoot/resources/team/getAll.operation.js +5 -0
  148. package/dist/nodes/Chatwoot/resources/team/getAll.operation.js.map +1 -0
  149. package/dist/nodes/Chatwoot/resources/team/index.d.ts +3 -0
  150. package/dist/nodes/Chatwoot/resources/team/index.js +60 -0
  151. package/dist/nodes/Chatwoot/resources/team/index.js.map +1 -0
  152. package/dist/nodes/Chatwoot/resources/team/update.operation.d.ts +2 -0
  153. package/dist/nodes/Chatwoot/resources/team/update.operation.js +59 -0
  154. package/dist/nodes/Chatwoot/resources/team/update.operation.js.map +1 -0
  155. package/dist/nodes/Chatwoot/resources/webhook/create.operation.d.ts +2 -0
  156. package/dist/nodes/Chatwoot/resources/webhook/create.operation.js +77 -0
  157. package/dist/nodes/Chatwoot/resources/webhook/create.operation.js.map +1 -0
  158. package/dist/nodes/Chatwoot/resources/webhook/delete.operation.d.ts +2 -0
  159. package/dist/nodes/Chatwoot/resources/webhook/delete.operation.js +20 -0
  160. package/dist/nodes/Chatwoot/resources/webhook/delete.operation.js.map +1 -0
  161. package/dist/nodes/Chatwoot/resources/webhook/getAll.operation.d.ts +2 -0
  162. package/dist/nodes/Chatwoot/resources/webhook/getAll.operation.js +5 -0
  163. package/dist/nodes/Chatwoot/resources/webhook/getAll.operation.js.map +1 -0
  164. package/dist/nodes/Chatwoot/resources/webhook/index.d.ts +3 -0
  165. package/dist/nodes/Chatwoot/resources/webhook/index.js +52 -0
  166. package/dist/nodes/Chatwoot/resources/webhook/index.js.map +1 -0
  167. package/dist/nodes/Chatwoot/resources/webhook/update.operation.d.ts +2 -0
  168. package/dist/nodes/Chatwoot/resources/webhook/update.operation.js +59 -0
  169. package/dist/nodes/Chatwoot/resources/webhook/update.operation.js.map +1 -0
  170. package/dist/nodes/Chatwoot/types.d.ts +322 -6
  171. package/dist/tsconfig.tsbuildinfo +1 -1
  172. package/package.json +4 -3
@@ -3,9 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Chatwoot = void 0;
4
4
  const n8n_workflow_1 = require("n8n-workflow");
5
5
  const GenericFunctions_1 = require("./GenericFunctions");
6
+ const account_1 = require("./resources/account");
7
+ const agent_1 = require("./resources/agent");
8
+ const agentBot_1 = require("./resources/agentBot");
9
+ const automationRule_1 = require("./resources/automationRule");
10
+ const team_1 = require("./resources/team");
11
+ const inbox_1 = require("./resources/inbox");
12
+ const label_1 = require("./resources/label");
13
+ const cannedResponse_1 = require("./resources/cannedResponse");
14
+ const customAttribute_1 = require("./resources/customAttribute");
15
+ const customFilter_1 = require("./resources/customFilter");
16
+ const webhook_1 = require("./resources/webhook");
6
17
  const conversation_1 = require("./resources/conversation");
7
18
  const message_1 = require("./resources/message");
8
19
  const contact_1 = require("./resources/contact");
20
+ const report_1 = require("./resources/report");
9
21
  class Chatwoot {
10
22
  constructor() {
11
23
  this.description = {
@@ -15,7 +27,7 @@ class Chatwoot {
15
27
  group: ['transform'],
16
28
  version: 1,
17
29
  subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
18
- description: 'Interact with Chatwoot API to manage conversations, messages, and contacts',
30
+ description: 'Interact with Chatwoot API to manage conversations, messages, contacts, and more',
19
31
  defaults: {
20
32
  name: 'Chatwoot',
21
33
  },
@@ -34,29 +46,64 @@ class Chatwoot {
34
46
  type: 'options',
35
47
  noDataExpression: true,
36
48
  options: [
37
- {
38
- name: 'Contact',
39
- value: 'contact',
40
- },
41
- {
42
- name: 'Conversation',
43
- value: 'conversation',
44
- },
45
- {
46
- name: 'Message',
47
- value: 'message',
48
- },
49
+ { name: 'Account', value: 'account' },
50
+ { name: 'Agent', value: 'agent' },
51
+ { name: 'Agent Bot', value: 'agentBot' },
52
+ { name: 'Automation Rule', value: 'automationRule' },
53
+ { name: 'Canned Response', value: 'cannedResponse' },
54
+ { name: 'Contact', value: 'contact' },
55
+ { name: 'Conversation', value: 'conversation' },
56
+ { name: 'Custom Attribute', value: 'customAttribute' },
57
+ { name: 'Custom Filter', value: 'customFilter' },
58
+ { name: 'Inbox', value: 'inbox' },
59
+ { name: 'Label', value: 'label' },
60
+ { name: 'Message', value: 'message' },
61
+ { name: 'Report', value: 'report' },
62
+ { name: 'Team', value: 'team' },
63
+ { name: 'Webhook', value: 'webhook' },
49
64
  ],
50
65
  default: 'conversation',
51
66
  },
67
+ account_1.accountOperations,
68
+ agent_1.agentOperations,
69
+ agentBot_1.agentBotOperations,
70
+ automationRule_1.automationRuleOperations,
71
+ team_1.teamOperations,
72
+ inbox_1.inboxOperations,
73
+ label_1.labelOperations,
74
+ cannedResponse_1.cannedResponseOperations,
75
+ customAttribute_1.customAttributeOperations,
76
+ customFilter_1.customFilterOperations,
77
+ webhook_1.webhookOperations,
52
78
  conversation_1.conversationOperations,
53
79
  message_1.messageOperations,
54
80
  contact_1.contactOperations,
81
+ report_1.reportOperations,
82
+ ...account_1.accountFields,
83
+ ...agent_1.agentFields,
84
+ ...agentBot_1.agentBotFields,
85
+ ...automationRule_1.automationRuleFields,
86
+ ...team_1.teamFields,
87
+ ...inbox_1.inboxFields,
88
+ ...label_1.labelFields,
89
+ ...cannedResponse_1.cannedResponseFields,
90
+ ...customAttribute_1.customAttributeFields,
91
+ ...customFilter_1.customFilterFields,
92
+ ...webhook_1.webhookFields,
55
93
  ...conversation_1.conversationFields,
56
94
  ...message_1.messageFields,
57
95
  ...contact_1.contactFields,
96
+ ...report_1.reportFields,
58
97
  ],
59
98
  };
99
+ this.methods = {
100
+ loadOptions: {
101
+ getAgents: GenericFunctions_1.getAgents,
102
+ getTeams: GenericFunctions_1.getTeams,
103
+ getInboxes: GenericFunctions_1.getInboxes,
104
+ getLabels: GenericFunctions_1.getLabels,
105
+ },
106
+ };
60
107
  }
61
108
  async execute() {
62
109
  const items = this.getInputData();
@@ -66,7 +113,274 @@ class Chatwoot {
66
113
  for (let i = 0; i < items.length; i++) {
67
114
  try {
68
115
  let responseData;
69
- if (resource === 'conversation') {
116
+ if (resource === 'account') {
117
+ if (operation === 'get') {
118
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '');
119
+ }
120
+ else if (operation === 'update') {
121
+ const updateFields = this.getNodeParameter('updateFields', i);
122
+ const body = {};
123
+ if (updateFields.name)
124
+ body.name = updateFields.name;
125
+ if (updateFields.locale)
126
+ body.locale = updateFields.locale;
127
+ if (updateFields.domain)
128
+ body.domain = updateFields.domain;
129
+ if (updateFields.support_email)
130
+ body.support_email = updateFields.support_email;
131
+ if (updateFields.auto_resolve_duration !== undefined) {
132
+ body.auto_resolve_duration = updateFields.auto_resolve_duration;
133
+ }
134
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', '', body);
135
+ }
136
+ else {
137
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
138
+ }
139
+ }
140
+ else if (resource === 'agent') {
141
+ if (operation === 'getAll') {
142
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/agents');
143
+ }
144
+ else if (operation === 'create') {
145
+ const name = this.getNodeParameter('name', i);
146
+ const email = this.getNodeParameter('email', i);
147
+ const role = this.getNodeParameter('role', i);
148
+ const additionalFields = this.getNodeParameter('additionalFields', i);
149
+ const body = { name, email, role };
150
+ if (additionalFields.availability_status) {
151
+ body.availability_status = additionalFields.availability_status;
152
+ }
153
+ if (additionalFields.auto_offline !== undefined) {
154
+ body.auto_offline = additionalFields.auto_offline;
155
+ }
156
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/agents', body);
157
+ }
158
+ else if (operation === 'update') {
159
+ const agentId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('agentId', i), 'Agent ID');
160
+ const updateFields = this.getNodeParameter('updateFields', i);
161
+ const body = {};
162
+ if (updateFields.name)
163
+ body.name = updateFields.name;
164
+ if (updateFields.role)
165
+ body.role = updateFields.role;
166
+ if (updateFields.availability_status)
167
+ body.availability_status = updateFields.availability_status;
168
+ if (updateFields.auto_offline !== undefined)
169
+ body.auto_offline = updateFields.auto_offline;
170
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/agents/${agentId}`, body);
171
+ }
172
+ else if (operation === 'delete') {
173
+ const agentId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('agentId', i), 'Agent ID');
174
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/agents/${agentId}`);
175
+ responseData = { success: true, id: agentId };
176
+ }
177
+ else {
178
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
179
+ }
180
+ }
181
+ else if (resource === 'team') {
182
+ if (operation === 'getAll') {
183
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/teams');
184
+ }
185
+ else if (operation === 'get') {
186
+ const teamId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('teamId', i), 'Team ID');
187
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/teams/${teamId}`);
188
+ }
189
+ else if (operation === 'create') {
190
+ const name = this.getNodeParameter('name', i);
191
+ const additionalFields = this.getNodeParameter('additionalFields', i);
192
+ const body = { name };
193
+ if (additionalFields.description)
194
+ body.description = additionalFields.description;
195
+ if (additionalFields.allow_auto_assign !== undefined) {
196
+ body.allow_auto_assign = additionalFields.allow_auto_assign;
197
+ }
198
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/teams', body);
199
+ }
200
+ else if (operation === 'update') {
201
+ const teamId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('teamId', i), 'Team ID');
202
+ const updateFields = this.getNodeParameter('updateFields', i);
203
+ const body = {};
204
+ if (updateFields.name)
205
+ body.name = updateFields.name;
206
+ if (updateFields.description)
207
+ body.description = updateFields.description;
208
+ if (updateFields.allow_auto_assign !== undefined)
209
+ body.allow_auto_assign = updateFields.allow_auto_assign;
210
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/teams/${teamId}`, body);
211
+ }
212
+ else if (operation === 'delete') {
213
+ const teamId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('teamId', i), 'Team ID');
214
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/teams/${teamId}`);
215
+ responseData = { success: true, id: teamId };
216
+ }
217
+ else {
218
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
219
+ }
220
+ }
221
+ else if (resource === 'inbox') {
222
+ if (operation === 'getAll') {
223
+ const response = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/inboxes');
224
+ responseData = (response.payload || response);
225
+ }
226
+ else if (operation === 'get') {
227
+ const inboxId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('inboxId', i), 'Inbox ID');
228
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/inboxes/${inboxId}`);
229
+ }
230
+ else if (operation === 'update') {
231
+ const inboxId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('inboxId', i), 'Inbox ID');
232
+ const updateFields = this.getNodeParameter('updateFields', i);
233
+ const body = { ...updateFields };
234
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/inboxes/${inboxId}`, body);
235
+ }
236
+ else {
237
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
238
+ }
239
+ }
240
+ else if (resource === 'label') {
241
+ if (operation === 'getAll') {
242
+ const response = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/labels');
243
+ responseData = (response.payload || response);
244
+ }
245
+ else if (operation === 'create') {
246
+ const title = this.getNodeParameter('title', i);
247
+ const additionalFields = this.getNodeParameter('additionalFields', i);
248
+ const body = { title };
249
+ if (additionalFields.description)
250
+ body.description = additionalFields.description;
251
+ if (additionalFields.color)
252
+ body.color = additionalFields.color;
253
+ if (additionalFields.show_on_sidebar !== undefined) {
254
+ body.show_on_sidebar = additionalFields.show_on_sidebar;
255
+ }
256
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/labels', body);
257
+ }
258
+ else if (operation === 'update') {
259
+ const labelId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('labelId', i), 'Label ID');
260
+ const updateFields = this.getNodeParameter('updateFields', i);
261
+ const body = { ...updateFields };
262
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/labels/${labelId}`, body);
263
+ }
264
+ else if (operation === 'delete') {
265
+ const labelId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('labelId', i), 'Label ID');
266
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/labels/${labelId}`);
267
+ responseData = { success: true, id: labelId };
268
+ }
269
+ else {
270
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
271
+ }
272
+ }
273
+ else if (resource === 'cannedResponse') {
274
+ if (operation === 'getAll') {
275
+ const options = this.getNodeParameter('options', i);
276
+ const qs = {};
277
+ if (options.search)
278
+ qs.search = options.search;
279
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/canned_responses', {}, qs);
280
+ }
281
+ else if (operation === 'create') {
282
+ const shortCode = this.getNodeParameter('shortCode', i);
283
+ const content = this.getNodeParameter('content', i);
284
+ const body = { short_code: shortCode, content };
285
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/canned_responses', body);
286
+ }
287
+ else if (operation === 'update') {
288
+ const cannedResponseId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('cannedResponseId', i), 'Canned Response ID');
289
+ const updateFields = this.getNodeParameter('updateFields', i);
290
+ const body = { ...updateFields };
291
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/canned_responses/${cannedResponseId}`, body);
292
+ }
293
+ else if (operation === 'delete') {
294
+ const cannedResponseId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('cannedResponseId', i), 'Canned Response ID');
295
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/canned_responses/${cannedResponseId}`);
296
+ responseData = { success: true, id: cannedResponseId };
297
+ }
298
+ else {
299
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
300
+ }
301
+ }
302
+ else if (resource === 'customAttribute') {
303
+ if (operation === 'getAll') {
304
+ const attributeModel = this.getNodeParameter('attributeModel', i);
305
+ const qs = { attribute_model: attributeModel };
306
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/custom_attribute_definitions', {}, qs);
307
+ }
308
+ else if (operation === 'get') {
309
+ const customAttributeId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('customAttributeId', i), 'Custom Attribute ID');
310
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/custom_attribute_definitions/${customAttributeId}`);
311
+ }
312
+ else if (operation === 'create') {
313
+ const attributeDisplayName = this.getNodeParameter('attributeDisplayName', i);
314
+ const attributeKey = this.getNodeParameter('attributeKey', i);
315
+ const attributeModel = this.getNodeParameter('attributeModel', i);
316
+ const attributeDisplayType = this.getNodeParameter('attributeDisplayType', i);
317
+ const additionalFields = this.getNodeParameter('additionalFields', i);
318
+ const body = {
319
+ attribute_display_name: attributeDisplayName,
320
+ attribute_key: attributeKey,
321
+ attribute_model: attributeModel,
322
+ attribute_display_type: attributeDisplayType,
323
+ };
324
+ if (additionalFields.attribute_description) {
325
+ body.attribute_description = additionalFields.attribute_description;
326
+ }
327
+ if (additionalFields.default_value)
328
+ body.default_value = additionalFields.default_value;
329
+ if (additionalFields.attribute_values) {
330
+ body.attribute_values = additionalFields.attribute_values.split(',').map(v => v.trim());
331
+ }
332
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/custom_attribute_definitions', body);
333
+ }
334
+ else if (operation === 'update') {
335
+ const customAttributeId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('customAttributeId', i), 'Custom Attribute ID');
336
+ const updateFields = this.getNodeParameter('updateFields', i);
337
+ const body = {};
338
+ if (updateFields.attribute_display_name)
339
+ body.attribute_display_name = updateFields.attribute_display_name;
340
+ if (updateFields.attribute_description)
341
+ body.attribute_description = updateFields.attribute_description;
342
+ if (updateFields.default_value)
343
+ body.default_value = updateFields.default_value;
344
+ if (updateFields.attribute_values) {
345
+ body.attribute_values = updateFields.attribute_values.split(',').map(v => v.trim());
346
+ }
347
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/custom_attribute_definitions/${customAttributeId}`, body);
348
+ }
349
+ else if (operation === 'delete') {
350
+ const customAttributeId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('customAttributeId', i), 'Custom Attribute ID');
351
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/custom_attribute_definitions/${customAttributeId}`);
352
+ responseData = { success: true, id: customAttributeId };
353
+ }
354
+ else {
355
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
356
+ }
357
+ }
358
+ else if (resource === 'webhook') {
359
+ if (operation === 'getAll') {
360
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/webhooks');
361
+ }
362
+ else if (operation === 'create') {
363
+ const url = this.getNodeParameter('url', i);
364
+ const subscriptions = this.getNodeParameter('subscriptions', i);
365
+ const body = { url, subscriptions };
366
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/webhooks', body);
367
+ }
368
+ else if (operation === 'update') {
369
+ const webhookId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('webhookId', i), 'Webhook ID');
370
+ const updateFields = this.getNodeParameter('updateFields', i);
371
+ const body = { ...updateFields };
372
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/webhooks/${webhookId}`, body);
373
+ }
374
+ else if (operation === 'delete') {
375
+ const webhookId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('webhookId', i), 'Webhook ID');
376
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/webhooks/${webhookId}`);
377
+ responseData = { success: true, id: webhookId };
378
+ }
379
+ else {
380
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
381
+ }
382
+ }
383
+ else if (resource === 'conversation') {
70
384
  if (operation === 'get') {
71
385
  const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
72
386
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/conversations/${conversationId}`);
@@ -75,31 +389,25 @@ class Chatwoot {
75
389
  const returnAll = this.getNodeParameter('returnAll', i);
76
390
  const filters = this.getNodeParameter('filters', i);
77
391
  const qs = {};
78
- if (filters.status && filters.status !== 'all') {
392
+ if (filters.status && filters.status !== 'all')
79
393
  qs.status = filters.status;
80
- }
81
- if (filters.assignee_type && filters.assignee_type !== 'all') {
394
+ if (filters.assignee_type && filters.assignee_type !== 'all')
82
395
  qs.assignee_type = filters.assignee_type;
83
- }
84
- if (filters.inbox_id) {
396
+ if (filters.inbox_id)
85
397
  qs.inbox_id = filters.inbox_id;
86
- }
87
- if (filters.team_id) {
398
+ if (filters.team_id)
88
399
  qs.team_id = filters.team_id;
89
- }
90
- if (filters.labels) {
91
- qs.labels = filters.labels.split(',').map((l) => l.trim());
92
- }
93
- if (filters.q) {
400
+ if (filters.labels)
401
+ qs.labels = filters.labels.split(',').map(l => l.trim());
402
+ if (filters.q)
94
403
  qs.q = filters.q;
95
- }
96
404
  if (returnAll) {
97
405
  responseData = await GenericFunctions_1.chatwootApiRequestAllItems.call(this, 'GET', '/conversations', {}, qs, 'payload');
98
406
  }
99
407
  else {
100
408
  const limit = this.getNodeParameter('limit', i);
101
409
  qs.page = 1;
102
- const result = (await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/conversations', {}, qs));
410
+ const result = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/conversations', {}, qs);
103
411
  const payload = (result.payload || []);
104
412
  responseData = payload.slice(0, limit);
105
413
  }
@@ -116,8 +424,56 @@ class Chatwoot {
116
424
  }
117
425
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/conversations/${conversationId}/toggle_status`, body);
118
426
  }
427
+ else if (operation === 'assign') {
428
+ const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
429
+ const assignmentType = this.getNodeParameter('assignmentType', i);
430
+ const body = {};
431
+ if (assignmentType === 'agent') {
432
+ body.assignee_id = (0, GenericFunctions_1.validateId)(this.getNodeParameter('assigneeId', i), 'Agent ID');
433
+ }
434
+ else if (assignmentType === 'team') {
435
+ body.team_id = (0, GenericFunctions_1.validateId)(this.getNodeParameter('teamId', i), 'Team ID');
436
+ }
437
+ else if (assignmentType === 'unassign') {
438
+ body.assignee_id = null;
439
+ }
440
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/conversations/${conversationId}/assignments`, body);
441
+ }
442
+ else if (operation === 'addLabels') {
443
+ const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
444
+ const labels = this.getNodeParameter('labels', i);
445
+ const body = { labels };
446
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/conversations/${conversationId}/labels`, body);
447
+ }
448
+ else if (operation === 'create') {
449
+ const sourceId = this.getNodeParameter('sourceId', i);
450
+ const inboxId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('inboxId', i), 'Inbox ID');
451
+ const additionalFields = this.getNodeParameter('additionalFields', i);
452
+ const body = {
453
+ source_id: sourceId,
454
+ inbox_id: inboxId,
455
+ };
456
+ if (additionalFields.contact_id)
457
+ body.contact_id = additionalFields.contact_id;
458
+ if (additionalFields.status)
459
+ body.status = additionalFields.status;
460
+ if (additionalFields.assignee_id)
461
+ body.assignee_id = additionalFields.assignee_id;
462
+ if (additionalFields.team_id)
463
+ body.team_id = additionalFields.team_id;
464
+ if (additionalFields.custom_attributes) {
465
+ body.custom_attributes = JSON.parse(additionalFields.custom_attributes);
466
+ }
467
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/conversations', body);
468
+ }
469
+ else if (operation === 'togglePriority') {
470
+ const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
471
+ const priority = this.getNodeParameter('priority', i);
472
+ const body = { priority };
473
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/conversations/${conversationId}/toggle_priority`, body);
474
+ }
119
475
  else {
120
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" is not supported for resource "conversation"`, { itemIndex: i });
476
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
121
477
  }
122
478
  }
123
479
  else if (resource === 'message') {
@@ -126,15 +482,12 @@ class Chatwoot {
126
482
  const content = this.getNodeParameter('content', i);
127
483
  const options = this.getNodeParameter('options', i);
128
484
  const body = { content };
129
- if (options.message_type) {
485
+ if (options.message_type)
130
486
  body.message_type = options.message_type;
131
- }
132
- if (options.private !== undefined) {
487
+ if (options.private !== undefined)
133
488
  body.private = options.private;
134
- }
135
- if (options.content_type) {
489
+ if (options.content_type)
136
490
  body.content_type = options.content_type;
137
- }
138
491
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/conversations/${conversationId}/messages`, body);
139
492
  }
140
493
  else if (operation === 'getAll') {
@@ -148,8 +501,14 @@ class Chatwoot {
148
501
  responseData = await GenericFunctions_1.chatwootApiRequestAllMessages.call(this, conversationId, limit);
149
502
  }
150
503
  }
504
+ else if (operation === 'delete') {
505
+ const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
506
+ const messageId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('messageId', i), 'Message ID');
507
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/conversations/${conversationId}/messages/${messageId}`);
508
+ responseData = { success: true, id: messageId };
509
+ }
151
510
  else {
152
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" is not supported for resource "message"`, { itemIndex: i });
511
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
153
512
  }
154
513
  }
155
514
  else if (resource === 'contact') {
@@ -157,26 +516,19 @@ class Chatwoot {
157
516
  const inboxId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('inboxId', i), 'Inbox ID');
158
517
  const name = this.getNodeParameter('name', i);
159
518
  const additionalFields = this.getNodeParameter('additionalFields', i);
160
- const body = {
161
- inbox_id: inboxId,
162
- };
163
- if (name) {
519
+ const body = { inbox_id: inboxId };
520
+ if (name)
164
521
  body.name = name;
165
- }
166
- if (additionalFields.email) {
522
+ if (additionalFields.email)
167
523
  body.email = additionalFields.email;
168
- }
169
- if (additionalFields.phone_number) {
524
+ if (additionalFields.phone_number)
170
525
  body.phone_number = additionalFields.phone_number;
171
- }
172
- if (additionalFields.identifier) {
526
+ if (additionalFields.identifier)
173
527
  body.identifier = additionalFields.identifier;
174
- }
175
528
  if (additionalFields.custom_attributes) {
176
- body.custom_attributes =
177
- typeof additionalFields.custom_attributes === 'string'
178
- ? JSON.parse(additionalFields.custom_attributes)
179
- : additionalFields.custom_attributes;
529
+ body.custom_attributes = typeof additionalFields.custom_attributes === 'string'
530
+ ? JSON.parse(additionalFields.custom_attributes)
531
+ : additionalFields.custom_attributes;
180
532
  }
181
533
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/contacts', body);
182
534
  }
@@ -188,16 +540,15 @@ class Chatwoot {
188
540
  const returnAll = this.getNodeParameter('returnAll', i);
189
541
  const options = this.getNodeParameter('options', i);
190
542
  const qs = {};
191
- if (options.sort) {
543
+ if (options.sort)
192
544
  qs.sort = options.sort;
193
- }
194
545
  if (returnAll) {
195
546
  responseData = await GenericFunctions_1.chatwootApiRequestAllItems.call(this, 'GET', '/contacts', {}, qs, 'payload');
196
547
  }
197
548
  else {
198
549
  const limit = this.getNodeParameter('limit', i);
199
550
  qs.page = 1;
200
- const result = (await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/contacts', {}, qs));
551
+ const result = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/contacts', {}, qs);
201
552
  const payload = (result.payload || []);
202
553
  responseData = payload.slice(0, limit);
203
554
  }
@@ -206,29 +557,22 @@ class Chatwoot {
206
557
  const contactId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('contactId', i), 'Contact ID');
207
558
  const updateFields = this.getNodeParameter('updateFields', i);
208
559
  const body = {};
209
- if (updateFields.name) {
560
+ if (updateFields.name)
210
561
  body.name = updateFields.name;
211
- }
212
- if (updateFields.email) {
562
+ if (updateFields.email)
213
563
  body.email = updateFields.email;
214
- }
215
- if (updateFields.phone_number) {
564
+ if (updateFields.phone_number)
216
565
  body.phone_number = updateFields.phone_number;
217
- }
218
- if (updateFields.identifier) {
566
+ if (updateFields.identifier)
219
567
  body.identifier = updateFields.identifier;
220
- }
221
- if (updateFields.avatar_url) {
568
+ if (updateFields.avatar_url)
222
569
  body.avatar_url = updateFields.avatar_url;
223
- }
224
- if (updateFields.blocked !== undefined) {
570
+ if (updateFields.blocked !== undefined)
225
571
  body.blocked = updateFields.blocked;
226
- }
227
572
  if (updateFields.custom_attributes) {
228
- body.custom_attributes =
229
- typeof updateFields.custom_attributes === 'string'
230
- ? JSON.parse(updateFields.custom_attributes)
231
- : updateFields.custom_attributes;
573
+ body.custom_attributes = typeof updateFields.custom_attributes === 'string'
574
+ ? JSON.parse(updateFields.custom_attributes)
575
+ : updateFields.custom_attributes;
232
576
  }
233
577
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PUT', `/contacts/${contactId}`, body);
234
578
  }
@@ -242,28 +586,218 @@ class Chatwoot {
242
586
  const returnAll = this.getNodeParameter('returnAll', i);
243
587
  const options = this.getNodeParameter('options', i);
244
588
  const qs = { q: query };
245
- if (options.sort) {
589
+ if (options.sort)
246
590
  qs.sort = options.sort;
247
- }
248
591
  if (returnAll) {
249
592
  responseData = await GenericFunctions_1.chatwootApiRequestAllItems.call(this, 'GET', '/contacts/search', {}, qs, 'payload');
250
593
  }
251
594
  else {
252
595
  const limit = this.getNodeParameter('limit', i);
253
596
  qs.page = 1;
254
- const result = (await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/contacts/search', {}, qs));
597
+ const result = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/contacts/search', {}, qs);
255
598
  const payload = (result.payload || []);
256
599
  responseData = payload.slice(0, limit);
257
600
  }
258
601
  }
602
+ else if (operation === 'getConversations') {
603
+ const contactId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('contactId', i), 'Contact ID');
604
+ const response = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/contacts/${contactId}/conversations`);
605
+ responseData = (response.payload || response);
606
+ }
607
+ else if (operation === 'merge') {
608
+ const baseContactId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('baseContactId', i), 'Base Contact ID');
609
+ const mergeeContactId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('mergeeContactId', i), 'Merge Contact ID');
610
+ const body = {
611
+ base_contact_id: baseContactId,
612
+ mergee_contact_id: mergeeContactId,
613
+ };
614
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/actions/contact_merge', body);
615
+ }
616
+ else {
617
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
618
+ }
619
+ }
620
+ else if (resource === 'agentBot') {
621
+ if (operation === 'getAll') {
622
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/agent_bots');
623
+ }
624
+ else if (operation === 'get') {
625
+ const agentBotId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('agentBotId', i), 'Agent Bot ID');
626
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/agent_bots/${agentBotId}`);
627
+ }
628
+ else if (operation === 'create') {
629
+ const name = this.getNodeParameter('name', i);
630
+ const additionalFields = this.getNodeParameter('additionalFields', i);
631
+ const body = { name };
632
+ if (additionalFields.description)
633
+ body.description = additionalFields.description;
634
+ if (additionalFields.outgoing_url)
635
+ body.outgoing_url = additionalFields.outgoing_url;
636
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/agent_bots', body);
637
+ }
638
+ else if (operation === 'update') {
639
+ const agentBotId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('agentBotId', i), 'Agent Bot ID');
640
+ const updateFields = this.getNodeParameter('updateFields', i);
641
+ const body = { ...updateFields };
642
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/agent_bots/${agentBotId}`, body);
643
+ }
644
+ else if (operation === 'delete') {
645
+ const agentBotId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('agentBotId', i), 'Agent Bot ID');
646
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/agent_bots/${agentBotId}`);
647
+ responseData = { success: true, id: agentBotId };
648
+ }
649
+ else {
650
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
651
+ }
652
+ }
653
+ else if (resource === 'automationRule') {
654
+ if (operation === 'getAll') {
655
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/automation_rules');
656
+ }
657
+ else if (operation === 'get') {
658
+ const automationRuleId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('automationRuleId', i), 'Automation Rule ID');
659
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/automation_rules/${automationRuleId}`);
660
+ }
661
+ else if (operation === 'create') {
662
+ const name = this.getNodeParameter('name', i);
663
+ const eventName = this.getNodeParameter('eventName', i);
664
+ const conditions = JSON.parse(this.getNodeParameter('conditions', i));
665
+ const actions = JSON.parse(this.getNodeParameter('actions', i));
666
+ const additionalFields = this.getNodeParameter('additionalFields', i);
667
+ const body = {
668
+ name,
669
+ event_name: eventName,
670
+ conditions,
671
+ actions,
672
+ };
673
+ if (additionalFields.description)
674
+ body.description = additionalFields.description;
675
+ if (additionalFields.active !== undefined)
676
+ body.active = additionalFields.active;
677
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/automation_rules', body);
678
+ }
679
+ else if (operation === 'update') {
680
+ const automationRuleId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('automationRuleId', i), 'Automation Rule ID');
681
+ const updateFields = this.getNodeParameter('updateFields', i);
682
+ const body = {};
683
+ if (updateFields.name)
684
+ body.name = updateFields.name;
685
+ if (updateFields.description)
686
+ body.description = updateFields.description;
687
+ if (updateFields.active !== undefined)
688
+ body.active = updateFields.active;
689
+ if (updateFields.conditions)
690
+ body.conditions = JSON.parse(updateFields.conditions);
691
+ if (updateFields.actions)
692
+ body.actions = JSON.parse(updateFields.actions);
693
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/automation_rules/${automationRuleId}`, body);
694
+ }
695
+ else if (operation === 'delete') {
696
+ const automationRuleId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('automationRuleId', i), 'Automation Rule ID');
697
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/automation_rules/${automationRuleId}`);
698
+ responseData = { success: true, id: automationRuleId };
699
+ }
700
+ else {
701
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
702
+ }
703
+ }
704
+ else if (resource === 'customFilter') {
705
+ if (operation === 'getAll') {
706
+ const filterType = this.getNodeParameter('filterType', i);
707
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/custom_filters', {}, { filter_type: filterType });
708
+ }
709
+ else if (operation === 'get') {
710
+ const customFilterId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('customFilterId', i), 'Custom Filter ID');
711
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/custom_filters/${customFilterId}`);
712
+ }
713
+ else if (operation === 'create') {
714
+ const name = this.getNodeParameter('name', i);
715
+ const filterType = this.getNodeParameter('filterType', i);
716
+ const query = JSON.parse(this.getNodeParameter('query', i));
717
+ const body = {
718
+ name,
719
+ filter_type: filterType,
720
+ query,
721
+ };
722
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/custom_filters', body);
723
+ }
724
+ else if (operation === 'update') {
725
+ const customFilterId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('customFilterId', i), 'Custom Filter ID');
726
+ const updateFields = this.getNodeParameter('updateFields', i);
727
+ const body = {};
728
+ if (updateFields.name)
729
+ body.name = updateFields.name;
730
+ if (updateFields.query)
731
+ body.query = JSON.parse(updateFields.query);
732
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/custom_filters/${customFilterId}`, body);
733
+ }
734
+ else if (operation === 'delete') {
735
+ const customFilterId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('customFilterId', i), 'Custom Filter ID');
736
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/custom_filters/${customFilterId}`);
737
+ responseData = { success: true, id: customFilterId };
738
+ }
739
+ else {
740
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
741
+ }
742
+ }
743
+ else if (resource === 'report') {
744
+ const qs = {};
745
+ if (operation === 'accountSummary') {
746
+ const since = new Date(this.getNodeParameter('since', i)).getTime() / 1000;
747
+ const until = new Date(this.getNodeParameter('until', i)).getTime() / 1000;
748
+ const metric = this.getNodeParameter('metric', i);
749
+ const options = this.getNodeParameter('options', i);
750
+ qs.since = since;
751
+ qs.until = until;
752
+ qs.metric = metric;
753
+ if (options.type)
754
+ qs.type = options.type;
755
+ if (options.id)
756
+ qs.id = options.id;
757
+ if (options.timezone_offset)
758
+ qs.timezone_offset = options.timezone_offset;
759
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/reports/summary', {}, qs);
760
+ }
761
+ else if (operation === 'agentStatistics') {
762
+ const since = new Date(this.getNodeParameter('since', i)).getTime() / 1000;
763
+ const until = new Date(this.getNodeParameter('until', i)).getTime() / 1000;
764
+ const options = this.getNodeParameter('options', i);
765
+ qs.since = since;
766
+ qs.until = until;
767
+ if (options.timezone_offset)
768
+ qs.timezone_offset = options.timezone_offset;
769
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/reports/agents', {}, qs);
770
+ }
771
+ else if (operation === 'conversationCounts') {
772
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/conversations/meta');
773
+ }
774
+ else if (operation === 'conversationStatistics') {
775
+ const since = new Date(this.getNodeParameter('since', i)).getTime() / 1000;
776
+ const until = new Date(this.getNodeParameter('until', i)).getTime() / 1000;
777
+ const groupBy = this.getNodeParameter('groupBy', i);
778
+ const options = this.getNodeParameter('options', i);
779
+ qs.since = since;
780
+ qs.until = until;
781
+ if (options.timezone_offset)
782
+ qs.timezone_offset = options.timezone_offset;
783
+ let endpoint = '/reports';
784
+ if (groupBy === 'agent')
785
+ endpoint = '/reports/conversations';
786
+ else if (groupBy === 'inbox')
787
+ endpoint = '/reports/inboxes';
788
+ else if (groupBy === 'team')
789
+ endpoint = '/reports/teams';
790
+ else if (groupBy === 'channel_type')
791
+ endpoint = '/reports/conversations';
792
+ qs.type = groupBy;
793
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', endpoint, {}, qs);
794
+ }
259
795
  else {
260
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" is not supported for resource "contact"`, { itemIndex: i });
796
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
261
797
  }
262
798
  }
263
799
  else {
264
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Resource "${resource}" is not supported`, {
265
- itemIndex: i,
266
- });
800
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Resource "${resource}" is not supported`, { itemIndex: i });
267
801
  }
268
802
  const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
269
803
  returnData.push(...executionData);