n8n-nodes-evolution-message-search 1.0.8 → 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,83 +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(ctx) {
|
|
7
|
-
super();
|
|
8
|
-
this.ctx = ctx;
|
|
9
|
-
this.name = (0, n8n_workflow_1.nodeNameToToolName)(ctx.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).';
|
|
11
|
-
}
|
|
12
|
-
async _call(input) {
|
|
13
|
-
const params = typeof input === 'string' ? JSON.parse(input) : input;
|
|
14
|
-
const credentials = await this.ctx.getCredentials('evolutionApi');
|
|
15
|
-
const serverUrl = credentials['server-url'];
|
|
16
|
-
const apiKey = credentials.apikey;
|
|
17
|
-
const instanceName = this.ctx.getNodeParameter('instanceName', 0);
|
|
18
|
-
const userConversationId = this.ctx.getNodeParameter('conversationId', 0) || '';
|
|
19
|
-
const allowModelSetConversation = this.ctx.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.ctx.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.ctx.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
|
-
const result = {
|
|
73
|
-
total,
|
|
74
|
-
pages: totalPages,
|
|
75
|
-
currentPage: page,
|
|
76
|
-
pageSize,
|
|
77
|
-
records: Array.isArray(messages.records) ? messages.records : messages,
|
|
78
|
-
};
|
|
79
|
-
return JSON.stringify(result);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
5
|
class SearchMessages {
|
|
83
6
|
constructor() {
|
|
84
7
|
this.description = {
|
|
@@ -87,8 +10,8 @@ class SearchMessages {
|
|
|
87
10
|
icon: 'file:icon.svg',
|
|
88
11
|
group: ['transform'],
|
|
89
12
|
version: 1,
|
|
90
|
-
subtitle: '
|
|
91
|
-
description: 'Search WhatsApp message history
|
|
13
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
14
|
+
description: 'Search WhatsApp message history via Evolution API',
|
|
92
15
|
defaults: {
|
|
93
16
|
name: 'Evolution API - Search Messages',
|
|
94
17
|
},
|
|
@@ -102,46 +25,35 @@ class SearchMessages {
|
|
|
102
25
|
},
|
|
103
26
|
],
|
|
104
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
|
+
},
|
|
105
37
|
{
|
|
106
38
|
displayName: 'Instance Name',
|
|
107
39
|
name: 'instanceName',
|
|
108
40
|
type: 'string',
|
|
109
|
-
|
|
110
|
-
description: 'Name of the Evolution API instance (set by user, model cannot change)',
|
|
41
|
+
default: '',
|
|
111
42
|
},
|
|
112
43
|
{
|
|
113
44
|
displayName: 'Conversation ID',
|
|
114
45
|
name: 'conversationId',
|
|
115
46
|
type: 'string',
|
|
116
|
-
|
|
117
|
-
description: 'WhatsApp conversation ID (JID). If empty, searches all conversations.',
|
|
118
|
-
placeholder: '5511999999999@s.whatsapp.net',
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
displayName: 'Allow Model to Set Conversation',
|
|
122
|
-
name: 'allowModelSetConversation',
|
|
123
|
-
type: 'boolean',
|
|
124
|
-
default: false,
|
|
125
|
-
description: 'If enabled, the AI model can set the conversation ID. If disabled, model must use the value provided above.',
|
|
47
|
+
default: '',
|
|
126
48
|
},
|
|
127
49
|
{
|
|
128
50
|
displayName: 'Items per Page',
|
|
129
51
|
name: 'pageSize',
|
|
130
52
|
type: 'number',
|
|
131
53
|
default: 10,
|
|
132
|
-
typeOptions: {
|
|
133
|
-
minValue: 1,
|
|
134
|
-
maxValue: 100,
|
|
135
|
-
},
|
|
136
|
-
description: 'Number of results per page (set by user, model cannot change)',
|
|
137
54
|
},
|
|
138
55
|
],
|
|
139
56
|
};
|
|
140
57
|
}
|
|
141
|
-
async supplyData() {
|
|
142
|
-
return {
|
|
143
|
-
response: new SearchMessagesTool(this),
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
58
|
}
|
|
147
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",
|