n8n-nodes-evolution-message-search 1.0.9 → 1.1.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.
@@ -2,82 +2,6 @@
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
- }
81
5
  class SearchMessages {
82
6
  constructor() {
83
7
  this.description = {
@@ -91,7 +15,7 @@ class SearchMessages {
91
15
  defaults: {
92
16
  name: 'Evolution API - Search Messages',
93
17
  },
94
- inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
18
+ inputs: ['main'],
95
19
  outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
96
20
  outputNames: ['Tool'],
97
21
  credentials: [
@@ -106,14 +30,16 @@ class SearchMessages {
106
30
  name: 'instanceName',
107
31
  type: 'string',
108
32
  required: true,
109
- description: 'Name of the Evolution API instance (set by user, model cannot change)',
33
+ default: '',
34
+ description: 'Name of the Evolution API instance',
110
35
  },
111
36
  {
112
37
  displayName: 'Conversation ID',
113
38
  name: 'conversationId',
114
39
  type: 'string',
115
40
  required: false,
116
- description: 'WhatsApp conversation ID (JID). If empty, searches all conversations.',
41
+ default: '',
42
+ description: 'WhatsApp conversation ID (JID)',
117
43
  placeholder: '5511999999999@s.whatsapp.net',
118
44
  },
119
45
  {
@@ -121,26 +47,73 @@ class SearchMessages {
121
47
  name: 'allowModelSetConversation',
122
48
  type: 'boolean',
123
49
  default: false,
124
- description: 'If enabled, the AI model can set the conversation ID. If disabled, model must use the value provided above.',
125
50
  },
126
51
  {
127
52
  displayName: 'Items per Page',
128
53
  name: 'pageSize',
129
54
  type: 'number',
130
55
  default: 10,
131
- typeOptions: {
132
- minValue: 1,
133
- maxValue: 100,
134
- },
135
- description: 'Number of results per page (set by user, model cannot change)',
136
56
  },
137
57
  ],
138
58
  };
139
59
  }
140
- async supplyData() {
141
- return {
142
- response: new SearchMessagesTool(this),
143
- };
60
+ async supplyData(context, itemIndex) {
61
+ const node = context.getNode();
62
+ const credentials = await context.getCredentials('evolutionApi');
63
+ const serverUrl = credentials['server-url'];
64
+ const apiKey = credentials.apikey;
65
+ const instanceName = context.getNodeParameter('instanceName', itemIndex);
66
+ const userConversationId = context.getNodeParameter('conversationId', itemIndex) || '';
67
+ const allowModelSetConversation = context.getNodeParameter('allowModelSetConversation', itemIndex);
68
+ class EvolutionSearchTool extends n8n_workflow_1.Tool {
69
+ constructor() {
70
+ super();
71
+ this.name = (0, n8n_workflow_1.nodeNameToToolName)(node);
72
+ this.description = 'Search WhatsApp message history. Input: {"keywords":"text","dateFrom":"ISO","dateTo":"ISO","page":1,"pageSize":10,"conversationId":"jid"}';
73
+ }
74
+ async _call(input) {
75
+ const params = typeof input === 'string' ? JSON.parse(input) : input;
76
+ let conversationId = userConversationId;
77
+ if (!conversationId && allowModelSetConversation && params.conversationId) {
78
+ conversationId = params.conversationId;
79
+ }
80
+ const keywords = params.keywords || '';
81
+ const dateFrom = params.dateFrom || '';
82
+ const dateTo = params.dateTo || '';
83
+ const pageSize = params.pageSize || 10;
84
+ const page = params.page || 1;
85
+ const whereClause = {};
86
+ if (conversationId) whereClause['key.remote'] = conversationId;
87
+ if (keywords) whereClause['message.conversationMessage.text'] = { contains: keywords };
88
+ if (dateFrom || dateTo) {
89
+ whereClause['timestamp'] = {};
90
+ if (dateFrom) whereClause['timestamp']['gte'] = new Date(dateFrom).getTime() / 1000;
91
+ if (dateTo) whereClause['timestamp']['lte'] = new Date(dateTo).getTime() / 1000;
92
+ }
93
+ const body = {
94
+ where: whereClause,
95
+ take: pageSize,
96
+ skip: (page - 1) * pageSize,
97
+ orderBy: { timestamp: 'desc' },
98
+ };
99
+ const cleanUrl = serverUrl.replace(/\/$/, '');
100
+ const response = await context.helpers.request({
101
+ method: 'POST',
102
+ uri: `${cleanUrl}/chat/findMessages/${instanceName}`,
103
+ body,
104
+ headers: { 'Content-Type': 'application/json', 'apikey': apiKey },
105
+ });
106
+ const messages = response.messages || response;
107
+ return JSON.stringify({
108
+ total: messages.total || 0,
109
+ pages: Math.ceil((messages.total || 0) / pageSize),
110
+ currentPage: page,
111
+ pageSize,
112
+ records: messages.records || [],
113
+ });
114
+ }
115
+ }
116
+ return new EvolutionSearchTool();
144
117
  }
145
118
  }
146
119
  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.9",
3
+ "version": "1.1.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",