@renatoascencio/n8n-nodes-chatwoot 0.1.2 → 0.2.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 (149) hide show
  1. package/README.md +314 -80
  2. package/dist/nodes/Chatwoot/Chatwoot.node.d.ts +9 -0
  3. package/dist/nodes/Chatwoot/Chatwoot.node.js +383 -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 +10 -6
  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/cannedResponse/create.operation.d.ts +2 -0
  39. package/dist/nodes/Chatwoot/resources/cannedResponse/create.operation.js +38 -0
  40. package/dist/nodes/Chatwoot/resources/cannedResponse/create.operation.js.map +1 -0
  41. package/dist/nodes/Chatwoot/resources/cannedResponse/delete.operation.d.ts +2 -0
  42. package/dist/nodes/Chatwoot/resources/cannedResponse/delete.operation.js +20 -0
  43. package/dist/nodes/Chatwoot/resources/cannedResponse/delete.operation.js.map +1 -0
  44. package/dist/nodes/Chatwoot/resources/cannedResponse/getAll.operation.d.ts +2 -0
  45. package/dist/nodes/Chatwoot/resources/cannedResponse/getAll.operation.js +28 -0
  46. package/dist/nodes/Chatwoot/resources/cannedResponse/getAll.operation.js.map +1 -0
  47. package/dist/nodes/Chatwoot/resources/cannedResponse/index.d.ts +3 -0
  48. package/dist/nodes/Chatwoot/resources/cannedResponse/index.js +52 -0
  49. package/dist/nodes/Chatwoot/resources/cannedResponse/index.js.map +1 -0
  50. package/dist/nodes/Chatwoot/resources/cannedResponse/update.operation.d.ts +2 -0
  51. package/dist/nodes/Chatwoot/resources/cannedResponse/update.operation.js +52 -0
  52. package/dist/nodes/Chatwoot/resources/cannedResponse/update.operation.js.map +1 -0
  53. package/dist/nodes/Chatwoot/resources/contact/getConversations.operation.d.ts +2 -0
  54. package/dist/nodes/Chatwoot/resources/contact/getConversations.operation.js +20 -0
  55. package/dist/nodes/Chatwoot/resources/contact/getConversations.operation.js.map +1 -0
  56. package/dist/nodes/Chatwoot/resources/contact/index.js +16 -0
  57. package/dist/nodes/Chatwoot/resources/contact/index.js.map +1 -1
  58. package/dist/nodes/Chatwoot/resources/contact/merge.operation.d.ts +2 -0
  59. package/dist/nodes/Chatwoot/resources/contact/merge.operation.js +34 -0
  60. package/dist/nodes/Chatwoot/resources/contact/merge.operation.js.map +1 -0
  61. package/dist/nodes/Chatwoot/resources/conversation/addLabels.operation.d.ts +2 -0
  62. package/dist/nodes/Chatwoot/resources/conversation/addLabels.operation.js +37 -0
  63. package/dist/nodes/Chatwoot/resources/conversation/addLabels.operation.js.map +1 -0
  64. package/dist/nodes/Chatwoot/resources/conversation/assign.operation.d.ts +2 -0
  65. package/dist/nodes/Chatwoot/resources/conversation/assign.operation.js +87 -0
  66. package/dist/nodes/Chatwoot/resources/conversation/assign.operation.js.map +1 -0
  67. package/dist/nodes/Chatwoot/resources/conversation/index.js +16 -0
  68. package/dist/nodes/Chatwoot/resources/conversation/index.js.map +1 -1
  69. package/dist/nodes/Chatwoot/resources/customAttribute/create.operation.d.ts +2 -0
  70. package/dist/nodes/Chatwoot/resources/customAttribute/create.operation.js +122 -0
  71. package/dist/nodes/Chatwoot/resources/customAttribute/create.operation.js.map +1 -0
  72. package/dist/nodes/Chatwoot/resources/customAttribute/delete.operation.d.ts +2 -0
  73. package/dist/nodes/Chatwoot/resources/customAttribute/delete.operation.js +20 -0
  74. package/dist/nodes/Chatwoot/resources/customAttribute/delete.operation.js.map +1 -0
  75. package/dist/nodes/Chatwoot/resources/customAttribute/get.operation.d.ts +2 -0
  76. package/dist/nodes/Chatwoot/resources/customAttribute/get.operation.js +20 -0
  77. package/dist/nodes/Chatwoot/resources/customAttribute/get.operation.js.map +1 -0
  78. package/dist/nodes/Chatwoot/resources/customAttribute/getAll.operation.d.ts +2 -0
  79. package/dist/nodes/Chatwoot/resources/customAttribute/getAll.operation.js +32 -0
  80. package/dist/nodes/Chatwoot/resources/customAttribute/getAll.operation.js.map +1 -0
  81. package/dist/nodes/Chatwoot/resources/customAttribute/index.d.ts +3 -0
  82. package/dist/nodes/Chatwoot/resources/customAttribute/index.js +60 -0
  83. package/dist/nodes/Chatwoot/resources/customAttribute/index.js.map +1 -0
  84. package/dist/nodes/Chatwoot/resources/customAttribute/update.operation.d.ts +2 -0
  85. package/dist/nodes/Chatwoot/resources/customAttribute/update.operation.js +64 -0
  86. package/dist/nodes/Chatwoot/resources/customAttribute/update.operation.js.map +1 -0
  87. package/dist/nodes/Chatwoot/resources/inbox/get.operation.d.ts +2 -0
  88. package/dist/nodes/Chatwoot/resources/inbox/get.operation.js +23 -0
  89. package/dist/nodes/Chatwoot/resources/inbox/get.operation.js.map +1 -0
  90. package/dist/nodes/Chatwoot/resources/inbox/getAll.operation.d.ts +2 -0
  91. package/dist/nodes/Chatwoot/resources/inbox/getAll.operation.js +5 -0
  92. package/dist/nodes/Chatwoot/resources/inbox/getAll.operation.js.map +1 -0
  93. package/dist/nodes/Chatwoot/resources/inbox/index.d.ts +3 -0
  94. package/dist/nodes/Chatwoot/resources/inbox/index.js +44 -0
  95. package/dist/nodes/Chatwoot/resources/inbox/index.js.map +1 -0
  96. package/dist/nodes/Chatwoot/resources/inbox/update.operation.d.ts +2 -0
  97. package/dist/nodes/Chatwoot/resources/inbox/update.operation.js +143 -0
  98. package/dist/nodes/Chatwoot/resources/inbox/update.operation.js.map +1 -0
  99. package/dist/nodes/Chatwoot/resources/label/create.operation.d.ts +2 -0
  100. package/dist/nodes/Chatwoot/resources/label/create.operation.js +56 -0
  101. package/dist/nodes/Chatwoot/resources/label/create.operation.js.map +1 -0
  102. package/dist/nodes/Chatwoot/resources/label/delete.operation.d.ts +2 -0
  103. package/dist/nodes/Chatwoot/resources/label/delete.operation.js +23 -0
  104. package/dist/nodes/Chatwoot/resources/label/delete.operation.js.map +1 -0
  105. package/dist/nodes/Chatwoot/resources/label/getAll.operation.d.ts +2 -0
  106. package/dist/nodes/Chatwoot/resources/label/getAll.operation.js +5 -0
  107. package/dist/nodes/Chatwoot/resources/label/getAll.operation.js.map +1 -0
  108. package/dist/nodes/Chatwoot/resources/label/index.d.ts +3 -0
  109. package/dist/nodes/Chatwoot/resources/label/index.js +52 -0
  110. package/dist/nodes/Chatwoot/resources/label/index.js.map +1 -0
  111. package/dist/nodes/Chatwoot/resources/label/update.operation.d.ts +2 -0
  112. package/dist/nodes/Chatwoot/resources/label/update.operation.js +66 -0
  113. package/dist/nodes/Chatwoot/resources/label/update.operation.js.map +1 -0
  114. package/dist/nodes/Chatwoot/resources/team/create.operation.d.ts +2 -0
  115. package/dist/nodes/Chatwoot/resources/team/create.operation.js +49 -0
  116. package/dist/nodes/Chatwoot/resources/team/create.operation.js.map +1 -0
  117. package/dist/nodes/Chatwoot/resources/team/delete.operation.d.ts +2 -0
  118. package/dist/nodes/Chatwoot/resources/team/delete.operation.js +23 -0
  119. package/dist/nodes/Chatwoot/resources/team/delete.operation.js.map +1 -0
  120. package/dist/nodes/Chatwoot/resources/team/get.operation.d.ts +2 -0
  121. package/dist/nodes/Chatwoot/resources/team/get.operation.js +23 -0
  122. package/dist/nodes/Chatwoot/resources/team/get.operation.js.map +1 -0
  123. package/dist/nodes/Chatwoot/resources/team/getAll.operation.d.ts +2 -0
  124. package/dist/nodes/Chatwoot/resources/team/getAll.operation.js +5 -0
  125. package/dist/nodes/Chatwoot/resources/team/getAll.operation.js.map +1 -0
  126. package/dist/nodes/Chatwoot/resources/team/index.d.ts +3 -0
  127. package/dist/nodes/Chatwoot/resources/team/index.js +60 -0
  128. package/dist/nodes/Chatwoot/resources/team/index.js.map +1 -0
  129. package/dist/nodes/Chatwoot/resources/team/update.operation.d.ts +2 -0
  130. package/dist/nodes/Chatwoot/resources/team/update.operation.js +59 -0
  131. package/dist/nodes/Chatwoot/resources/team/update.operation.js.map +1 -0
  132. package/dist/nodes/Chatwoot/resources/webhook/create.operation.d.ts +2 -0
  133. package/dist/nodes/Chatwoot/resources/webhook/create.operation.js +77 -0
  134. package/dist/nodes/Chatwoot/resources/webhook/create.operation.js.map +1 -0
  135. package/dist/nodes/Chatwoot/resources/webhook/delete.operation.d.ts +2 -0
  136. package/dist/nodes/Chatwoot/resources/webhook/delete.operation.js +20 -0
  137. package/dist/nodes/Chatwoot/resources/webhook/delete.operation.js.map +1 -0
  138. package/dist/nodes/Chatwoot/resources/webhook/getAll.operation.d.ts +2 -0
  139. package/dist/nodes/Chatwoot/resources/webhook/getAll.operation.js +5 -0
  140. package/dist/nodes/Chatwoot/resources/webhook/getAll.operation.js.map +1 -0
  141. package/dist/nodes/Chatwoot/resources/webhook/index.d.ts +3 -0
  142. package/dist/nodes/Chatwoot/resources/webhook/index.js +52 -0
  143. package/dist/nodes/Chatwoot/resources/webhook/index.js.map +1 -0
  144. package/dist/nodes/Chatwoot/resources/webhook/update.operation.d.ts +2 -0
  145. package/dist/nodes/Chatwoot/resources/webhook/update.operation.js +59 -0
  146. package/dist/nodes/Chatwoot/resources/webhook/update.operation.js.map +1 -0
  147. package/dist/nodes/Chatwoot/types.d.ts +305 -8
  148. package/dist/tsconfig.tsbuildinfo +1 -1
  149. package/package.json +4 -3
@@ -3,6 +3,14 @@ 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 team_1 = require("./resources/team");
9
+ const inbox_1 = require("./resources/inbox");
10
+ const label_1 = require("./resources/label");
11
+ const cannedResponse_1 = require("./resources/cannedResponse");
12
+ const customAttribute_1 = require("./resources/customAttribute");
13
+ const webhook_1 = require("./resources/webhook");
6
14
  const conversation_1 = require("./resources/conversation");
7
15
  const message_1 = require("./resources/message");
8
16
  const contact_1 = require("./resources/contact");
@@ -15,7 +23,7 @@ class Chatwoot {
15
23
  group: ['transform'],
16
24
  version: 1,
17
25
  subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
18
- description: 'Interact with Chatwoot API to manage conversations, messages, and contacts',
26
+ description: 'Interact with Chatwoot API to manage conversations, messages, contacts, and more',
19
27
  defaults: {
20
28
  name: 'Chatwoot',
21
29
  },
@@ -34,29 +42,52 @@ class Chatwoot {
34
42
  type: 'options',
35
43
  noDataExpression: true,
36
44
  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
- },
45
+ { name: 'Account', value: 'account' },
46
+ { name: 'Agent', value: 'agent' },
47
+ { name: 'Canned Response', value: 'cannedResponse' },
48
+ { name: 'Contact', value: 'contact' },
49
+ { name: 'Conversation', value: 'conversation' },
50
+ { name: 'Custom Attribute', value: 'customAttribute' },
51
+ { name: 'Inbox', value: 'inbox' },
52
+ { name: 'Label', value: 'label' },
53
+ { name: 'Message', value: 'message' },
54
+ { name: 'Team', value: 'team' },
55
+ { name: 'Webhook', value: 'webhook' },
49
56
  ],
50
57
  default: 'conversation',
51
58
  },
59
+ account_1.accountOperations,
60
+ agent_1.agentOperations,
61
+ team_1.teamOperations,
62
+ inbox_1.inboxOperations,
63
+ label_1.labelOperations,
64
+ cannedResponse_1.cannedResponseOperations,
65
+ customAttribute_1.customAttributeOperations,
66
+ webhook_1.webhookOperations,
52
67
  conversation_1.conversationOperations,
53
68
  message_1.messageOperations,
54
69
  contact_1.contactOperations,
70
+ ...account_1.accountFields,
71
+ ...agent_1.agentFields,
72
+ ...team_1.teamFields,
73
+ ...inbox_1.inboxFields,
74
+ ...label_1.labelFields,
75
+ ...cannedResponse_1.cannedResponseFields,
76
+ ...customAttribute_1.customAttributeFields,
77
+ ...webhook_1.webhookFields,
55
78
  ...conversation_1.conversationFields,
56
79
  ...message_1.messageFields,
57
80
  ...contact_1.contactFields,
58
81
  ],
59
82
  };
83
+ this.methods = {
84
+ loadOptions: {
85
+ getAgents: GenericFunctions_1.getAgents,
86
+ getTeams: GenericFunctions_1.getTeams,
87
+ getInboxes: GenericFunctions_1.getInboxes,
88
+ getLabels: GenericFunctions_1.getLabels,
89
+ },
90
+ };
60
91
  }
61
92
  async execute() {
62
93
  const items = this.getInputData();
@@ -66,7 +97,274 @@ class Chatwoot {
66
97
  for (let i = 0; i < items.length; i++) {
67
98
  try {
68
99
  let responseData;
69
- if (resource === 'conversation') {
100
+ if (resource === 'account') {
101
+ if (operation === 'get') {
102
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '');
103
+ }
104
+ else if (operation === 'update') {
105
+ const updateFields = this.getNodeParameter('updateFields', i);
106
+ const body = {};
107
+ if (updateFields.name)
108
+ body.name = updateFields.name;
109
+ if (updateFields.locale)
110
+ body.locale = updateFields.locale;
111
+ if (updateFields.domain)
112
+ body.domain = updateFields.domain;
113
+ if (updateFields.support_email)
114
+ body.support_email = updateFields.support_email;
115
+ if (updateFields.auto_resolve_duration !== undefined) {
116
+ body.auto_resolve_duration = updateFields.auto_resolve_duration;
117
+ }
118
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', '', body);
119
+ }
120
+ else {
121
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
122
+ }
123
+ }
124
+ else if (resource === 'agent') {
125
+ if (operation === 'getAll') {
126
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/agents');
127
+ }
128
+ else if (operation === 'create') {
129
+ const name = this.getNodeParameter('name', i);
130
+ const email = this.getNodeParameter('email', i);
131
+ const role = this.getNodeParameter('role', i);
132
+ const additionalFields = this.getNodeParameter('additionalFields', i);
133
+ const body = { name, email, role };
134
+ if (additionalFields.availability_status) {
135
+ body.availability_status = additionalFields.availability_status;
136
+ }
137
+ if (additionalFields.auto_offline !== undefined) {
138
+ body.auto_offline = additionalFields.auto_offline;
139
+ }
140
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/agents', body);
141
+ }
142
+ else if (operation === 'update') {
143
+ const agentId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('agentId', i), 'Agent ID');
144
+ const updateFields = this.getNodeParameter('updateFields', i);
145
+ const body = {};
146
+ if (updateFields.name)
147
+ body.name = updateFields.name;
148
+ if (updateFields.role)
149
+ body.role = updateFields.role;
150
+ if (updateFields.availability_status)
151
+ body.availability_status = updateFields.availability_status;
152
+ if (updateFields.auto_offline !== undefined)
153
+ body.auto_offline = updateFields.auto_offline;
154
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/agents/${agentId}`, body);
155
+ }
156
+ else if (operation === 'delete') {
157
+ const agentId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('agentId', i), 'Agent ID');
158
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/agents/${agentId}`);
159
+ responseData = { success: true, id: agentId };
160
+ }
161
+ else {
162
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
163
+ }
164
+ }
165
+ else if (resource === 'team') {
166
+ if (operation === 'getAll') {
167
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/teams');
168
+ }
169
+ else if (operation === 'get') {
170
+ const teamId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('teamId', i), 'Team ID');
171
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/teams/${teamId}`);
172
+ }
173
+ else if (operation === 'create') {
174
+ const name = this.getNodeParameter('name', i);
175
+ const additionalFields = this.getNodeParameter('additionalFields', i);
176
+ const body = { name };
177
+ if (additionalFields.description)
178
+ body.description = additionalFields.description;
179
+ if (additionalFields.allow_auto_assign !== undefined) {
180
+ body.allow_auto_assign = additionalFields.allow_auto_assign;
181
+ }
182
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/teams', body);
183
+ }
184
+ else if (operation === 'update') {
185
+ const teamId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('teamId', i), 'Team ID');
186
+ const updateFields = this.getNodeParameter('updateFields', i);
187
+ const body = {};
188
+ if (updateFields.name)
189
+ body.name = updateFields.name;
190
+ if (updateFields.description)
191
+ body.description = updateFields.description;
192
+ if (updateFields.allow_auto_assign !== undefined)
193
+ body.allow_auto_assign = updateFields.allow_auto_assign;
194
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/teams/${teamId}`, body);
195
+ }
196
+ else if (operation === 'delete') {
197
+ const teamId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('teamId', i), 'Team ID');
198
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/teams/${teamId}`);
199
+ responseData = { success: true, id: teamId };
200
+ }
201
+ else {
202
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
203
+ }
204
+ }
205
+ else if (resource === 'inbox') {
206
+ if (operation === 'getAll') {
207
+ const response = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/inboxes');
208
+ responseData = (response.payload || response);
209
+ }
210
+ else if (operation === 'get') {
211
+ const inboxId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('inboxId', i), 'Inbox ID');
212
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/inboxes/${inboxId}`);
213
+ }
214
+ else if (operation === 'update') {
215
+ const inboxId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('inboxId', i), 'Inbox ID');
216
+ const updateFields = this.getNodeParameter('updateFields', i);
217
+ const body = { ...updateFields };
218
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/inboxes/${inboxId}`, body);
219
+ }
220
+ else {
221
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
222
+ }
223
+ }
224
+ else if (resource === 'label') {
225
+ if (operation === 'getAll') {
226
+ const response = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/labels');
227
+ responseData = (response.payload || response);
228
+ }
229
+ else if (operation === 'create') {
230
+ const title = this.getNodeParameter('title', i);
231
+ const additionalFields = this.getNodeParameter('additionalFields', i);
232
+ const body = { title };
233
+ if (additionalFields.description)
234
+ body.description = additionalFields.description;
235
+ if (additionalFields.color)
236
+ body.color = additionalFields.color;
237
+ if (additionalFields.show_on_sidebar !== undefined) {
238
+ body.show_on_sidebar = additionalFields.show_on_sidebar;
239
+ }
240
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/labels', body);
241
+ }
242
+ else if (operation === 'update') {
243
+ const labelId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('labelId', i), 'Label ID');
244
+ const updateFields = this.getNodeParameter('updateFields', i);
245
+ const body = { ...updateFields };
246
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/labels/${labelId}`, body);
247
+ }
248
+ else if (operation === 'delete') {
249
+ const labelId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('labelId', i), 'Label ID');
250
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/labels/${labelId}`);
251
+ responseData = { success: true, id: labelId };
252
+ }
253
+ else {
254
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
255
+ }
256
+ }
257
+ else if (resource === 'cannedResponse') {
258
+ if (operation === 'getAll') {
259
+ const options = this.getNodeParameter('options', i);
260
+ const qs = {};
261
+ if (options.search)
262
+ qs.search = options.search;
263
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/canned_responses', {}, qs);
264
+ }
265
+ else if (operation === 'create') {
266
+ const shortCode = this.getNodeParameter('shortCode', i);
267
+ const content = this.getNodeParameter('content', i);
268
+ const body = { short_code: shortCode, content };
269
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/canned_responses', body);
270
+ }
271
+ else if (operation === 'update') {
272
+ const cannedResponseId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('cannedResponseId', i), 'Canned Response ID');
273
+ const updateFields = this.getNodeParameter('updateFields', i);
274
+ const body = { ...updateFields };
275
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/canned_responses/${cannedResponseId}`, body);
276
+ }
277
+ else if (operation === 'delete') {
278
+ const cannedResponseId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('cannedResponseId', i), 'Canned Response ID');
279
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/canned_responses/${cannedResponseId}`);
280
+ responseData = { success: true, id: cannedResponseId };
281
+ }
282
+ else {
283
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
284
+ }
285
+ }
286
+ else if (resource === 'customAttribute') {
287
+ if (operation === 'getAll') {
288
+ const attributeModel = this.getNodeParameter('attributeModel', i);
289
+ const qs = { attribute_model: attributeModel };
290
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/custom_attribute_definitions', {}, qs);
291
+ }
292
+ else if (operation === 'get') {
293
+ const customAttributeId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('customAttributeId', i), 'Custom Attribute ID');
294
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/custom_attribute_definitions/${customAttributeId}`);
295
+ }
296
+ else if (operation === 'create') {
297
+ const attributeDisplayName = this.getNodeParameter('attributeDisplayName', i);
298
+ const attributeKey = this.getNodeParameter('attributeKey', i);
299
+ const attributeModel = this.getNodeParameter('attributeModel', i);
300
+ const attributeDisplayType = this.getNodeParameter('attributeDisplayType', i);
301
+ const additionalFields = this.getNodeParameter('additionalFields', i);
302
+ const body = {
303
+ attribute_display_name: attributeDisplayName,
304
+ attribute_key: attributeKey,
305
+ attribute_model: attributeModel,
306
+ attribute_display_type: attributeDisplayType,
307
+ };
308
+ if (additionalFields.attribute_description) {
309
+ body.attribute_description = additionalFields.attribute_description;
310
+ }
311
+ if (additionalFields.default_value)
312
+ body.default_value = additionalFields.default_value;
313
+ if (additionalFields.attribute_values) {
314
+ body.attribute_values = additionalFields.attribute_values.split(',').map(v => v.trim());
315
+ }
316
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/custom_attribute_definitions', body);
317
+ }
318
+ else if (operation === 'update') {
319
+ const customAttributeId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('customAttributeId', i), 'Custom Attribute ID');
320
+ const updateFields = this.getNodeParameter('updateFields', i);
321
+ const body = {};
322
+ if (updateFields.attribute_display_name)
323
+ body.attribute_display_name = updateFields.attribute_display_name;
324
+ if (updateFields.attribute_description)
325
+ body.attribute_description = updateFields.attribute_description;
326
+ if (updateFields.default_value)
327
+ body.default_value = updateFields.default_value;
328
+ if (updateFields.attribute_values) {
329
+ body.attribute_values = updateFields.attribute_values.split(',').map(v => v.trim());
330
+ }
331
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/custom_attribute_definitions/${customAttributeId}`, body);
332
+ }
333
+ else if (operation === 'delete') {
334
+ const customAttributeId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('customAttributeId', i), 'Custom Attribute ID');
335
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/custom_attribute_definitions/${customAttributeId}`);
336
+ responseData = { success: true, id: customAttributeId };
337
+ }
338
+ else {
339
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
340
+ }
341
+ }
342
+ else if (resource === 'webhook') {
343
+ if (operation === 'getAll') {
344
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/webhooks');
345
+ }
346
+ else if (operation === 'create') {
347
+ const url = this.getNodeParameter('url', i);
348
+ const subscriptions = this.getNodeParameter('subscriptions', i);
349
+ const body = { url, subscriptions };
350
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/webhooks', body);
351
+ }
352
+ else if (operation === 'update') {
353
+ const webhookId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('webhookId', i), 'Webhook ID');
354
+ const updateFields = this.getNodeParameter('updateFields', i);
355
+ const body = { ...updateFields };
356
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PATCH', `/webhooks/${webhookId}`, body);
357
+ }
358
+ else if (operation === 'delete') {
359
+ const webhookId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('webhookId', i), 'Webhook ID');
360
+ await GenericFunctions_1.chatwootApiRequest.call(this, 'DELETE', `/webhooks/${webhookId}`);
361
+ responseData = { success: true, id: webhookId };
362
+ }
363
+ else {
364
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
365
+ }
366
+ }
367
+ else if (resource === 'conversation') {
70
368
  if (operation === 'get') {
71
369
  const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
72
370
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/conversations/${conversationId}`);
@@ -75,31 +373,25 @@ class Chatwoot {
75
373
  const returnAll = this.getNodeParameter('returnAll', i);
76
374
  const filters = this.getNodeParameter('filters', i);
77
375
  const qs = {};
78
- if (filters.status && filters.status !== 'all') {
376
+ if (filters.status && filters.status !== 'all')
79
377
  qs.status = filters.status;
80
- }
81
- if (filters.assignee_type && filters.assignee_type !== 'all') {
378
+ if (filters.assignee_type && filters.assignee_type !== 'all')
82
379
  qs.assignee_type = filters.assignee_type;
83
- }
84
- if (filters.inbox_id) {
380
+ if (filters.inbox_id)
85
381
  qs.inbox_id = filters.inbox_id;
86
- }
87
- if (filters.team_id) {
382
+ if (filters.team_id)
88
383
  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) {
384
+ if (filters.labels)
385
+ qs.labels = filters.labels.split(',').map(l => l.trim());
386
+ if (filters.q)
94
387
  qs.q = filters.q;
95
- }
96
388
  if (returnAll) {
97
389
  responseData = await GenericFunctions_1.chatwootApiRequestAllItems.call(this, 'GET', '/conversations', {}, qs, 'payload');
98
390
  }
99
391
  else {
100
392
  const limit = this.getNodeParameter('limit', i);
101
393
  qs.page = 1;
102
- const result = (await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/conversations', {}, qs));
394
+ const result = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/conversations', {}, qs);
103
395
  const payload = (result.payload || []);
104
396
  responseData = payload.slice(0, limit);
105
397
  }
@@ -116,8 +408,29 @@ class Chatwoot {
116
408
  }
117
409
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/conversations/${conversationId}/toggle_status`, body);
118
410
  }
411
+ else if (operation === 'assign') {
412
+ const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
413
+ const assignmentType = this.getNodeParameter('assignmentType', i);
414
+ const body = {};
415
+ if (assignmentType === 'agent') {
416
+ body.assignee_id = (0, GenericFunctions_1.validateId)(this.getNodeParameter('assigneeId', i), 'Agent ID');
417
+ }
418
+ else if (assignmentType === 'team') {
419
+ body.team_id = (0, GenericFunctions_1.validateId)(this.getNodeParameter('teamId', i), 'Team ID');
420
+ }
421
+ else if (assignmentType === 'unassign') {
422
+ body.assignee_id = null;
423
+ }
424
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/conversations/${conversationId}/assignments`, body);
425
+ }
426
+ else if (operation === 'addLabels') {
427
+ const conversationId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('conversationId', i), 'Conversation ID');
428
+ const labels = this.getNodeParameter('labels', i);
429
+ const body = { labels };
430
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/conversations/${conversationId}/labels`, body);
431
+ }
119
432
  else {
120
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" is not supported for resource "conversation"`, { itemIndex: i });
433
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
121
434
  }
122
435
  }
123
436
  else if (resource === 'message') {
@@ -126,15 +439,12 @@ class Chatwoot {
126
439
  const content = this.getNodeParameter('content', i);
127
440
  const options = this.getNodeParameter('options', i);
128
441
  const body = { content };
129
- if (options.message_type) {
442
+ if (options.message_type)
130
443
  body.message_type = options.message_type;
131
- }
132
- if (options.private !== undefined) {
444
+ if (options.private !== undefined)
133
445
  body.private = options.private;
134
- }
135
- if (options.content_type) {
446
+ if (options.content_type)
136
447
  body.content_type = options.content_type;
137
- }
138
448
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', `/conversations/${conversationId}/messages`, body);
139
449
  }
140
450
  else if (operation === 'getAll') {
@@ -149,7 +459,7 @@ class Chatwoot {
149
459
  }
150
460
  }
151
461
  else {
152
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" is not supported for resource "message"`, { itemIndex: i });
462
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
153
463
  }
154
464
  }
155
465
  else if (resource === 'contact') {
@@ -157,26 +467,19 @@ class Chatwoot {
157
467
  const inboxId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('inboxId', i), 'Inbox ID');
158
468
  const name = this.getNodeParameter('name', i);
159
469
  const additionalFields = this.getNodeParameter('additionalFields', i);
160
- const body = {
161
- inbox_id: inboxId,
162
- };
163
- if (name) {
470
+ const body = { inbox_id: inboxId };
471
+ if (name)
164
472
  body.name = name;
165
- }
166
- if (additionalFields.email) {
473
+ if (additionalFields.email)
167
474
  body.email = additionalFields.email;
168
- }
169
- if (additionalFields.phone_number) {
475
+ if (additionalFields.phone_number)
170
476
  body.phone_number = additionalFields.phone_number;
171
- }
172
- if (additionalFields.identifier) {
477
+ if (additionalFields.identifier)
173
478
  body.identifier = additionalFields.identifier;
174
- }
175
479
  if (additionalFields.custom_attributes) {
176
- body.custom_attributes =
177
- typeof additionalFields.custom_attributes === 'string'
178
- ? JSON.parse(additionalFields.custom_attributes)
179
- : additionalFields.custom_attributes;
480
+ body.custom_attributes = typeof additionalFields.custom_attributes === 'string'
481
+ ? JSON.parse(additionalFields.custom_attributes)
482
+ : additionalFields.custom_attributes;
180
483
  }
181
484
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/contacts', body);
182
485
  }
@@ -188,16 +491,15 @@ class Chatwoot {
188
491
  const returnAll = this.getNodeParameter('returnAll', i);
189
492
  const options = this.getNodeParameter('options', i);
190
493
  const qs = {};
191
- if (options.sort) {
494
+ if (options.sort)
192
495
  qs.sort = options.sort;
193
- }
194
496
  if (returnAll) {
195
497
  responseData = await GenericFunctions_1.chatwootApiRequestAllItems.call(this, 'GET', '/contacts', {}, qs, 'payload');
196
498
  }
197
499
  else {
198
500
  const limit = this.getNodeParameter('limit', i);
199
501
  qs.page = 1;
200
- const result = (await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/contacts', {}, qs));
502
+ const result = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/contacts', {}, qs);
201
503
  const payload = (result.payload || []);
202
504
  responseData = payload.slice(0, limit);
203
505
  }
@@ -206,29 +508,22 @@ class Chatwoot {
206
508
  const contactId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('contactId', i), 'Contact ID');
207
509
  const updateFields = this.getNodeParameter('updateFields', i);
208
510
  const body = {};
209
- if (updateFields.name) {
511
+ if (updateFields.name)
210
512
  body.name = updateFields.name;
211
- }
212
- if (updateFields.email) {
513
+ if (updateFields.email)
213
514
  body.email = updateFields.email;
214
- }
215
- if (updateFields.phone_number) {
515
+ if (updateFields.phone_number)
216
516
  body.phone_number = updateFields.phone_number;
217
- }
218
- if (updateFields.identifier) {
517
+ if (updateFields.identifier)
219
518
  body.identifier = updateFields.identifier;
220
- }
221
- if (updateFields.avatar_url) {
519
+ if (updateFields.avatar_url)
222
520
  body.avatar_url = updateFields.avatar_url;
223
- }
224
- if (updateFields.blocked !== undefined) {
521
+ if (updateFields.blocked !== undefined)
225
522
  body.blocked = updateFields.blocked;
226
- }
227
523
  if (updateFields.custom_attributes) {
228
- body.custom_attributes =
229
- typeof updateFields.custom_attributes === 'string'
230
- ? JSON.parse(updateFields.custom_attributes)
231
- : updateFields.custom_attributes;
524
+ body.custom_attributes = typeof updateFields.custom_attributes === 'string'
525
+ ? JSON.parse(updateFields.custom_attributes)
526
+ : updateFields.custom_attributes;
232
527
  }
233
528
  responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'PUT', `/contacts/${contactId}`, body);
234
529
  }
@@ -242,28 +537,39 @@ class Chatwoot {
242
537
  const returnAll = this.getNodeParameter('returnAll', i);
243
538
  const options = this.getNodeParameter('options', i);
244
539
  const qs = { q: query };
245
- if (options.sort) {
540
+ if (options.sort)
246
541
  qs.sort = options.sort;
247
- }
248
542
  if (returnAll) {
249
543
  responseData = await GenericFunctions_1.chatwootApiRequestAllItems.call(this, 'GET', '/contacts/search', {}, qs, 'payload');
250
544
  }
251
545
  else {
252
546
  const limit = this.getNodeParameter('limit', i);
253
547
  qs.page = 1;
254
- const result = (await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/contacts/search', {}, qs));
548
+ const result = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', '/contacts/search', {}, qs);
255
549
  const payload = (result.payload || []);
256
550
  responseData = payload.slice(0, limit);
257
551
  }
258
552
  }
553
+ else if (operation === 'getConversations') {
554
+ const contactId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('contactId', i), 'Contact ID');
555
+ const response = await GenericFunctions_1.chatwootApiRequest.call(this, 'GET', `/contacts/${contactId}/conversations`);
556
+ responseData = (response.payload || response);
557
+ }
558
+ else if (operation === 'merge') {
559
+ const baseContactId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('baseContactId', i), 'Base Contact ID');
560
+ const mergeeContactId = (0, GenericFunctions_1.validateId)(this.getNodeParameter('mergeeContactId', i), 'Merge Contact ID');
561
+ const body = {
562
+ base_contact_id: baseContactId,
563
+ mergee_contact_id: mergeeContactId,
564
+ };
565
+ responseData = await GenericFunctions_1.chatwootApiRequest.call(this, 'POST', '/actions/contact_merge', body);
566
+ }
259
567
  else {
260
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" is not supported for resource "contact"`, { itemIndex: i });
568
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Operation "${operation}" not supported`, { itemIndex: i });
261
569
  }
262
570
  }
263
571
  else {
264
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Resource "${resource}" is not supported`, {
265
- itemIndex: i,
266
- });
572
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Resource "${resource}" is not supported`, { itemIndex: i });
267
573
  }
268
574
  const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
269
575
  returnData.push(...executionData);