@areumtecnologia/baileys 1.0.6 → 1.1.1
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 +7 -2
- package/index.js +28 -38
- package/package.json +3 -4
- package/utils/message-normalizer.js +29 -30
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,18 @@ 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
|
+
/** Obtém a URL da foto de perfil de um grupo. */
|
|
57
|
+
async getProfilePicture(jid) {
|
|
58
|
+
this.client._validateConnection();
|
|
59
|
+
return this.client.sock.profilePictureUrl(jid, 'image');
|
|
60
|
+
}
|
|
56
61
|
|
|
57
|
-
/** Cria um novo grupo. */
|
|
62
|
+
/** Cria um novo grupo a partir de uma lista de jids. */
|
|
58
63
|
async create(subject, participantsJids) {
|
|
59
64
|
this.client._validateConnection();
|
|
60
65
|
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
|
|
@@ -187,7 +168,16 @@ class Client extends EventEmitter {
|
|
|
187
168
|
break;
|
|
188
169
|
|
|
189
170
|
case 'open':
|
|
190
|
-
|
|
171
|
+
const wid = this.sock.user.id.replace(/:.*?@/, "@");
|
|
172
|
+
const statusMessage = await this.sock.fetchStatus(wid);
|
|
173
|
+
this.user = {
|
|
174
|
+
id: wid,
|
|
175
|
+
lid: this.sock.user.lid.replace(/:.*?@/, "@"),
|
|
176
|
+
name: this.sock.user.name,
|
|
177
|
+
slogan: statusMessage[0]?.status || null,
|
|
178
|
+
picture: await this.sock.profilePictureUrl(wid),
|
|
179
|
+
business: await this.sock.getBusinessProfile(wid),
|
|
180
|
+
};
|
|
191
181
|
this.qrCode = null; // Limpa o QR code após a conexão
|
|
192
182
|
this.connected = true;
|
|
193
183
|
this.manualDisconnect = false;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@areumtecnologia/baileys",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "More baileys
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "More baileys Wrapper",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Áreum Tecnologia",
|
|
7
7
|
"type": "commonjs",
|
|
@@ -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'
|
|
@@ -215,11 +209,16 @@ class MessageNormalizer {
|
|
|
215
209
|
pollUpdate.pollCreationMessageKey.remoteJid,
|
|
216
210
|
pollUpdate.pollCreationMessageKey.id
|
|
217
211
|
);
|
|
212
|
+
|
|
213
|
+
if (!creationMsg) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
|
|
218
217
|
creationMsg.raw.message.pollCreationMessage = creationMsg.raw.message.pollCreationMessage ? creationMsg.raw.message.pollCreationMessage :
|
|
219
218
|
creationMsg.raw.message.pollCreationMessageV3;
|
|
220
219
|
|
|
221
220
|
// Verifica se a mensagem de criação existe e tem a estrutura correta
|
|
222
|
-
if (!creationMsg) {
|
|
221
|
+
if (!creationMsg.raw.message.pollCreationMessage) {
|
|
223
222
|
console.warn("Mensagem de criação da enquete não encontrada na store ou sem estrutura válida");
|
|
224
223
|
return {
|
|
225
224
|
pollCreationMessageId: pollUpdate.pollCreationMessageKey?.id,
|