n8n-nodes-evolution-message-search 1.1.1 → 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.
|
@@ -57,63 +57,70 @@ class SearchMessages {
|
|
|
57
57
|
],
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
async supplyData(
|
|
61
|
-
const
|
|
62
|
-
const credentials = await context.getCredentials('evolutionApi');
|
|
60
|
+
async supplyData(itemIndex) {
|
|
61
|
+
const credentials = await this.getCredentials('evolutionApi');
|
|
63
62
|
const serverUrl = credentials['server-url'];
|
|
64
63
|
const apiKey = credentials.apikey;
|
|
65
|
-
const instanceName =
|
|
66
|
-
const userConversationId =
|
|
67
|
-
const allowModelSetConversation =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (dateFrom) whereClause['timestamp']['gte'] = new Date(dateFrom).getTime() / 1000;
|
|
91
|
-
if (dateTo) whereClause['timestamp']['lte'] = new Date(dateTo).getTime() / 1000;
|
|
92
|
-
}
|
|
93
|
-
const body = {
|
|
94
|
-
where: whereClause,
|
|
95
|
-
take: pageSize,
|
|
96
|
-
skip: (page - 1) * pageSize,
|
|
97
|
-
orderBy: { timestamp: 'desc' },
|
|
98
|
-
};
|
|
99
|
-
const cleanUrl = serverUrl.replace(/\/$/, '');
|
|
100
|
-
const response = await context.helpers.request({
|
|
101
|
-
method: 'POST',
|
|
102
|
-
uri: `${cleanUrl}/chat/findMessages/${instanceName}`,
|
|
103
|
-
body,
|
|
104
|
-
headers: { 'Content-Type': 'application/json', 'apikey': apiKey },
|
|
105
|
-
});
|
|
106
|
-
const messages = response.messages || response;
|
|
107
|
-
return JSON.stringify({
|
|
108
|
-
total: messages.total || 0,
|
|
109
|
-
pages: Math.ceil((messages.total || 0) / pageSize),
|
|
110
|
-
currentPage: page,
|
|
111
|
-
pageSize,
|
|
112
|
-
records: messages.records || [],
|
|
113
|
-
});
|
|
114
|
-
}
|
|
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;
|
|
115
89
|
}
|
|
116
|
-
|
|
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
|
+
});
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
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",
|