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

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.
@@ -1,49 +1,52 @@
1
1
  'use strict';
2
+
2
3
  Object.defineProperty(exports, '__esModule', { value: true });
3
- const n8n_workflow_1 = require('n8n-workflow');
4
+ exports.EvolutionApi = void 0;
5
+
4
6
  class EvolutionApi {
5
- constructor() {
6
- this.name = 'evolutionApi';
7
- this.displayName = 'Evolution API';
8
- this.documentationUrl = 'https://doc.evolution-api.com/pt';
9
- this.properties = [
10
- {
11
- displayName: 'Server Url',
12
- name: 'server-url',
13
- type: 'string',
14
- default: '',
15
- placeholder: 'https://exemplo.com',
16
- description: 'Digite a URL completa da sua Evolution API (ex: https://api.exemplo.com)',
17
- },
18
- {
19
- displayName: 'ApiKey',
20
- name: 'apikey',
21
- type: 'string',
22
- default: '',
23
- typeOptions: {
24
- password: true,
25
- },
26
- description: 'Digite a ApiKey da Instancia ou Global da sua Evolution API',
27
- },
28
- ];
29
- this.authenticate = {
30
- type: 'generic',
31
- properties: {
32
- headers: {
33
- apikey: '={{$credentials.apikey}}',
34
- },
35
- },
36
- };
37
- this.test = {
38
- request: {
39
- baseURL: '={{$credentials["server-url"]}}',
40
- url: '={{$credentials["server-url"].endsWith("/") ? "/erro" : "/instance/fetchInstances"}}',
41
- method: 'GET',
42
- headers: {
43
- apikey: '={{$credentials.apikey}}',
44
- },
45
- },
46
- };
47
- }
7
+ constructor() {
8
+ this.name = 'evolutionApi';
9
+ this.displayName = 'Evolution API';
10
+ this.documentationUrl = 'https://docs.evolutionfoundation.com.br/evolution-api';
11
+ this.properties = [
12
+ {
13
+ displayName: 'Server Url',
14
+ name: 'server-url',
15
+ type: 'string',
16
+ default: '',
17
+ placeholder: 'https://example.com',
18
+ description: 'Digite a URL completa da sua Evolution API (ex: https://api.example.com)',
19
+ },
20
+ {
21
+ displayName: 'ApiKey',
22
+ name: 'apikey',
23
+ type: 'string',
24
+ typeOptions: {
25
+ password: true,
26
+ },
27
+ default: '',
28
+ description: 'Digite a ApiKey da Instancia ou Global da sua Evolution API',
29
+ },
30
+ ];
31
+ this.authenticate = {
32
+ type: 'generic',
33
+ properties: {
34
+ headers: {
35
+ apikey: '={{$credentials.apikey}}',
36
+ },
37
+ },
38
+ };
39
+ this.test = {
40
+ request: {
41
+ baseURL: '={{$credentials["server-url"]}}',
42
+ url: '=/instance/fetchInstances',
43
+ method: 'GET',
44
+ headers: {
45
+ apikey: '={{$credentials.apikey}}',
46
+ },
47
+ },
48
+ };
49
+ }
48
50
  }
51
+
49
52
  exports.EvolutionApi = EvolutionApi;
@@ -1,120 +1,211 @@
1
1
  'use strict';
2
+
2
3
  Object.defineProperty(exports, '__esModule', { value: true });
3
4
  exports.SearchMessages = void 0;
5
+
4
6
  const n8n_workflow_1 = require('n8n-workflow');
7
+
5
8
  class SearchMessages {
6
- constructor() {
7
- this.description = {
8
- displayName: 'Evolution API - Search Messages',
9
- name: 'searchMessages',
10
- icon: 'file:icon.svg',
11
- group: ['transform'],
12
- version: 1,
13
- subtitle: 'Search WhatsApp message history',
14
- description: 'Search WhatsApp message history by keywords, dates, and conversation',
15
- defaults: {
16
- name: 'Evolution API - Search Messages',
17
- },
18
- inputs: ['main'],
19
- outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
20
- outputNames: ['Tool'],
21
- credentials: [
22
- {
23
- name: 'evolutionApi',
24
- required: true,
25
- },
26
- ],
27
- properties: [
28
- {
29
- displayName: 'Instance Name',
30
- name: 'instanceName',
31
- type: 'string',
32
- required: true,
33
- default: '',
34
- description: 'Name of the Evolution API instance',
35
- },
36
- {
37
- displayName: 'Conversation ID',
38
- name: 'conversationId',
39
- type: 'string',
40
- required: false,
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,
50
- },
51
- {
52
- displayName: 'Items per Page',
53
- name: 'pageSize',
54
- type: 'number',
55
- default: 10,
56
- },
57
- ],
58
- };
59
- }
60
- async supplyData(itemIndex) {
61
- const credentials = await this.getCredentials('evolutionApi');
62
- const serverUrl = credentials['server-url'];
63
- const apiKey = credentials.apikey;
64
- const instanceName = this.getNodeParameter('instanceName', itemIndex);
65
- const userConversationId = this.getNodeParameter('conversationId', itemIndex) || '';
66
- const allowModelSetConversation = this.getNodeParameter('allowModelSetConversation', itemIndex);
67
- const node = this.getNode();
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
- },
116
- };
117
- return { response: tool };
118
- }
9
+ constructor() {
10
+ this.description = {
11
+ displayName: 'Evolution API - Search Messages',
12
+ name: 'searchMessages',
13
+ icon: 'file:icon.svg',
14
+ group: ['transform'],
15
+ version: 1,
16
+ subtitle: '={{$parameter["operation"]}}',
17
+ description: 'Search WhatsApp message history via Evolution API',
18
+ defaults: {
19
+ name: 'Evolution API - Search Messages',
20
+ },
21
+ usableAsTool: true,
22
+ inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
23
+ outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
24
+ credentials: [
25
+ {
26
+ name: 'evolutionApi',
27
+ required: true,
28
+ },
29
+ ],
30
+ properties: [
31
+ {
32
+ displayName: 'Instance Name',
33
+ name: 'instanceName',
34
+ type: 'string',
35
+ required: true,
36
+ default: '',
37
+ description: 'Name of the Evolution API instance (set by user, model cannot change)',
38
+ },
39
+ {
40
+ displayName: 'Conversation ID',
41
+ name: 'conversationId',
42
+ type: 'string',
43
+ required: false,
44
+ default: '',
45
+ description: 'WhatsApp conversation ID (JID). If empty, searches all conversations. Model can set if allowed.',
46
+ placeholder: '5511999999999@s.whatsapp.net',
47
+ },
48
+ {
49
+ displayName: 'Allow Model to Set Conversation',
50
+ name: 'allowModelSetConversation',
51
+ type: 'boolean',
52
+ default: false,
53
+ description: 'If enabled, the AI model can set the conversation ID',
54
+ },
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
+ {
80
+ displayName: 'Items per Page',
81
+ name: 'pageSize',
82
+ type: 'number',
83
+ default: 10,
84
+ typeOptions: {
85
+ minValue: 1,
86
+ maxValue: 100,
87
+ },
88
+ description: 'Number of results per page (defined by user, model cannot change)',
89
+ },
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
+ ],
101
+ };
102
+ }
103
+
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
+ 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
+ const credentials = await this.getCredentials('evolutionApi');
141
+ const serverUrl = credentials['server-url'];
142
+ const apiKey = credentials.apikey;
143
+
144
+ const instanceName = this.getNodeParameter('instanceName', itemIndex);
145
+ const userConversationId = this.getNodeParameter('conversationId', itemIndex) || '';
146
+ 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,
193
+ },
194
+ json: true,
195
+ });
196
+
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
+ };
208
+ }
119
209
  }
210
+
120
211
  exports.SearchMessages = SearchMessages;
@@ -1,20 +1,20 @@
1
1
  {
2
- "node": "n8n-nodes-evolution-message-search",
3
- "nodeVersion": "1.0",
4
- "codexVersion": "1.0",
5
- "categories": [
6
- "Communication"
7
- ],
8
- "resources": {
9
- "credentialDocumentation": [
10
- {
11
- "url": "https://docs.evolutionfoundation.com.br/evolution-api"
12
- }
13
- ],
14
- "primaryDocumentation": [
15
- {
16
- "url": "https://docs.evolutionfoundation.com.br/evolution-api"
17
- }
18
- ]
19
- }
2
+ "node": "n8n-nodes-evolution-message-search",
3
+ "nodeVersion": "1.0",
4
+ "codexVersion": "1.0",
5
+ "categories": [
6
+ "Communication"
7
+ ],
8
+ "resources": {
9
+ "credentialDocumentation": [
10
+ {
11
+ "url": "https://docs.evolutionfoundation.com.br/evolution-api"
12
+ }
13
+ ],
14
+ "primaryDocumentation": [
15
+ {
16
+ "url": "https://docs.evolutionfoundation.com.br/evolution-api"
17
+ }
18
+ ]
19
+ }
20
20
  }
@@ -1,5 +1,4 @@
1
1
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="none">
2
2
  <rect width="64" height="64" rx="8" fill="#25D366"/>
3
3
  <path d="M32 16c-8.837 0-16 7.163-16 16 0 6.626 4.134 12.318 10 14.706V44l6.19-3.416c2.206.611 4.54.92 6.81.92 8.837 0 16-7.163 16-16S40.837 16 32 16zm0 30c-2.21 0-4.383-.44-6.4-1.23l-.46-.17-4.89 2.7 2.75-4.77-.27-.46C20.52 40.36 18 36.29 18 32c0-7.732 6.268-14 14-14s14 6.268 14 14-6.268 14-14 14z" fill="white"/>
4
- <path d="M26 28h4v4h-4v-4zm6 0h4v4h-4v-4zm6 0h4v4h-4v-4z" fill="white"/>
5
4
  </svg>
package/index.js CHANGED
@@ -1,8 +1,2 @@
1
- module.exports = {
2
- nodes: [
3
- require('./dist/nodes/SearchMessages/SearchMessages.node.js'),
4
- ],
5
- credentials: [
6
- require('./dist/credentials/EvolutionApi.credentials.js'),
7
- ],
8
- };
1
+
2
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-evolution-message-search",
3
- "version": "1.1.3",
3
+ "version": "2.0.0",
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",
@@ -9,19 +9,8 @@
9
9
  "message-search"
10
10
  ],
11
11
  "license": "MIT",
12
- "homepage": "https://github.com/joaoramos/n8n-nodes-evolution-message-search",
13
- "author": {
14
- "name": "Joao Ramos"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/joaoramos/n8n-nodes-evolution-message-search.git"
19
- },
20
12
  "main": "index.js",
21
- "scripts": {
22
- "build": "tsc",
23
- "lint": "tsc --noEmit"
24
- },
13
+ "scripts": {},
25
14
  "files": [
26
15
  "dist"
27
16
  ],
@@ -34,11 +23,7 @@
34
23
  "dist/nodes/SearchMessages/SearchMessages.node.js"
35
24
  ]
36
25
  },
37
- "devDependencies": {
38
- "@types/node": "^18.17.0",
39
- "typescript": "^5.3.0"
40
- },
41
26
  "peerDependencies": {
42
- "n8n": ">=1.0.0"
27
+ "n8n-workflow": "*"
43
28
  }
44
29
  }