n8n-nodes-evolution-message-search 1.1.3 → 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.
@@ -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,152 @@
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
+ const core_tools_1 = require('@langchain/core/tools');
8
+
5
9
  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
- }
10
+ constructor() {
11
+ this.description = {
12
+ displayName: 'Evolution API - Search Messages',
13
+ name: 'searchMessages',
14
+ icon: 'file:icon.svg',
15
+ group: ['transform'],
16
+ version: 1,
17
+ subtitle: 'Search WhatsApp message history',
18
+ description: 'Search WhatsApp message history via Evolution API',
19
+ defaults: {
20
+ name: 'Evolution API - Search Messages',
21
+ },
22
+ inputs: [],
23
+ outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
24
+ outputNames: ['Tool'],
25
+ credentials: [
26
+ {
27
+ name: 'evolutionApi',
28
+ required: true,
29
+ },
30
+ ],
31
+ properties: [
32
+ {
33
+ displayName: 'Instance Name',
34
+ name: 'instanceName',
35
+ type: 'string',
36
+ required: true,
37
+ default: '',
38
+ description: 'Name of the Evolution API instance (set by user, model cannot change)',
39
+ },
40
+ {
41
+ displayName: 'Conversation ID',
42
+ name: 'conversationId',
43
+ type: 'string',
44
+ required: false,
45
+ default: '',
46
+ description: 'WhatsApp conversation ID (JID). If empty, searches all conversations. Model can set if allowed.',
47
+ placeholder: '5511999999999@s.whatsapp.net',
48
+ },
49
+ {
50
+ displayName: 'Allow Model to Set Conversation',
51
+ name: 'allowModelSetConversation',
52
+ type: 'boolean',
53
+ default: false,
54
+ description: 'If enabled, the AI model can set the conversation ID',
55
+ },
56
+ {
57
+ displayName: 'Items per Page',
58
+ name: 'pageSize',
59
+ type: 'number',
60
+ default: 10,
61
+ typeOptions: {
62
+ minValue: 1,
63
+ maxValue: 100,
64
+ },
65
+ description: 'Number of results per page (defined by user, model cannot change)',
66
+ },
67
+ ],
68
+ };
69
+ }
70
+
71
+ async supplyData(itemIndex) {
72
+ const credentials = await this.getCredentials('evolutionApi');
73
+ const serverUrl = credentials['server-url'];
74
+ const apiKey = credentials.apikey;
75
+ const instanceName = this.getNodeParameter('instanceName', itemIndex);
76
+ const userConversationId = this.getNodeParameter('conversationId', itemIndex) || '';
77
+ const allowModelSetConversation = this.getNodeParameter('allowModelSetConversation', itemIndex);
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
+ });
145
+ },
146
+ });
147
+
148
+ return { response: tool };
149
+ }
119
150
  }
151
+
120
152
  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.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",
@@ -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,8 @@
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": "*",
28
+ "@langchain/core": "*"
43
29
  }
44
30
  }