n8n-nodes-evolution-message-search 1.1.2 → 1.1.3

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.
@@ -65,62 +65,56 @@ class SearchMessages {
65
65
  const userConversationId = this.getNodeParameter('conversationId', itemIndex) || '';
66
66
  const allowModelSetConversation = this.getNodeParameter('allowModelSetConversation', itemIndex);
67
67
  const node = this.getNode();
68
- const tool = new EvolutionSearchTool(node, serverUrl, apiKey, instanceName, userConversationId, allowModelSetConversation, this);
69
- return { response: tool };
70
- }
71
- }
72
- class EvolutionSearchTool extends n8n_workflow_1.Tool {
73
- constructor(node, serverUrl, apiKey, instanceName, userConversationId, allowModelSetConversation, ctx) {
74
- super();
75
- this.name = (0, n8n_workflow_1.nodeNameToToolName)(node);
76
- this.description = 'Search WhatsApp message history. Input: {"keywords":"text","dateFrom":"ISO","dateTo":"ISO","page":1,"pageSize":10,"conversationId":"jid"}';
77
- this.serverUrl = serverUrl;
78
- this.apiKey = apiKey;
79
- this.instanceName = instanceName;
80
- this.userConversationId = userConversationId;
81
- this.allowModelSetConversation = allowModelSetConversation;
82
- this.ctx = ctx;
83
- }
84
- async _call(input) {
85
- const params = typeof input === 'string' ? JSON.parse(input) : input;
86
- let conversationId = this.userConversationId;
87
- if (!conversationId && this.allowModelSetConversation && params.conversationId) {
88
- conversationId = params.conversationId;
89
- }
90
- const keywords = params.keywords || '';
91
- const dateFrom = params.dateFrom || '';
92
- const dateTo = params.dateTo || '';
93
- const pageSize = params.pageSize || this.ctx.getNodeParameter('pageSize', 0) || 10;
94
- const page = params.page || 1;
95
- const whereClause = {};
96
- if (conversationId) whereClause['key.remote'] = conversationId;
97
- if (keywords) whereClause['message.conversationMessage.text'] = { contains: keywords };
98
- if (dateFrom || dateTo) {
99
- whereClause['timestamp'] = {};
100
- if (dateFrom) whereClause['timestamp']['gte'] = new Date(dateFrom).getTime() / 1000;
101
- if (dateTo) whereClause['timestamp']['lte'] = new Date(dateTo).getTime() / 1000;
102
- }
103
- const body = {
104
- where: whereClause,
105
- take: pageSize,
106
- skip: (page - 1) * pageSize,
107
- orderBy: { timestamp: 'desc' },
68
+ const ctx = this;
69
+ const tool = {
70
+ name: (0, n8n_workflow_1.nodeNameToToolName)(node),
71
+ description: 'Search WhatsApp message history. Input: {"keywords":"text","dateFrom":"ISO","dateTo":"ISO","page":1,"pageSize":10,"conversationId":"jid"}',
72
+ _call: async function (input) {
73
+ const params = typeof input === 'string' ? JSON.parse(input) : input;
74
+ let conversationId = userConversationId;
75
+ if (!conversationId && allowModelSetConversation && params.conversationId) {
76
+ conversationId = params.conversationId;
77
+ }
78
+ const keywords = params.keywords || '';
79
+ const dateFrom = params.dateFrom || '';
80
+ const dateTo = params.dateTo || '';
81
+ const pageSize = params.pageSize || ctx.getNodeParameter('pageSize', 0) || 10;
82
+ const page = params.page || 1;
83
+ const whereClause = {};
84
+ if (conversationId) whereClause['key.remote'] = conversationId;
85
+ if (keywords) whereClause['message.conversationMessage.text'] = { contains: keywords };
86
+ if (dateFrom || dateTo) {
87
+ whereClause['timestamp'] = {};
88
+ if (dateFrom) whereClause['timestamp']['gte'] = new Date(dateFrom).getTime() / 1000;
89
+ if (dateTo) whereClause['timestamp']['lte'] = new Date(dateTo).getTime() / 1000;
90
+ }
91
+ const body = {
92
+ where: whereClause,
93
+ take: pageSize,
94
+ skip: (page - 1) * pageSize,
95
+ orderBy: { timestamp: 'desc' },
96
+ };
97
+ const cleanUrl = serverUrl.replace(/\/$/, '');
98
+ const response = await ctx.helpers.request({
99
+ method: 'POST',
100
+ uri: `${cleanUrl}/chat/findMessages/${instanceName}`,
101
+ body,
102
+ headers: { 'Content-Type': 'application/json', 'apikey': apiKey },
103
+ });
104
+ const messages = response.messages || response;
105
+ return JSON.stringify({
106
+ total: messages.total || 0,
107
+ pages: Math.ceil((messages.total || 0) / pageSize),
108
+ currentPage: page,
109
+ pageSize,
110
+ records: messages.records || [],
111
+ });
112
+ },
113
+ invoke: async function (input) {
114
+ return this._call(input);
115
+ },
108
116
  };
109
- const cleanUrl = this.serverUrl.replace(/\/$/, '');
110
- const response = await this.ctx.helpers.request({
111
- method: 'POST',
112
- uri: `${cleanUrl}/chat/findMessages/${this.instanceName}`,
113
- body,
114
- headers: { 'Content-Type': 'application/json', 'apikey': this.apiKey },
115
- });
116
- const messages = response.messages || response;
117
- return JSON.stringify({
118
- total: messages.total || 0,
119
- pages: Math.ceil((messages.total || 0) / pageSize),
120
- currentPage: page,
121
- pageSize,
122
- records: messages.records || [],
123
- });
117
+ return { response: tool };
124
118
  }
125
119
  }
126
120
  exports.SearchMessages = SearchMessages;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-evolution-message-search",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
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",