n8n-nodes-evolution-message-search 1.0.6 → 1.0.7

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.
@@ -108,80 +108,84 @@ class SearchMessages {
108
108
  ],
109
109
  };
110
110
  }
111
- async execute(executeFunctions) {
112
- const items = executeFunctions.getInputData();
111
+ async execute(context) {
112
+ const executeFunctions = context;
113
+ let itemIndex = 0;
114
+ let items = [];
115
+ if (executeFunctions.getInputData) {
116
+ items = executeFunctions.getInputData();
117
+ }
113
118
  const returnData = [];
114
- for (let i = 0; i < items.length; i++) {
115
- const credentials = await executeFunctions.getCredentials('evolutionApi');
116
- const serverUrl = credentials['server-url'];
117
- const apiKey = credentials.apikey;
118
- const instanceName = executeFunctions.getNodeParameter('instanceName', i);
119
- const userConversationId = executeFunctions.getNodeParameter('conversationId', i) || '';
120
- const allowModelSetConversation = executeFunctions.getNodeParameter('allowModelSetConversation', i);
121
- let conversationId = userConversationId;
122
- if (!conversationId && allowModelSetConversation) {
123
- conversationId = executeFunctions.getNodeParameter('modelConversationId', i) || '';
124
- }
125
- const keywords = executeFunctions.getNodeParameter('keywords', i) || '';
126
- const dateFrom = executeFunctions.getNodeParameter('dateFrom', i) || '';
127
- const dateTo = executeFunctions.getNodeParameter('dateTo', i) || '';
128
- const pageSize = executeFunctions.getNodeParameter('pageSize', i) || 10;
129
- const page = executeFunctions.getNodeParameter('page', i) || 1;
130
- const skip = (page - 1) * pageSize;
131
- const whereClause = {};
132
- if (conversationId) {
133
- whereClause['key.remote'] = conversationId;
134
- }
135
- if (keywords) {
136
- whereClause['message.conversationMessage.text'] = {
137
- contains: keywords,
138
- };
119
+ const i = itemIndex;
120
+ const credentials = await executeFunctions.getCredentials('evolutionApi');
121
+ const serverUrl = credentials['server-url'];
122
+ const apiKey = credentials.apikey;
123
+ const instanceName = executeFunctions.getNodeParameter('instanceName', i);
124
+ const userConversationId = executeFunctions.getNodeParameter('conversationId', i) || '';
125
+ const allowModelSetConversation = executeFunctions.getNodeParameter('allowModelSetConversation', i);
126
+ let conversationId = userConversationId;
127
+ if (!conversationId && allowModelSetConversation) {
128
+ conversationId = executeFunctions.getNodeParameter('modelConversationId', i) || '';
129
+ }
130
+ const keywords = executeFunctions.getNodeParameter('keywords', i) || '';
131
+ const dateFrom = executeFunctions.getNodeParameter('dateFrom', i) || '';
132
+ const dateTo = executeFunctions.getNodeParameter('dateTo', i) || '';
133
+ const pageSize = executeFunctions.getNodeParameter('pageSize', i) || 10;
134
+ const page = executeFunctions.getNodeParameter('page', i) || 1;
135
+ const skip = (page - 1) * pageSize;
136
+ const whereClause = {};
137
+ if (conversationId) {
138
+ whereClause['key.remote'] = conversationId;
139
+ }
140
+ if (keywords) {
141
+ whereClause['message.conversationMessage.text'] = {
142
+ contains: keywords,
143
+ };
144
+ }
145
+ if (dateFrom || dateTo) {
146
+ whereClause['timestamp'] = {};
147
+ if (dateFrom) {
148
+ const fromTimestamp = new Date(dateFrom).getTime() / 1000;
149
+ whereClause['timestamp']['gte'] = fromTimestamp;
139
150
  }
140
- if (dateFrom || dateTo) {
141
- whereClause['timestamp'] = {};
142
- if (dateFrom) {
143
- const fromTimestamp = new Date(dateFrom).getTime() / 1000;
144
- whereClause['timestamp']['gte'] = fromTimestamp;
145
- }
146
- if (dateTo) {
147
- const toTimestamp = new Date(dateTo).getTime() / 1000;
148
- whereClause['timestamp']['lte'] = toTimestamp;
149
- }
151
+ if (dateTo) {
152
+ const toTimestamp = new Date(dateTo).getTime() / 1000;
153
+ whereClause['timestamp']['lte'] = toTimestamp;
150
154
  }
151
- const body = {
152
- where: whereClause,
153
- take: pageSize,
154
- skip: skip,
155
- orderBy: {
156
- timestamp: 'desc',
157
- },
158
- };
159
- const cleanUrl = serverUrl.replace(/\/$/, '');
160
- const responseData = await executeFunctions.helpers.request({
161
- method: 'POST',
162
- uri: `${cleanUrl}/chat/findMessages/${instanceName}`,
163
- body,
164
- headers: {
165
- 'Content-Type': 'application/json',
166
- 'Accept': 'application/json',
167
- 'apikey': apiKey,
168
- },
169
- });
170
- const messages = responseData.messages || responseData;
171
- const total = messages.total || messages.length || 0;
172
- const totalPages = Math.ceil(total / pageSize);
173
- const result = {
174
- total,
175
- pages: totalPages,
176
- currentPage: page,
177
- pageSize,
178
- records: Array.isArray(messages.records) ? messages.records : messages,
179
- };
180
- returnData.push({
181
- json: result,
182
- pairedItem: { item: i },
183
- });
184
155
  }
156
+ const body = {
157
+ where: whereClause,
158
+ take: pageSize,
159
+ skip: skip,
160
+ orderBy: {
161
+ timestamp: 'desc',
162
+ },
163
+ };
164
+ const cleanUrl = serverUrl.replace(/\/$/, '');
165
+ const responseData = await executeFunctions.helpers.request({
166
+ method: 'POST',
167
+ uri: `${cleanUrl}/chat/findMessages/${instanceName}`,
168
+ body,
169
+ headers: {
170
+ 'Content-Type': 'application/json',
171
+ 'Accept': 'application/json',
172
+ 'apikey': apiKey,
173
+ },
174
+ });
175
+ const messages = responseData.messages || responseData;
176
+ const total = messages.total || messages.length || 0;
177
+ const totalPages = Math.ceil(total / pageSize);
178
+ const result = {
179
+ total,
180
+ pages: totalPages,
181
+ currentPage: page,
182
+ pageSize,
183
+ records: Array.isArray(messages.records) ? messages.records : messages,
184
+ };
185
+ returnData.push({
186
+ json: result,
187
+ pairedItem: { item: i },
188
+ });
185
189
  return [returnData];
186
190
  }
187
191
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-evolution-message-search",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Evolution API - Search Messages node for n8n. Search WhatsApp message history by keywords, dates, and conversation.",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",