@areumtecnologia/baileys 1.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.
- package/baileys.code-workspace +8 -0
- package/desktop.ini +0 -0
- package/handlers/desktop.ini +0 -0
- package/handlers/groups.js +94 -0
- package/handlers/messages.js +285 -0
- package/handlers/presence-status.js +9 -0
- package/handlers/users.js +94 -0
- package/index.js +456 -0
- package/package.json +16 -0
- package/tests/app.js +68 -0
- package/tests/desktop.ini +0 -0
- package/types/buttons.js +72 -0
- package/types/desktop.ini +0 -0
- package/types/interactive-messages.js +318 -0
- package/utils/desktop.ini +0 -0
- package/utils/generic-utils.js +23 -0
- package/utils/index.js +4 -0
- package/utils/message-normalizer.js +323 -0
- package/utils/message-store-db-handler.js +39 -0
- package/utils/message-store.js +67 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
class MessageStore {
|
|
5
|
+
constructor(table) {
|
|
6
|
+
this.table = table;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async saveMessage(chatId, message) {
|
|
10
|
+
return await this.table.insert({ chat_id: chatId, key: message.id, from: message.from, to: message.to })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async getMessage(chatId, id) {
|
|
15
|
+
return await this.table.select([{ chat_id: chatId }, 'AND', { mid: id }]);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getMessages(chatId, { from, to, limit } = {}) {
|
|
19
|
+
return await this.table.select([{ chat_id: chatId }, 'AND', { mid: id }]);
|
|
20
|
+
|
|
21
|
+
let messages = this._loadMessages(chatId);
|
|
22
|
+
|
|
23
|
+
if (from || to) {
|
|
24
|
+
messages = messages.filter(msg => {
|
|
25
|
+
const ts = new Date(msg.timestamp).getTime();
|
|
26
|
+
return (!from || ts >= new Date(from).getTime()) &&
|
|
27
|
+
(!to || ts <= new Date(to).getTime());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (limit) {
|
|
32
|
+
messages = messages.slice(-limit);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return messages;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = MessageStore;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
class MessageStore {
|
|
5
|
+
constructor(basePath) {
|
|
6
|
+
this.basePath = path.join(basePath, 'message_store');
|
|
7
|
+
if (!fs.existsSync(this.basePath)) {
|
|
8
|
+
fs.mkdirSync(this.basePath, { recursive: true });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
_getFilePath(chatId) {
|
|
13
|
+
return path.join(this.basePath, `${chatId}.json`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
_loadMessages(chatId) {
|
|
17
|
+
const filePath = this._getFilePath(chatId);
|
|
18
|
+
if (!fs.existsSync(filePath)) return [];
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8')) || [];
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error("Erro ao ler mensagens:", err);
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_saveMessages(chatId, messages) {
|
|
28
|
+
const filePath = this._getFilePath(chatId);
|
|
29
|
+
fs.writeFileSync(filePath, JSON.stringify(messages, null, 2));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
saveMessage(chatId, message) {
|
|
33
|
+
const messages = this._loadMessages(chatId);
|
|
34
|
+
|
|
35
|
+
// Evita duplicados pelo id
|
|
36
|
+
if (!messages.find(m => m.id === message.id)) {
|
|
37
|
+
messages.push(message);
|
|
38
|
+
this._saveMessages(chatId, messages);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
getMessage(chatId, id) {
|
|
44
|
+
const messages = this._loadMessages(chatId);
|
|
45
|
+
return messages.find(m => m.id === id);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getMessages(chatId, { from, to, limit } = {}) {
|
|
49
|
+
let messages = this._loadMessages(chatId);
|
|
50
|
+
|
|
51
|
+
if (from || to) {
|
|
52
|
+
messages = messages.filter(msg => {
|
|
53
|
+
const ts = new Date(msg.timestamp).getTime();
|
|
54
|
+
return (!from || ts >= new Date(from).getTime()) &&
|
|
55
|
+
(!to || ts <= new Date(to).getTime());
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (limit) {
|
|
60
|
+
messages = messages.slice(-limit);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return messages;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = MessageStore;
|