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
|
-
|
|
4
|
+
exports.EvolutionApi = void 0;
|
|
5
|
+
|
|
4
6
|
class EvolutionApi {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-evolution-message-search",
|
|
3
|
-
"version": "
|
|
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": "
|
|
27
|
+
"n8n-workflow": "*"
|
|
43
28
|
}
|
|
44
29
|
}
|