n8n-nodes-evolution-message-search 1.1.0 → 1.1.2
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: '
|
|
14
|
-
description: 'Search WhatsApp message history
|
|
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: [
|
|
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,70 @@ class SearchMessages {
|
|
|
55
57
|
],
|
|
56
58
|
};
|
|
57
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 tool = new EvolutionSearchTool(node, serverUrl, apiKey, instanceName, userConversationId, allowModelSetConversation, this);
|
|
69
|
+
return { response: tool };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class EvolutionSearchTool extends n8n_workflow_1.Tool {
|
|
73
|
+
constructor(node, serverUrl, apiKey, instanceName, userConversationId, allowModelSetConversation, ctx) {
|
|
74
|
+
super();
|
|
75
|
+
this.name = (0, n8n_workflow_1.nodeNameToToolName)(node);
|
|
76
|
+
this.description = 'Search WhatsApp message history. Input: {"keywords":"text","dateFrom":"ISO","dateTo":"ISO","page":1,"pageSize":10,"conversationId":"jid"}';
|
|
77
|
+
this.serverUrl = serverUrl;
|
|
78
|
+
this.apiKey = apiKey;
|
|
79
|
+
this.instanceName = instanceName;
|
|
80
|
+
this.userConversationId = userConversationId;
|
|
81
|
+
this.allowModelSetConversation = allowModelSetConversation;
|
|
82
|
+
this.ctx = ctx;
|
|
83
|
+
}
|
|
84
|
+
async _call(input) {
|
|
85
|
+
const params = typeof input === 'string' ? JSON.parse(input) : input;
|
|
86
|
+
let conversationId = this.userConversationId;
|
|
87
|
+
if (!conversationId && this.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 || this.ctx.getNodeParameter('pageSize', 0) || 10;
|
|
94
|
+
const page = params.page || 1;
|
|
95
|
+
const whereClause = {};
|
|
96
|
+
if (conversationId) whereClause['key.remote'] = conversationId;
|
|
97
|
+
if (keywords) whereClause['message.conversationMessage.text'] = { contains: keywords };
|
|
98
|
+
if (dateFrom || dateTo) {
|
|
99
|
+
whereClause['timestamp'] = {};
|
|
100
|
+
if (dateFrom) whereClause['timestamp']['gte'] = new Date(dateFrom).getTime() / 1000;
|
|
101
|
+
if (dateTo) whereClause['timestamp']['lte'] = new Date(dateTo).getTime() / 1000;
|
|
102
|
+
}
|
|
103
|
+
const body = {
|
|
104
|
+
where: whereClause,
|
|
105
|
+
take: pageSize,
|
|
106
|
+
skip: (page - 1) * pageSize,
|
|
107
|
+
orderBy: { timestamp: 'desc' },
|
|
108
|
+
};
|
|
109
|
+
const cleanUrl = this.serverUrl.replace(/\/$/, '');
|
|
110
|
+
const response = await this.ctx.helpers.request({
|
|
111
|
+
method: 'POST',
|
|
112
|
+
uri: `${cleanUrl}/chat/findMessages/${this.instanceName}`,
|
|
113
|
+
body,
|
|
114
|
+
headers: { 'Content-Type': 'application/json', 'apikey': this.apiKey },
|
|
115
|
+
});
|
|
116
|
+
const messages = response.messages || response;
|
|
117
|
+
return JSON.stringify({
|
|
118
|
+
total: messages.total || 0,
|
|
119
|
+
pages: Math.ceil((messages.total || 0) / pageSize),
|
|
120
|
+
currentPage: page,
|
|
121
|
+
pageSize,
|
|
122
|
+
records: messages.records || [],
|
|
123
|
+
});
|
|
124
|
+
}
|
|
58
125
|
}
|
|
59
126
|
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.
|
|
3
|
+
"version": "1.1.2",
|
|
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",
|