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

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.
@@ -2,6 +2,82 @@
2
2
  Object.defineProperty(exports, '__esModule', { value: true });
3
3
  exports.SearchMessages = void 0;
4
4
  const n8n_workflow_1 = require('n8n-workflow');
5
+ class SearchMessagesTool extends n8n_workflow_1.Tool {
6
+ constructor(node) {
7
+ super();
8
+ this.node = node;
9
+ this.name = (0, n8n_workflow_1.nodeNameToToolName)(node.getNode());
10
+ this.description = 'Search WhatsApp message history. Input should be an 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 with total, pages, currentPage, and records.';
11
+ }
12
+ async _call(input) {
13
+ const params = typeof input === 'string' ? JSON.parse(input) : input;
14
+ const credentials = await this.node.getCredentials('evolutionApi');
15
+ const serverUrl = credentials['server-url'];
16
+ const apiKey = credentials.apikey;
17
+ const instanceName = this.node.getNodeParameter('instanceName', 0);
18
+ const userConversationId = this.node.getNodeParameter('conversationId', 0) || '';
19
+ const allowModelSetConversation = this.node.getNodeParameter('allowModelSetConversation', 0);
20
+ let conversationId = userConversationId;
21
+ if (!conversationId && allowModelSetConversation && params.conversationId) {
22
+ conversationId = params.conversationId;
23
+ }
24
+ const keywords = params.keywords || '';
25
+ const dateFrom = params.dateFrom || '';
26
+ const dateTo = params.dateTo || '';
27
+ const pageSize = params.pageSize || this.node.getNodeParameter('pageSize', 0) || 10;
28
+ const page = params.page || 1;
29
+ const skip = (page - 1) * pageSize;
30
+ const whereClause = {};
31
+ if (conversationId) {
32
+ whereClause['key.remote'] = conversationId;
33
+ }
34
+ if (keywords) {
35
+ whereClause['message.conversationMessage.text'] = {
36
+ contains: keywords,
37
+ };
38
+ }
39
+ if (dateFrom || dateTo) {
40
+ whereClause['timestamp'] = {};
41
+ if (dateFrom) {
42
+ const fromTimestamp = new Date(dateFrom).getTime() / 1000;
43
+ whereClause['timestamp']['gte'] = fromTimestamp;
44
+ }
45
+ if (dateTo) {
46
+ const toTimestamp = new Date(dateTo).getTime() / 1000;
47
+ whereClause['timestamp']['lte'] = toTimestamp;
48
+ }
49
+ }
50
+ const body = {
51
+ where: whereClause,
52
+ take: pageSize,
53
+ skip: skip,
54
+ orderBy: {
55
+ timestamp: 'desc',
56
+ },
57
+ };
58
+ const cleanUrl = serverUrl.replace(/\/$/, '');
59
+ const responseData = await this.node.helpers.request({
60
+ method: 'POST',
61
+ uri: `${cleanUrl}/chat/findMessages/${instanceName}`,
62
+ body,
63
+ headers: {
64
+ 'Content-Type': 'application/json',
65
+ 'Accept': 'application/json',
66
+ 'apikey': apiKey,
67
+ },
68
+ });
69
+ const messages = responseData.messages || responseData;
70
+ const total = messages.total || messages.length || 0;
71
+ const totalPages = Math.ceil(total / pageSize);
72
+ return JSON.stringify({
73
+ total,
74
+ pages: totalPages,
75
+ currentPage: page,
76
+ pageSize,
77
+ records: Array.isArray(messages.records) ? messages.records : messages,
78
+ });
79
+ }
80
+ }
5
81
  class SearchMessages {
6
82
  constructor() {
7
83
  this.description = {
@@ -15,9 +91,9 @@ class SearchMessages {
15
91
  defaults: {
16
92
  name: 'Evolution API - Search Messages',
17
93
  },
18
- usableAsTool: true,
19
94
  inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
20
- outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
95
+ outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
96
+ outputNames: ['Tool'],
21
97
  credentials: [
22
98
  {
23
99
  name: 'evolutionApi',
@@ -47,43 +123,6 @@ class SearchMessages {
47
123
  default: false,
48
124
  description: 'If enabled, the AI model can set the conversation ID. If disabled, model must use the value provided above.',
49
125
  },
50
- {
51
- displayName: 'Model Conversation ID',
52
- name: 'modelConversationId',
53
- type: 'string',
54
- required: false,
55
- displayOptions: {
56
- show: {
57
- allowModelSetConversation: [true],
58
- },
59
- },
60
- description: 'Conversation ID that the AI model can set (only used if allowed)',
61
- placeholder: '5511999999999@s.whatsapp.net',
62
- },
63
- {
64
- displayName: 'Keywords',
65
- name: 'keywords',
66
- type: 'string',
67
- required: false,
68
- default: '',
69
- description: 'Search text in message content (model can set)',
70
- },
71
- {
72
- displayName: 'Date From',
73
- name: 'dateFrom',
74
- type: 'dateTime',
75
- required: false,
76
- default: '',
77
- description: 'Start date for message search (model can set)',
78
- },
79
- {
80
- displayName: 'Date To',
81
- name: 'dateTo',
82
- type: 'dateTime',
83
- required: false,
84
- default: '',
85
- description: 'End date for message search (model can set)',
86
- },
87
126
  {
88
127
  displayName: 'Items per Page',
89
128
  name: 'pageSize',
@@ -95,98 +134,13 @@ class SearchMessages {
95
134
  },
96
135
  description: 'Number of results per page (set by user, model cannot change)',
97
136
  },
98
- {
99
- displayName: 'Page Number',
100
- name: 'page',
101
- type: 'number',
102
- default: 1,
103
- typeOptions: {
104
- minValue: 1,
105
- },
106
- description: 'Page number to retrieve (model can navigate)',
107
- },
108
137
  ],
109
138
  };
110
139
  }
111
- async execute(context) {
112
- const executeFunctions = context;
113
- let itemIndex = 0;
114
- let items = [];
115
- if (executeFunctions.getInputData) {
116
- items = executeFunctions.getInputData();
117
- }
118
- const returnData = [];
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;
150
- }
151
- if (dateTo) {
152
- const toTimestamp = new Date(dateTo).getTime() / 1000;
153
- whereClause['timestamp']['lte'] = toTimestamp;
154
- }
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,
140
+ async supplyData() {
141
+ return {
142
+ response: new SearchMessagesTool(this),
184
143
  };
185
- returnData.push({
186
- json: result,
187
- pairedItem: { item: i },
188
- });
189
- return [returnData];
190
144
  }
191
145
  }
192
146
  exports.SearchMessages = SearchMessages;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-evolution-message-search",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
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",