n8n-nodes-evolution-message-search 2.0.0 → 2.0.1

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.
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
  exports.SearchMessages = void 0;
5
5
 
6
6
  const n8n_workflow_1 = require('n8n-workflow');
7
+ const core_tools_1 = require('@langchain/core/tools');
7
8
 
8
9
  class SearchMessages {
9
10
  constructor() {
@@ -13,14 +14,14 @@ class SearchMessages {
13
14
  icon: 'file:icon.svg',
14
15
  group: ['transform'],
15
16
  version: 1,
16
- subtitle: '={{$parameter["operation"]}}',
17
+ subtitle: 'Search WhatsApp message history',
17
18
  description: 'Search WhatsApp message history via Evolution API',
18
19
  defaults: {
19
20
  name: 'Evolution API - Search Messages',
20
21
  },
21
- usableAsTool: true,
22
- inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
23
- outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
22
+ inputs: [],
23
+ outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
24
+ outputNames: ['Tool'],
24
25
  credentials: [
25
26
  {
26
27
  name: 'evolutionApi',
@@ -52,30 +53,6 @@ class SearchMessages {
52
53
  default: false,
53
54
  description: 'If enabled, the AI model can set the conversation ID',
54
55
  },
55
- {
56
- displayName: 'Keywords',
57
- name: 'keywords',
58
- type: 'string',
59
- required: false,
60
- default: '',
61
- description: 'Search text in message content (model can set)',
62
- },
63
- {
64
- displayName: 'Date From',
65
- name: 'dateFrom',
66
- type: 'dateTime',
67
- required: false,
68
- default: '',
69
- description: 'Start date for message search (model can set)',
70
- },
71
- {
72
- displayName: 'Date To',
73
- name: 'dateTo',
74
- type: 'dateTime',
75
- required: false,
76
- default: '',
77
- description: 'End date for message search (model can set)',
78
- },
79
56
  {
80
57
  displayName: 'Items per Page',
81
58
  name: 'pageSize',
@@ -87,124 +64,88 @@ class SearchMessages {
87
64
  },
88
65
  description: 'Number of results per page (defined by user, model cannot change)',
89
66
  },
90
- {
91
- displayName: 'Page Number',
92
- name: 'page',
93
- type: 'number',
94
- default: 1,
95
- typeOptions: {
96
- minValue: 1,
97
- },
98
- description: 'Page number to retrieve (model can navigate)',
99
- },
100
67
  ],
101
68
  };
102
69
  }
103
70
 
104
- async execute() {
105
- const items = this.getInputData();
106
- const returnData = [];
107
-
108
- for (let i = 0; i < items.length; i++) {
109
- const result = await this.executeSingle.call(this, i);
110
- returnData.push({
111
- json: result,
112
- pairedItem: { item: i },
113
- });
114
- }
115
-
116
- return [returnData];
117
- }
118
-
119
71
  async supplyData(itemIndex) {
120
- const result = await this.executeSingle.call(this, itemIndex);
121
- return {
122
- response: {
123
- name: this.getNode().name,
124
- description: 'Search WhatsApp message history',
125
- invoke: async (input) => {
126
- if (typeof input === 'object' && input !== null) {
127
- for (const key of ['keywords', 'dateFrom', 'dateTo', 'page', 'conversationId']) {
128
- if (input[key] !== undefined && input[key] !== null) {
129
- this.getNodeParameter;
130
- }
131
- }
132
- }
133
- return JSON.stringify(result);
134
- },
135
- },
136
- };
137
- }
138
-
139
- async executeSingle(itemIndex) {
140
72
  const credentials = await this.getCredentials('evolutionApi');
141
73
  const serverUrl = credentials['server-url'];
142
74
  const apiKey = credentials.apikey;
143
-
144
75
  const instanceName = this.getNodeParameter('instanceName', itemIndex);
145
76
  const userConversationId = this.getNodeParameter('conversationId', itemIndex) || '';
146
77
  const allowModelSetConversation = this.getNodeParameter('allowModelSetConversation', itemIndex);
147
- const keywords = this.getNodeParameter('keywords', itemIndex) || '';
148
- const dateFrom = this.getNodeParameter('dateFrom', itemIndex) || '';
149
- const dateTo = this.getNodeParameter('dateTo', itemIndex) || '';
150
- const pageSize = this.getNodeParameter('pageSize', itemIndex) || 10;
151
- const page = this.getNodeParameter('page', itemIndex) || 1;
152
-
153
- const conversationId = userConversationId;
154
- const skip = (page - 1) * pageSize;
155
-
156
- const whereClause = {};
157
- if (conversationId && allowModelSetConversation) {
158
- whereClause['key.remote'] = conversationId;
159
- } else if (conversationId) {
160
- whereClause['key.remote'] = conversationId;
161
- }
162
-
163
- if (keywords) {
164
- whereClause['message.conversationMessage.text'] = { contains: keywords };
165
- }
166
-
167
- if (dateFrom || dateTo) {
168
- whereClause['timestamp'] = {};
169
- if (dateFrom) {
170
- whereClause['timestamp']['gte'] = new Date(dateFrom).getTime() / 1000;
171
- }
172
- if (dateTo) {
173
- whereClause['timestamp']['lte'] = new Date(dateTo).getTime() / 1000;
174
- }
175
- }
176
-
177
- const body = {
178
- where: whereClause,
179
- take: pageSize,
180
- skip: skip,
181
- orderBy: { timestamp: 'desc' },
182
- };
183
-
184
- const cleanUrl = serverUrl.replace(/\/$/, '');
185
- const response = await this.helpers.request({
186
- method: 'POST',
187
- uri: `${cleanUrl}/chat/findMessages/${instanceName}`,
188
- body,
189
- headers: {
190
- 'Content-Type': 'application/json',
191
- Accept: 'application/json',
192
- apikey: apiKey,
78
+ const pageSizeDefault = this.getNodeParameter('pageSize', itemIndex) || 10;
79
+ const ctx = this;
80
+
81
+ const tool = new core_tools_1.DynamicTool({
82
+ name: n8n_workflow_1.nodeNameToToolName(this.getNode()),
83
+ description: 'Search WhatsApp message history. Input must be a JSON object with: keywords (string, optional), dateFrom (ISO date string, optional), dateTo (ISO date string, optional), page (number, default 1), pageSize (number, default 10), conversationId (string, optional). Returns paginated message search results.',
84
+ func: async (input) => {
85
+ const params = typeof input === 'string' ? JSON.parse(input) : (input || {});
86
+ let conversationId = userConversationId;
87
+ if (!conversationId && 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 || pageSizeDefault;
94
+ const page = params.page || 1;
95
+ const skip = (page - 1) * pageSize;
96
+
97
+ const whereClause = {};
98
+ if (conversationId) {
99
+ whereClause['key.remote'] = conversationId;
100
+ }
101
+ if (keywords) {
102
+ whereClause['message.conversationMessage.text'] = { contains: keywords };
103
+ }
104
+ if (dateFrom || dateTo) {
105
+ whereClause['timestamp'] = {};
106
+ if (dateFrom) {
107
+ whereClause['timestamp']['gte'] = new Date(dateFrom).getTime() / 1000;
108
+ }
109
+ if (dateTo) {
110
+ whereClause['timestamp']['lte'] = new Date(dateTo).getTime() / 1000;
111
+ }
112
+ }
113
+
114
+ const body = {
115
+ where: whereClause,
116
+ take: pageSize,
117
+ skip: skip,
118
+ orderBy: { timestamp: 'desc' },
119
+ };
120
+
121
+ const cleanUrl = serverUrl.replace(/\/$/, '');
122
+ const response = await ctx.helpers.request({
123
+ method: 'POST',
124
+ uri: `${cleanUrl}/chat/findMessages/${instanceName}`,
125
+ body,
126
+ headers: {
127
+ 'Content-Type': 'application/json',
128
+ Accept: 'application/json',
129
+ apikey: apiKey,
130
+ },
131
+ json: true,
132
+ });
133
+
134
+ const messages = response.messages || response;
135
+ const total = messages.total || messages.length || 0;
136
+ const totalPages = Math.ceil(total / pageSize);
137
+
138
+ return JSON.stringify({
139
+ total,
140
+ pages: totalPages,
141
+ currentPage: page,
142
+ pageSize,
143
+ records: Array.isArray(messages.records) ? messages.records : messages,
144
+ });
193
145
  },
194
- json: true,
195
146
  });
196
147
 
197
- const messages = response.messages || response;
198
- const total = messages.total || messages.length || 0;
199
- const totalPages = Math.ceil(total / pageSize);
200
-
201
- return {
202
- total,
203
- pages: totalPages,
204
- currentPage: page,
205
- pageSize,
206
- records: Array.isArray(messages.records) ? messages.records : messages,
207
- };
148
+ return { response: tool };
208
149
  }
209
150
  }
210
151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-evolution-message-search",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
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",
@@ -24,6 +24,7 @@
24
24
  ]
25
25
  },
26
26
  "peerDependencies": {
27
- "n8n-workflow": "*"
27
+ "n8n-workflow": "*",
28
+ "@langchain/core": "*"
28
29
  }
29
30
  }