n8n-nodes-evolution-message-search 1.1.0 → 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.
@@ -10,12 +10,12 @@ class SearchMessages {
10
10
  icon: 'file:icon.svg',
11
11
  group: ['transform'],
12
12
  version: 1,
13
- subtitle: '={{$parameter["operation"]}}',
14
- description: 'Search WhatsApp message history via Evolution API',
13
+ subtitle: 'Search WhatsApp message history',
14
+ description: 'Search WhatsApp message history by keywords, dates, and conversation',
15
15
  defaults: {
16
16
  name: 'Evolution API - Search Messages',
17
17
  },
18
- inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
18
+ inputs: ['main'],
19
19
  outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
20
20
  outputNames: ['Tool'],
21
21
  credentials: [
@@ -25,26 +25,28 @@ class SearchMessages {
25
25
  },
26
26
  ],
27
27
  properties: [
28
- {
29
- displayName: 'Operation',
30
- name: 'operation',
31
- type: 'options',
32
- options: [
33
- { name: 'Search Messages', value: 'search' },
34
- ],
35
- default: 'search',
36
- },
37
28
  {
38
29
  displayName: 'Instance Name',
39
30
  name: 'instanceName',
40
31
  type: 'string',
32
+ required: true,
41
33
  default: '',
34
+ description: 'Name of the Evolution API instance',
42
35
  },
43
36
  {
44
37
  displayName: 'Conversation ID',
45
38
  name: 'conversationId',
46
39
  type: 'string',
40
+ required: false,
47
41
  default: '',
42
+ description: 'WhatsApp conversation ID (JID)',
43
+ placeholder: '5511999999999@s.whatsapp.net',
44
+ },
45
+ {
46
+ displayName: 'Allow Model to Set Conversation',
47
+ name: 'allowModelSetConversation',
48
+ type: 'boolean',
49
+ default: false,
48
50
  },
49
51
  {
50
52
  displayName: 'Items per Page',
@@ -55,5 +57,63 @@ class SearchMessages {
55
57
  ],
56
58
  };
57
59
  }
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();
117
+ }
58
118
  }
59
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.1.0",
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",