@areumtecnologia/baileys 1.0.6 → 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.
- package/handlers/baileys.js +2 -2
- package/handlers/groups.js +2 -2
- package/index.js +18 -37
- package/package.json +2 -3
- package/utils/message-normalizer.js +23 -29
package/handlers/baileys.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const wb = require('@whiskeysockets/baileys');
|
|
1
|
+
// const wb = require('@whiskeysockets/baileys');
|
|
2
2
|
const {
|
|
3
3
|
Browsers,
|
|
4
4
|
makeWASocket,
|
|
@@ -13,7 +13,7 @@ const {
|
|
|
13
13
|
} = require('@itsukichan/baileys');
|
|
14
14
|
|
|
15
15
|
module.exports = {
|
|
16
|
-
whiskeysocketsMakeWASocket: wb.makeWASocket,
|
|
16
|
+
// whiskeysocketsMakeWASocket: wb.makeWASocket,
|
|
17
17
|
itsukichanMakeWASocket: makeWASocket,
|
|
18
18
|
Browsers,
|
|
19
19
|
decryptPollVote,
|
package/handlers/groups.js
CHANGED
|
@@ -48,13 +48,13 @@ class GroupHandler {
|
|
|
48
48
|
this.client = client;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
/** Obtém os metadados de um grupo. */
|
|
51
|
+
/** Obtém os metadados de um grupo a partir da jid do grupo. */
|
|
52
52
|
async getMetadata(groupId) {
|
|
53
53
|
this.client._validateConnection();
|
|
54
54
|
return this.client.sock.groupMetadata(groupId);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
/** Cria um novo grupo. */
|
|
57
|
+
/** Cria um novo grupo a partir de uma lista de jids. */
|
|
58
58
|
async create(subject, participantsJids) {
|
|
59
59
|
this.client._validateConnection();
|
|
60
60
|
return this.client.sock.groupCreate(subject, participantsJids);
|
package/index.js
CHANGED
|
@@ -82,10 +82,11 @@ class Client extends EventEmitter {
|
|
|
82
82
|
// =================================================================================================
|
|
83
83
|
// Instancia os handlers, passando a si mesma (this) como referência.
|
|
84
84
|
// Isso permite que os handlers acessem o 'sock' e outros métodos do cliente.
|
|
85
|
-
this.messages = new MessageHandler(this);
|
|
86
85
|
this.groups = new GroupHandler(this);
|
|
87
86
|
this.users = new UserHandler(this);
|
|
88
87
|
this.calls = new CallHandler(this);
|
|
88
|
+
this.messages = new MessageHandler(this);
|
|
89
|
+
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
/**
|
|
@@ -97,42 +98,22 @@ class Client extends EventEmitter {
|
|
|
97
98
|
this.status = ClientEvent.INIT;
|
|
98
99
|
const { state, saveCreds } = await useMultiFileAuthState(this.sessionPath);
|
|
99
100
|
const { version } = await fetchLatestBaileysVersion();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return msg ? msg.raw?.message : undefined;
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
} else {
|
|
120
|
-
// Conecta usando Baileys
|
|
121
|
-
this.sock = whiskeysocketsMakeWASocket({
|
|
122
|
-
auth: state,
|
|
123
|
-
version,
|
|
124
|
-
browser: this.enviroment ? this.enviroment : Browsers.macOS("Desktop"),
|
|
125
|
-
logger: pino({ level: this.loggerLevel }),
|
|
126
|
-
markOnlineOnConnect: this.markOnlineOnConnect || false,
|
|
127
|
-
cachedGroupMetadata: async (jid) => groupCache.get(jid),
|
|
128
|
-
getMessage: async (key) => {
|
|
129
|
-
const chatId = key.remoteJid;
|
|
130
|
-
const msg = this.store?.getMessage(chatId, key.id);
|
|
131
|
-
// precisa retornar o raw.message
|
|
132
|
-
return msg ? msg.raw?.message : undefined;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
101
|
+
|
|
102
|
+
this.sock = itsukichanMakeWASocket({
|
|
103
|
+
auth: state,
|
|
104
|
+
version,
|
|
105
|
+
browser: this.enviroment ? this.enviroment : Browsers.macOS("Desktop"),
|
|
106
|
+
logger: pino({ level: this.loggerLevel }),
|
|
107
|
+
markOnlineOnConnect: this.markOnlineOnConnect || false,
|
|
108
|
+
keepAliveIntervalMs: 15000,
|
|
109
|
+
cachedGroupMetadata: async (jid) => groupCache.get(jid),
|
|
110
|
+
getMessage: async (key) => {
|
|
111
|
+
const chatId = key.remoteJid;
|
|
112
|
+
const msg = this.store?.getMessage(chatId, key.id);
|
|
113
|
+
// precisa retornar o raw.message
|
|
114
|
+
return msg ? msg.raw?.message : undefined;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
136
117
|
|
|
137
118
|
// =================================================================================================
|
|
138
119
|
// EVENTO CENTRALIZADO DE CICLO DE VIDA
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@areumtecnologia/baileys",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "More baileys fork",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Áreum Tecnologia",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@itsukichan/baileys": "
|
|
14
|
-
"@whiskeysockets/baileys": "^7.0.0-rc.9",
|
|
13
|
+
"@itsukichan/baileys": "github:Itsukichann/Baileys#master",
|
|
15
14
|
"crypto-digest-sync": "^1.0.0",
|
|
16
15
|
"node-cache": "^5.1.2",
|
|
17
16
|
"qrcode": "^1.5.4",
|
|
@@ -31,24 +31,32 @@ class MessageNormalizer {
|
|
|
31
31
|
const type = this._getFriendlyType(rawMessage.message);
|
|
32
32
|
const messageContent = rawMessage.message[originalType];
|
|
33
33
|
const contextInfo = messageContent?.contextInfo;
|
|
34
|
-
const chatId = rawMessage.key.remoteJid.includes('@lid') ? rawMessage.key.remoteJidAlt?.replace(/:.*?@/, "@") : rawMessage.key.remoteJid;
|
|
35
|
-
const isGroup = chatId.endsWith('@g.us');
|
|
36
34
|
const clientJid = client.jidNormalizedUser(client.sock.user.id);
|
|
37
|
-
const
|
|
38
|
-
const
|
|
35
|
+
const clientLid = client.sock.user.lid.replace(/:.*?@/, "@");
|
|
36
|
+
const fromMe = rawMessage.key.fromMe;
|
|
37
|
+
const chatLid = [rawMessage.key.remoteJid, rawMessage.key.remoteJidAlt].find(jid => jid && jid.includes('@lid'))?.replace(/:.*?@/, "@");
|
|
38
|
+
const chatId = [rawMessage.key.remoteJid, rawMessage.key.remoteJidAlt].find(jid => jid && !jid.includes('@lid'))?.replace(/:.*?@/, "@");
|
|
39
|
+
const isGroup = chatId.endsWith('@g.us');
|
|
40
|
+
const groupMetadata = isGroup ? await client.groups.getMetadata(chatId) : null;
|
|
41
|
+
const groupParticipants = groupMetadata?.participants;
|
|
42
|
+
const from = fromMe ? clientJid : chatId;
|
|
43
|
+
const to = fromMe ? chatId : clientJid;
|
|
44
|
+
|
|
39
45
|
const normalized = {
|
|
40
46
|
id: rawMessage.key.id,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
lid: rawMessage.key.remoteJid.includes('@lid') ? rawMessage.key.remoteJid : rawMessage.key.remoteJidAlt && rawMessage.key.remoteJidAlt.includes('@lid') ? rawMessage.key.remoteJidAlt : null,
|
|
50
|
-
pushName: rawMessage.pushName || ''
|
|
47
|
+
chat: {
|
|
48
|
+
id: chatId,
|
|
49
|
+
lid: from == to ? clientLid : chatLid,
|
|
50
|
+
isGroup,
|
|
51
|
+
groupMetadata,
|
|
52
|
+
groupPushName: groupMetadata?.subject || null,
|
|
53
|
+
groupParticipantSender: groupParticipants?.find(participant => fromMe && participant.id === clientJid || !fromMe && participant.id === [rawMessage.key.participant, rawMessage.key.participantAlt].find(jid => jid && !jid.includes('@lid'))?.replace(/:.*?@/, "@")) || null,
|
|
54
|
+
isBusiness: !!rawMessage.verifiedBizName,
|
|
51
55
|
},
|
|
56
|
+
fromMe,
|
|
57
|
+
from,
|
|
58
|
+
fromPushName: fromMe ? client.user.name : isGroup ? groupMetadata?.subject : rawMessage.pushName,
|
|
59
|
+
to,
|
|
52
60
|
type,
|
|
53
61
|
body: this._extractBody(rawMessage.message),
|
|
54
62
|
hasMedia: false,
|
|
@@ -66,6 +74,7 @@ class MessageNormalizer {
|
|
|
66
74
|
reaction: this._extractReaction(rawMessage.message),
|
|
67
75
|
pollUpdate: await this._extractPollUpdate(rawMessage, client),
|
|
68
76
|
poll: this._extractPollCreation(rawMessage),
|
|
77
|
+
timestamp: new Date(Number(rawMessage.messageTimestamp) * 1000),
|
|
69
78
|
raw: rawMessage // Referência ao objeto original para acesso avançado
|
|
70
79
|
};
|
|
71
80
|
|
|
@@ -91,21 +100,6 @@ class MessageNormalizer {
|
|
|
91
100
|
|
|
92
101
|
/**
|
|
93
102
|
* @private Retorna um tipo amigável baseado no conteúdo da mensagem.
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* {
|
|
97
|
-
"text": "This is an Interactive message!",
|
|
98
|
-
"title": "Hiii",
|
|
99
|
-
"subtitle": "There is a subtitle",
|
|
100
|
-
"footer": "Hello World!",
|
|
101
|
-
"interactiveButtons": [
|
|
102
|
-
{
|
|
103
|
-
"name": "cta_copy",
|
|
104
|
-
"buttonParamsJson": "{\"display_text\":\"Click Me!\",\"copy_code\":\"12345\"}"
|
|
105
|
-
}
|
|
106
|
-
]
|
|
107
|
-
}
|
|
108
|
-
*
|
|
109
103
|
*/
|
|
110
104
|
static _getFriendlyType(message) {
|
|
111
105
|
if (!message) return 'unknown'
|