n8n-nodes-evolution-message-search 1.0.9 → 1.1.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.
|
@@ -2,82 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
exports.SearchMessages = void 0;
|
|
4
4
|
const n8n_workflow_1 = require('n8n-workflow');
|
|
5
|
-
class SearchMessagesTool extends n8n_workflow_1.Tool {
|
|
6
|
-
constructor(node) {
|
|
7
|
-
super();
|
|
8
|
-
this.node = node;
|
|
9
|
-
this.name = (0, n8n_workflow_1.nodeNameToToolName)(node.getNode());
|
|
10
|
-
this.description = 'Search WhatsApp message history. Input should be an 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 with total, pages, currentPage, and records.';
|
|
11
|
-
}
|
|
12
|
-
async _call(input) {
|
|
13
|
-
const params = typeof input === 'string' ? JSON.parse(input) : input;
|
|
14
|
-
const credentials = await this.node.getCredentials('evolutionApi');
|
|
15
|
-
const serverUrl = credentials['server-url'];
|
|
16
|
-
const apiKey = credentials.apikey;
|
|
17
|
-
const instanceName = this.node.getNodeParameter('instanceName', 0);
|
|
18
|
-
const userConversationId = this.node.getNodeParameter('conversationId', 0) || '';
|
|
19
|
-
const allowModelSetConversation = this.node.getNodeParameter('allowModelSetConversation', 0);
|
|
20
|
-
let conversationId = userConversationId;
|
|
21
|
-
if (!conversationId && allowModelSetConversation && params.conversationId) {
|
|
22
|
-
conversationId = params.conversationId;
|
|
23
|
-
}
|
|
24
|
-
const keywords = params.keywords || '';
|
|
25
|
-
const dateFrom = params.dateFrom || '';
|
|
26
|
-
const dateTo = params.dateTo || '';
|
|
27
|
-
const pageSize = params.pageSize || this.node.getNodeParameter('pageSize', 0) || 10;
|
|
28
|
-
const page = params.page || 1;
|
|
29
|
-
const skip = (page - 1) * pageSize;
|
|
30
|
-
const whereClause = {};
|
|
31
|
-
if (conversationId) {
|
|
32
|
-
whereClause['key.remote'] = conversationId;
|
|
33
|
-
}
|
|
34
|
-
if (keywords) {
|
|
35
|
-
whereClause['message.conversationMessage.text'] = {
|
|
36
|
-
contains: keywords,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (dateFrom || dateTo) {
|
|
40
|
-
whereClause['timestamp'] = {};
|
|
41
|
-
if (dateFrom) {
|
|
42
|
-
const fromTimestamp = new Date(dateFrom).getTime() / 1000;
|
|
43
|
-
whereClause['timestamp']['gte'] = fromTimestamp;
|
|
44
|
-
}
|
|
45
|
-
if (dateTo) {
|
|
46
|
-
const toTimestamp = new Date(dateTo).getTime() / 1000;
|
|
47
|
-
whereClause['timestamp']['lte'] = toTimestamp;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const body = {
|
|
51
|
-
where: whereClause,
|
|
52
|
-
take: pageSize,
|
|
53
|
-
skip: skip,
|
|
54
|
-
orderBy: {
|
|
55
|
-
timestamp: 'desc',
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
const cleanUrl = serverUrl.replace(/\/$/, '');
|
|
59
|
-
const responseData = await this.node.helpers.request({
|
|
60
|
-
method: 'POST',
|
|
61
|
-
uri: `${cleanUrl}/chat/findMessages/${instanceName}`,
|
|
62
|
-
body,
|
|
63
|
-
headers: {
|
|
64
|
-
'Content-Type': 'application/json',
|
|
65
|
-
'Accept': 'application/json',
|
|
66
|
-
'apikey': apiKey,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
const messages = responseData.messages || responseData;
|
|
70
|
-
const total = messages.total || messages.length || 0;
|
|
71
|
-
const totalPages = Math.ceil(total / pageSize);
|
|
72
|
-
return JSON.stringify({
|
|
73
|
-
total,
|
|
74
|
-
pages: totalPages,
|
|
75
|
-
currentPage: page,
|
|
76
|
-
pageSize,
|
|
77
|
-
records: Array.isArray(messages.records) ? messages.records : messages,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
5
|
class SearchMessages {
|
|
82
6
|
constructor() {
|
|
83
7
|
this.description = {
|
|
@@ -86,8 +10,8 @@ class SearchMessages {
|
|
|
86
10
|
icon: 'file:icon.svg',
|
|
87
11
|
group: ['transform'],
|
|
88
12
|
version: 1,
|
|
89
|
-
subtitle: '
|
|
90
|
-
description: 'Search WhatsApp message history
|
|
13
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
14
|
+
description: 'Search WhatsApp message history via Evolution API',
|
|
91
15
|
defaults: {
|
|
92
16
|
name: 'Evolution API - Search Messages',
|
|
93
17
|
},
|
|
@@ -101,46 +25,35 @@ class SearchMessages {
|
|
|
101
25
|
},
|
|
102
26
|
],
|
|
103
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
|
+
},
|
|
104
37
|
{
|
|
105
38
|
displayName: 'Instance Name',
|
|
106
39
|
name: 'instanceName',
|
|
107
40
|
type: 'string',
|
|
108
|
-
|
|
109
|
-
description: 'Name of the Evolution API instance (set by user, model cannot change)',
|
|
41
|
+
default: '',
|
|
110
42
|
},
|
|
111
43
|
{
|
|
112
44
|
displayName: 'Conversation ID',
|
|
113
45
|
name: 'conversationId',
|
|
114
46
|
type: 'string',
|
|
115
|
-
|
|
116
|
-
description: 'WhatsApp conversation ID (JID). If empty, searches all conversations.',
|
|
117
|
-
placeholder: '5511999999999@s.whatsapp.net',
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
displayName: 'Allow Model to Set Conversation',
|
|
121
|
-
name: 'allowModelSetConversation',
|
|
122
|
-
type: 'boolean',
|
|
123
|
-
default: false,
|
|
124
|
-
description: 'If enabled, the AI model can set the conversation ID. If disabled, model must use the value provided above.',
|
|
47
|
+
default: '',
|
|
125
48
|
},
|
|
126
49
|
{
|
|
127
50
|
displayName: 'Items per Page',
|
|
128
51
|
name: 'pageSize',
|
|
129
52
|
type: 'number',
|
|
130
53
|
default: 10,
|
|
131
|
-
typeOptions: {
|
|
132
|
-
minValue: 1,
|
|
133
|
-
maxValue: 100,
|
|
134
|
-
},
|
|
135
|
-
description: 'Number of results per page (set by user, model cannot change)',
|
|
136
54
|
},
|
|
137
55
|
],
|
|
138
56
|
};
|
|
139
57
|
}
|
|
140
|
-
async supplyData() {
|
|
141
|
-
return {
|
|
142
|
-
response: new SearchMessagesTool(this),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
58
|
}
|
|
146
59
|
exports.SearchMessages = SearchMessages;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-evolution-message-search",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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",
|